Hi,

Please see comments below
On 07/04/15 14:42, Voss, Marko wrote:
Hello,

I do have the following situation:

We have to use the CXFNonSpringJaxrsServlet for implementing the REST endpoints.

The main servlet (old code to be replaced by the new REST endpoints) of the 
application does implement internal forwarding to JSP pages. (for example to a 
login page)


1.      I tried to implement the forwarding as it was already done by the old 
servlet using:

@Context
private ServletContext context;

context.getRequestDispatcher(url).forward(request, response);

But this does not work, because of a ClassCastException happening. The 
exception message was like: The ThreadLocal instance for ServletContext could 
not be casted to the RequestDispatcher instance, which is provided by the 
server. (NetWeaver)

The ThreadLocal object is provided by CXF and the RequestDispatcher 
implementation is provided by NetWeaver. Of course, this will not work.
Hmm, interesting, may make sense supporting this variation, I'll have a look...



2.       I was trying to use the RequestDispatcherProvider of CXF, but how can 
you configure this provider using the CXFNonSpringJaxrsServlet?

<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>
                     ...
                     </param-value>
              </init-param>
              <init-param>
                     <param-name>jaxrs.providers</param-name>
                     <param-value>
                     org.apache.cxf.jaxrs.provider.RequestDispatcherProvider
                     <!-- How to configure this one here??? -->
                     </param-value>
              </init-param>
              <load-on-startup>1</load-on-startup>
        </servlet>


The simplest way to do at a servlet level is to use redirect parameters, see

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=a2212337bd6a9ed7a212b21a6826850581601121;hb=HEAD

or indeed you can directly configure this provider (and other providers) as a parameter, do something like

org.apache.cxf.jaxrs.provider.RequestDispatcherProvider(resourcePath=/WEB-INF/jsp/test.jsp someotherproperty=somevalue)



3.       I was trying to implement a RequestHandler, which worked but when the 
forwarding happens, I get spammed by error messages on server side, that the 
OutputStreams of the servlets are already taken by a getWriter() method. This 
spam should be avoided. Example Spam:

WARNING: Interceptor for {http://impl.jaxrs.web.foo.bar/}MyServiceImpl has 
thrown exception, unwinding now
com.sap.engine.services.servlets_jsp.server.exceptions.WebIllegalStateException:
 The stream has already been taken by method [getWriter()].
at 
com.sap.engine.services.servlets_jsp.server.runtime.client.HttpServletResponseFacade.getOutputStream(HttpServletResponseFacade.java:244)

This servlet is not in use at all at this point of the request and not after 
the request as well. So I wonder in general, why this exception occurs on this 
servlet. It is maybe a NetWeaver thing.


4.       I was trying to implement an equivalent to the 
RequestDispatcherProvider, doing things here by code. But even when this works, 
I still get the spam from above.

In both cases the outbound CXF JAX-RS interceptor and Http transport need to know the request has been redirected, this can be done by setting an "http.request.redirected" property on the current message,

message.put("http.request.redirected", true)

But the option 2 is simpler, can you try it and let me know if it works for you ?

Thanks, Sergey


Any help is much appreciated.


Best regards,

Marko


Reply via email to