Hi,

The 2nd servlet is not needed, remove it. Actually I see you made this work, and perhaps it can be tuned, but a simpler option is keep you restulApp servlet only and add:


<<init-param>
>              <param-name>redirects-list</param-name>
>              <param-value>(\w)+.css</param-value>
>          </init-param>
>          <init-param>
>              <param-name>redirect-servlet-path</param-name>
>              <param-value>/Styles</param-value>
>          </init-param>

The only reason we have to add it, is, as far as I understand, to overcome a problem with a .css request being treated by restfulApp as a regular HTTP/JAX-RS request, so the above should take care of it.


Also note you have "/rest/*" URL pattern for the main servlet - as I've said earlier, if you css files were not having a "/rest/" path segment, then there would be no need to do the above as CXFServlet would not interfere, so tune a JSP link as "/Styles/default.css" or similar for it to start resolving the link relative to /appcontext/, skipping /rest/.

It appears to be complex, but it is really about tuning it a bit to make sure all is aligned...Let me know please hot it goes with a single servlet only

Sergey


On 30/04/15 07:34, Voss, Marko wrote:
Well, after replacing

<link rel="StyleSheet" type="text/css" href="Styles/default.css"/>

With

<link rel="StyleSheet" type="text/css" href="/Styles/default.css"/>

It works, BUT the redirect lost the /appcontext part of the URL. Doesn't the 
servlets have to stay in the appcontext?


Best regards,
Marko

-----Ursprüngliche Nachricht-----
Von: Voss, Marko
Gesendet: Donnerstag, 30. April 2015 08:18
An: users@cxf.apache.org
Betreff: AW: AW: AW: AW: AW: AW: AW: How to forward requests to a JSP page when 
using CXFNonSpringJaxrsServlet

Hi Sergey,

I don't get it. It does not work... What am I doing wrong?

     <servlet>
         <servlet-name>RestfulApp</servlet-name>
         
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
         <init-param>
             <param-name>jaxrs.serviceClasses</param-name>
             <param-value>
             org.foo.bar.MyServiceImpl
             </param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>

     <servlet>
         <display-name>Redirect CXF Servlet</display-name>
         <servlet-name>RedirectCXFServlet</servlet-name>
         
<servlet-class>org.apache.cxf.transport.servlet.CXFNonSpringServlet</servlet-class>
         <init-param>
             <param-name>redirects-list</param-name>
             <param-value>/rest/Styles/(\w)+.css</param-value>
         </init-param>
         <init-param>
             <param-name>redirect-servlet-path</param-name>
             <param-value>/Styles</param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>

     <servlet-mapping>
         <servlet-name>RedirectCXFServlet</servlet-name>
         <url-pattern>/Styles/*</url-pattern>
     </servlet-mapping>

     <servlet-mapping>
         <servlet-name>RestfulApp</servlet-name>
         <url-pattern>/rest/*</url-pattern>
     </servlet-mapping>

So we have the MyServiceImpl, which performs a forwarding (via 
RequestDispatcher) to a JSP page. This JSP does call a stylesheet like so:

<link rel="StyleSheet" type="text/css" href="Styles/default.css"/>

This ends up in a request like this:

http://server:port/appcontext/rest/Styles/default.css

Now, I would expect the RedirectCXFServlet to catch this request and forward it 
to

http://server:port/appcontext/Styles/default.css

But nothing like this happens. I still get a 404 on 
http://server:port/appcontext/rest/Styles/default.css.

:-/


Thank you and best regards,
Marko

-----Ursprüngliche Nachricht-----
Von: Sergey Beryozkin [mailto:sberyoz...@gmail.com]
Gesendet: Mittwoch, 29. April 2015 13:46
An: users@cxf.apache.org
Betreff: Re: AW: AW: AW: AW: AW: AW: How to forward requests to a JSP page when 
using CXFNonSpringJaxrsServlet

np, thanks for experimenting with the redirection code :-)

Let me know please if it works

Sergey
On 29/04/15 12:43, Voss, Marko wrote:
Thank you Sergey, I will test this as soon as I can continue working
on this again. :)

Cheers,
Marko

-----Ursprüngliche Nachricht-----
Von: Sergey Beryozkin [mailto:sberyoz...@gmail.com]
Gesendet: Mittwoch, 29. April 2015 13:29
An: users@cxf.apache.org
Betreff: Re: AW: AW: AW: AW: AW: How to forward requests to a JSP page
when using CXFNonSpringJaxrsServlet

<init-param>
                  <param-name>redirects-list</param-name>
                  <param-value>
                        /(\w)+.css
                      </param-value>
              </init-param>
              <init-param>
                  <param-name>redirect-servlet-name</param-name>
                  <param-value>default</param-value>
              </init-param>

or even

<init-param>
                  <param-name>static-resources-list</param-name>
                  <param-value>/(\w)+.css</param-value>
              </init-param>


though the latter option is limited...

HTH, Sergey

On 29/04/15 12:22, Sergey Beryozkin wrote:
LOL, it has 3 such servlet declarations, not 2. I'm confused :-)
Still the examples are straightforward IMHO. Check the example
showing a redirect for all the html pages...

Sergey
On 29/04/15 12:18, Sergey Beryozkin wrote:
Well, I've mentioned which servlet parameters need to be checked.
The web.xml has 4 servlet declarations, only 2 of them have these
parameters. What exactly is confusing ?


On 29/04/15 12:06, Voss, Marko wrote:
Hi Sergey,

to be honest, those are multiple examples at once, aren't they?
This is confusing for me...


-----Ursprüngliche Nachricht-----
Von: Sergey Beryozkin [mailto:sberyoz...@gmail.com]
Gesendet: Mittwoch, 29. April 2015 12:28
An: users@cxf.apache.org
Betreff: Re: AW: AW: AW: AW: How to forward requests to a JSP page
when using CXFNonSpringJaxrsServlet

Hi Marko
On 29/04/15 10:44, Voss, Marko wrote:
Hi Sergey,

You can control by configuring CXFServlet with init parameters
that would let it know that a default servlet needs to take care
of all of .css files, set a redirect init parameter there Does it help ?

Well, I do not know, how to set this up for the
CXFNonSpringJaxrsServlet. I can see a parameter named
'jaxrs.static.subresources' in that class, but I highly doubt,
that this is the same. Can you show me an example, of how to do
this, please?

See for example

https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob;f=systests
/
jaxrs/src/test/resources/jaxrs_dispatch/WEB-INF/web.xml;h=a2212337b
d 6a9ed7a212b21a6826850581601121;hb=HEAD



(redirect-list, redirect-servlet-name parameters) - redirect to a
'default' or other servlet name representing a default servlet.

It is only needed if you have a wildcard URL pattern for CXFServlet
because it obviously catches all the requests...

Cheers, Sergey





Thank you very much.

Best regards,
Marko

-----Ursprüngliche Nachricht-----
Von: Sergey Beryozkin [mailto:sberyoz...@gmail.com]
Gesendet: Donnerstag, 23. April 2015 13:55
An: users@cxf.apache.org
Betreff: Re: AW: AW: AW: How to forward requests to a JSP page
when using CXFNonSpringJaxrsServlet

Hi Marko

On 23/04/15 07:48, Voss, Marko wrote:
Hi Sergey,

I am running into a different issue with this. The forwarding
calls a JSP, which requires a stylesheet.

The JAXRS service, which is performing the forwarding is located at:

/appcontext/rest/service

The JSP is located at:

/appcontext/foo.jsp

The stylesheet will be loaded from:

/appcontext/rest/css/stylesheet.css

Instead of:

/appcontext/css/stylesheet.css

What entity loads this stylesheet, JSP ? Using a "/css/stylesheet.css"
relative to a base HTTP address ?
So CXF endpoint is at "/appcontext/rest" base address and I think
this base address is used when forwarding. CXF does not know that
given a JSP reference such as "/appcontext/css/stylesheet.css" it
needs to use "/appcontext" only as a base address.
Well, JSP can just use a context value only, instead of the base
HTTP address that CXF sets up. I.e, use Servlet API in JSP to get
the context and + "css/stylesheet.css" to it.


Even if I put the stylesheet into a rest folder, it does not
work, because the JAXRS servlet, "thinks" it has to handle a rest
service request.

You can control by configuring CXFServlet with init parameters
that would let it know that a default servlet needs to take care
of all of .css files, set a redirect init parameter there


Does it help ?

Cheers, Sergey

Why is the stylesheet loaded like this? How can I avoid this behavior?


Thank you in advance and best regards,

Marko







--
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com



--
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com


Reply via email to