Hi

Thanks for the detailed description, I'm forwarding the message to the users list,

On 14/05/12 23:21, Tony Giaccone wrote:


Hi, my first posting and I have looked over the mailing list and a host of 
other web sites but
for the life of me I can't figure out how solve my problem.


First a general description, I'm creating a Restful Web Service that manages a 
persistent
entity (eventually many but for now one).  I'm using Spring, Spring Security, 
Jackson and
Apache CXF. I'm using maven for my builds and deploying to jetty.

I have a servlet that responds to incoming requests and routes them to the 
correct service
implementation.  The WebService part works just fine.


What I want do do now, is include a page of HTML which includes css and 
javascript in the
application so that I can use to test the web services.  I want to deploy the 
service and the
static html/javascript/css in the same war file.

Essentially I have this file layout:

        webapp +
                        |
                        ----->  static - +
                        |                       |
                        |                       | - MyTestCode.html
                         |                       |
                         |                       | ->  css (contains css files)
                         |                       |
                         |                       | ->  js (contains javascript 
included in the MyTestCode.htm file)
                        |
                        ----->WEB-INF -+
                        |                            | -->  
applicationContext.xml
                        |                            |
                        |                            |-->  web.xml
                        |
                        |--- index.jsp



Assume I have a servlet named myServlet,  I want all the requests that go to my

myServlet/service

to map to a Restful service implementation.

So for example:

        http://localhost:8080/myServlet/server/user/getAll   - calls a method 
on the service implementation.

I want this URL

        http://locahost:8080/myServlet/static/MyTestCode.html

To return the data from the file of html


I'm aware of this page: http://cxf.apache.org/docs/servlet-transport.html

But I've not been able to figure out how to get this to work.  Do I have to use 
both a
redirect servlet and a static-resource-list? I've tried every combination I can 
think of to get this to
work but had zero success.

Can someone point me in the right direction?

The simplest option is to avoid using a wildcard uri pattern. If you can have two servlet declarations, one listening on '/server/*', another one on '/static/*', then it should work without any problems.

If you do need to use a single CXFServlet also capable of serving the static content, then you need to set up a static-resource-list, the values are reg expressions, so you should probably do something like this:

<init-param>
 <param-name>static-resources-list</param-name>
 <param-value>/static/(\w)+.[html|css|js]</param-value>
</init-param>

or

<init-param>
 <param-name>static-resources-list</param-name>
 <param-value>
   /static/Mytest.html
   /static/My.css
   /static/My.js
 </param-value>
</init-param>

Combining redirect & static configuration won;t work, but it may be worth trying to use the redirect parameters only:

<init-param>
            <param-name>redirects-list</param-name>
                <param-value>/(\w)+.html</param-value>
            </init-param>
            <init-param>
                <param-name>reditect-servlet-name</param-name>
                <param-value>DefaultCXFServlet</param-value>
            </init-param>
        
However I'm not sure how it will work with CXFServlet listening on '*'.

See also this section:
http://cxf.apache.org/docs/jax-rs-redirection.html

HTH, Sergey




Tony Giaccone




--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to