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. 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> 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. Any help is much appreciated. Best regards, Marko