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