You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Marcelo Alcantara <ma...@gmail.com> on 2013/11/13 08:04:36 UTC
Fowarding to jsp from CXF
Hi
I need to redirect to a jsp that is inside WEB-INF from a CXF/Jetty started
server.
How can I redirect from inside a rest service to a jsp that is inside
WEB-INF/jsp?
I tried doing a simple servlet forward but it always use the app context
regardless of weather the path starts with '/' or not.
I also saw the documentation but in my case the jsp is not related at all
with any entity (it's a login page).
Thanks in advance.
Marcelo
Re: Fowarding to jsp from CXF
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 14/11/13 05:07, Marcelo Alcantara wrote:
> Hi Sergey,
>
> Thanks a lot for the very detailed response.
>
> I tried your second option but could not make it work.
>
> That's the message I get:
>
> [qtp1721979929-14] WARN org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
> - No root resource matching request path
> /auth/oauth2/WEB-INF/jsp/login_full.jsp has been found, Relative Path:
> /WEB-INF/jsp/login_full.jsp. Please enable FINE/TRACE log level for more
> details.
>
> Is there any aditional configuration in the web.xml that is needed to make
> it works?
>
Yes, check the link I forwarded you re making sure CXFServlet is not
catching a redirect. One way to do is to restrict CXFServlet URL pattern
and if that is not possible then configure CXFServlet to redirect to
"jsp" for any requests having a jsp prefix, check that link please
Sergey
> Thanks
> Marcelo
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
Re: Fowarding to jsp from CXF
Posted by Marcelo Alcantara <ma...@gmail.com>.
Hi Sergey,
Thanks a lot for the very detailed response.
I tried your second option but could not make it work.
That's the message I get:
[qtp1721979929-14] WARN org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor
- No root resource matching request path
/auth/oauth2/WEB-INF/jsp/login_full.jsp has been found, Relative Path:
/WEB-INF/jsp/login_full.jsp. Please enable FINE/TRACE log level for more
details.
Is there any aditional configuration in the web.xml that is needed to make
it works?
Thanks
Marcelo
--
Marcelo Alcantara
Senior Developer/Architect
--------------------------------------------------------
maralc@gmail.com
+64 21 0612324
On Wed, Nov 13, 2013 at 11:27 PM, Sergey Beryozkin <sb...@gmail.com>wrote:
> Hi
>
> On 13/11/13 07:04, Marcelo Alcantara wrote:
>
>> Hi
>>
>> I need to redirect to a jsp that is inside WEB-INF from a CXF/Jetty
>> started
>> server.
>>
>> How can I redirect from inside a rest service to a jsp that is inside
>> WEB-INF/jsp?
>>
>> I tried doing a simple servlet forward but it always use the app context
>> regardless of weather the path starts with '/' or not.
>>
>> I also saw the documentation but in my case the jsp is not related at all
>> with any entity (it's a login page).
>>
>>
> Assuming your work with CXF 2.7.7, then what you can do is to use JAX-RS
> 2.0 Pre-Matching ContainerRequestFilter which will block the request with a
> ready Response, this Response would set a media type text/html and set the
> 'marker' entity either an enum (ex, LOGIN_REQUIRED) or some empty class
> like LoginRequired, using enums can be cheaper, and then configure CXF
> RequestDispatcherProvider as suggested here:
>
> http://cxf.apache.org/docs/jax-rs-redirection.html#JAX-RSRedirection-
> WithRequestDispatcherProvider, check the example on configuring it with
> enums if you chose to work with enums.
>
> Note, setting a 'marker' entity in Response is needed because otherwise
> RequestDispatcherProvider, being JAX-RS MessageBodyWriter, won't be
> activated.
>
> However you can avoid using RequestDispatcherProvider by doing something
> like this in your custom ContainerRequestFilter (vaguely referred to in
> http://cxf.apache.org/docs/jax-rs-redirection.html#JAX-RSRedirection-
> CustomRedirection):
>
> 1. inject "@Context HttpServletRequest request";
> 2. PhaseInterceptorChain.getCurrentMessage().put(AbstractHTTPDestination.REQUEST_REDIRECTED,
> true);
> 3. Use HttpServletRequest to get to RequestDispatcher and forward the
> request to the chosen jsp resource
>
> This will work fine too.
>
> Finally, if you have CXFServlet using a wildcard url pattern, then you'd
> need to further restrict it to ensure the above redirects do not get
> captured by the same servlet
>
> HTH, Sergey
>
>
> Thanks in advance.
>>
>> Marcelo
>>
>>
>
Re: Fowarding to jsp from CXF
Posted by Sergey Beryozkin <sb...@gmail.com>.
On 13/11/13 10:27, Sergey Beryozkin wrote:
> Hi
> On 13/11/13 07:04, Marcelo Alcantara wrote:
>> Hi
>>
>> I need to redirect to a jsp that is inside WEB-INF from a CXF/Jetty
>> started
>> server.
>>
>> How can I redirect from inside a rest service to a jsp that is inside
>> WEB-INF/jsp?
>>
>> I tried doing a simple servlet forward but it always use the app context
>> regardless of weather the path starts with '/' or not.
>>
>> I also saw the documentation but in my case the jsp is not related at all
>> with any entity (it's a login page).
>>
>
> Assuming your work with CXF 2.7.7, then what you can do is to use JAX-RS
> 2.0 Pre-Matching ContainerRequestFilter which will block the request
> with a ready Response, this Response would set a media type text/html
> and set the 'marker' entity either an enum (ex, LOGIN_REQUIRED) or some
> empty class like LoginRequired, using enums can be cheaper, and then
> configure CXF RequestDispatcherProvider as suggested here:
>
> http://cxf.apache.org/docs/jax-rs-redirection.html#JAX-RSRedirection-WithRequestDispatcherProvider,
> check the example on configuring it with enums if you chose to work with
> enums.
>
> Note, setting a 'marker' entity in Response is needed because otherwise
> RequestDispatcherProvider, being JAX-RS MessageBodyWriter, won't be
> activated.
>
> However you can avoid using RequestDispatcherProvider by doing something
> like this in your custom ContainerRequestFilter (vaguely referred to in
> http://cxf.apache.org/docs/jax-rs-redirection.html#JAX-RSRedirection-CustomRedirection):
>
>
> 1. inject "@Context HttpServletRequest request";
> 2.
> PhaseInterceptorChain.getCurrentMessage().put(AbstractHTTPDestination.REQUEST_REDIRECTED,
> true);
> 3. Use HttpServletRequest to get to RequestDispatcher and forward the
> request to the chosen jsp resource
>
> This will work fine too.
>
> Finally, if you have CXFServlet using a wildcard url pattern, then you'd
> need to further restrict it to ensure the above redirects do not get
> captured by the same servlet
>
Which is described in more detail here
http://cxf.apache.org/docs/jax-rs-redirection.html#JAX-RSRedirection-WithCXFServlet
> HTH, Sergey
>
>
>> Thanks in advance.
>>
>> Marcelo
>>
>
Re: Fowarding to jsp from CXF
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 13/11/13 07:04, Marcelo Alcantara wrote:
> Hi
>
> I need to redirect to a jsp that is inside WEB-INF from a CXF/Jetty started
> server.
>
> How can I redirect from inside a rest service to a jsp that is inside
> WEB-INF/jsp?
>
> I tried doing a simple servlet forward but it always use the app context
> regardless of weather the path starts with '/' or not.
>
> I also saw the documentation but in my case the jsp is not related at all
> with any entity (it's a login page).
>
Assuming your work with CXF 2.7.7, then what you can do is to use JAX-RS
2.0 Pre-Matching ContainerRequestFilter which will block the request
with a ready Response, this Response would set a media type text/html
and set the 'marker' entity either an enum (ex, LOGIN_REQUIRED) or some
empty class like LoginRequired, using enums can be cheaper, and then
configure CXF RequestDispatcherProvider as suggested here:
http://cxf.apache.org/docs/jax-rs-redirection.html#JAX-RSRedirection-WithRequestDispatcherProvider,
check the example on configuring it with enums if you chose to work with
enums.
Note, setting a 'marker' entity in Response is needed because otherwise
RequestDispatcherProvider, being JAX-RS MessageBodyWriter, won't be
activated.
However you can avoid using RequestDispatcherProvider by doing something
like this in your custom ContainerRequestFilter (vaguely referred to in
http://cxf.apache.org/docs/jax-rs-redirection.html#JAX-RSRedirection-CustomRedirection):
1. inject "@Context HttpServletRequest request";
2.
PhaseInterceptorChain.getCurrentMessage().put(AbstractHTTPDestination.REQUEST_REDIRECTED,
true);
3. Use HttpServletRequest to get to RequestDispatcher and forward the
request to the chosen jsp resource
This will work fine too.
Finally, if you have CXFServlet using a wildcard url pattern, then you'd
need to further restrict it to ensure the above redirects do not get
captured by the same servlet
HTH, Sergey
> Thanks in advance.
>
> Marcelo
>