Hi Sergey I have tried extending the CXFServlet and overriding the redirect method as you suggest. But the response is empty by that time -
By the time redirect method is invoked has the CXFServlet already intercepted the .jsp request and created a new Response (discarding the one generated when the JSP was initially processed by the servlet container) ? From: Sergey Beryozkin [mailto:[email protected]] Sent: 05 January 2010 14:22 To: Paul Wilton Cc: [email protected] Subject: RE: another question on RequestDispatcherProvider Hi Paul I think I understand now what has to be fixed. CXFServlet's redirect-list is useful for redirecting as opposed to blocking which is what we need here. So I will introduce say a block-list parameter which will be used to block certain requests, given that in some cases users will also redirect to public resources located above /WEB-INF with CXFServlet having a '/' uri-pattern... In meantime, as a workaround, you might want to extend a CXFServlet and override its redirect(...) method : protected void redirect(HttpServletRequest request, HttpServletResponse response, String pathInfo) { if (pathInfo.endsWith(".jsp")) { return; } super.redirect(...); } Give it a try please and let me know if it helps, but either way I will add a block-list parameter cheers, Sergey -----Original Message----- From: Paul Wilton [mailto:[email protected]] Sent: Tue 1/5/2010 8:29 AM To: Sergey Beryozkin Cc: [email protected] Subject: RE: another question on RequestDispatcherProvider Hi Sergey I just tried it. But after SPRING MVC has processed the request and the forwarded to the jsp the CXFServlet still then attempts to redirect to the JSP resource - which fails (as it is not reachable) - see stack trace Shouldn't the CXFServlet should not be intercepting internal request forwards at all ? If I run the CXFServlet on a more specific URL, then it is all okay - the JSP rendered response is returned - but ideally I want to run my CXF servlet on the root URL. My CXF servlet config is here: <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-clas s> <init-param> <param-name>redirects-list</param-name> <param-value>/WEB-INF/jsp/(\w)+.jsp</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> javax.servlet.ServletException: RequestDispatcher for path /WEB-INF/jsp/test.jsp has failed org.apache.cxf.transport.servlet.AbstractHTTPServlet.redirect(AbstractHT TPServlet.java:234) org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(Abstr actHTTPServlet.java:170) org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPS ervlet.java:108) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTT PServlet.java:159) org.springframework.web.servlet.view.InternalResourceView.renderMergedOu tputModel(InternalResourceView.java:236) org.springframework.web.servlet.view.AbstractView.render(AbstractView.ja va:257) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServl et.java:1183) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherS ervlet.java:902) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherSe rvlet.java:807) org.springframework.web.servlet.FrameworkServlet.processRequest(Framewor kServlet.java:571) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet. java:501) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) From: Sergey Beryozkin [mailto:[email protected]] Sent: 05 January 2010 13:01 To: Paul Wilton; [email protected] Subject: RE: another question on RequestDispatcherProvider Hi Paul Sorry for a delay, I was off yesterday for most of the day, working for half a day today and will likely work all day tomorrow... I suspect it has something to do with the fact that the path starts with /WEB-INF (and with '/') and that CXFServlet has a capture-all '/'. So when the forward occurs, the JSP page is being invoked but CXFServlet gets this call too. If you prefer to have CXFServlet capturing '/' then you can configure it like this : <init-param> <param-name>redirects-list</param-name> <param-value>/(\w)+.jsp</param-value> </init-param> So it may act as a guard in ensuring no recursive calls go through this CXFServlet, it will just ensure that a jsp call will not escape back into the CXF interceptors chain. Give it a try please and let me know if it helps. cheers, Sergey -----Original Message----- From: Paul Wilton [mailto:[email protected]] Sent: Tue 1/5/2010 7:15 AM To: [email protected]; Sergey Beryozkin Subject: RE: another question on RequestDispatcherProvider If I change my cxfservlet to run on a more specific URL than "/" then it all works fine. But unfortunately I am not keen to do that... Which results in the /WEB-INF/jsp/*.jsp forwards all being picked up by the CXF servlet... I can understand the CXFServlet picking up redirects - but not forwards -----Original Message----- From: Paul Wilton [mailto:[email protected]] Sent: 05 January 2010 09:17 To: [email protected] Cc: [email protected] Subject: FW: another question on RequestDispatcherProvider Hi Sergey Sorry to bug you :( Of course it is perfectly feasible I am doing something wrong here, but with cxf 2.2.5 if I forward (delegate) a request to a JSP resource, whether from the CXF servlet or another servlet, the CXF jaxrs IN interceptor picks up the forward and tries to match it against a URL processing rule ? throwing a jaxrs method not found error. Any chance you could take a look and provide some guidance Much appreciated Paul Wilton -----Original Message----- From: Paul Wilton [mailto:[email protected]] Sent: 04 January 2010 15:47 To: [email protected] Subject: RE: another question on RequestDispatcherProvider Even if I create a separate spring MVC servlet that delegates to the JSP, after spring MVC has processed the request and forwarded to the JSP, my jaxrs:server JAXRSInInterceptor still tries to intercept and process the /WEB-INF/jsp/test.jsp URL and throws a method not found error. Any clues on how to prevent this ? -----Original Message----- From: Paul Wilton [mailto:[email protected]] Sent: 04 January 2010 15:08 To: [email protected] Subject: RE: another question on RequestDispatcherProvider okay - I have a two jaxrs:server beans configured on different URLS, It seems when the first one completes the other is picking up the forward from the first one... very confusing. -----Original Message----- From: Paul Wilton [mailto:[email protected]] Sent: 04 January 2010 14:17 To: [email protected] Subject: RE: another question on RequestDispatcherProvider Just to follow up on this, here is a thread dump showing the call stack at the point the WARNIGN message is output. You can see how the forward is being recycled through the JAXRSInInterceptor chain after the RequestDispatcherProvider.writeTo() method has successfully delegated (forwarded) to the JSP. http-808...@7 daemon, prio=5, in group 'main', status: 'runnable' java.lang.Thread.State: RUNNABLE at org.apache.cxf.jaxrs.utils.JAXRSUtils.logNoMatchMessage(JAXRSUtils.java: 381) at org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:3 37) at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRS InInterceptor.java:148) at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSI nInterceptor.java:63) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC hain.java:236) at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiati onObserver.java:109) at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestin ation.java:98) at org.apache.cxf.transport.servlet.ServletController.invokeDestination(Ser vletController.java:394) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletControl ler.java:133) at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFSe rvlet.java:142) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(Abstr actHTTPServlet.java:179) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPS ervlet.java:108) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTT PServlet.java:159) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:206) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatc her.java:646) at org.apache.catalina.core.ApplicationDispatcher.processRequest(Applicatio nDispatcher.java:436) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDisp atcher.java:374) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispat cher.java:302) at org.apache.cxf.jaxrs.provider.RequestDispatcherProvider.writeTo(RequestD ispatcherProvider.java:104) at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JA XRSOutInterceptor.java:232) at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAX RSOutInterceptor.java:137) at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRS OutInterceptor.java:77) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC hain.java:236) at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Outgoi ngChainInterceptor.java:76) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC hain.java:236) at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiati onObserver.java:109) at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestin ation.java:98) at org.apache.cxf.transport.servlet.ServletController.invokeDestination(Ser vletController.java:394) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletControl ler.java:133) at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFSe rvlet.java:142) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(Abstr actHTTPServlet.java:179) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPS ervlet.java:108) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTT PServlet.java:159) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv e.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv e.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java :128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java :102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:2 93) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:84 9) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process( Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Thread.java:619) -----Original Message----- From: Paul Wilton [mailto:[email protected]] Sent: 04 January 2010 14:10 To: [email protected] Subject: another question on RequestDispatcherProvider I am experiencing some unexpected behaviour when using RequestDispatcherProvider to delegate a request to a JSP After the service method has been executed the writeTo method on the RequestDispatcherProvider is invoked, and correctly forwards to my JSP using javax.servlet.RequestDispatcher.forward(request,response) However at that point, somewhere during/after the forward, the JAXRSOutInterceptor picks up the forwarded request (the JSP path) as if it's a redirect and throws a 404 error trying to martch the forward against one of its JAX-RS patterns: "No operation matching request path /WEB-INF/jsp/test.jsp is found" I would have expected the response from the forward to be returned directly to the client - but it somehow seems to be being recycled (redirected) back into the JAX-RS interceptor chain. I am using CXF 2.2.5 Wiring as follows: <jaxrs:server id="testRestServer" address="/test/"> <jaxrs:serviceBeans> <ref bean="testServer"/> </jaxrs:serviceBeans> <jaxrs:providers> <ref bean="dispatchProvider1"/> </jaxrs:providers> </jaxrs:server> <bean id="dispatchProvider1" class="org.apache.cxf.jaxrs.provider.RequestDispatcherProvider"> <property name="resourcePath" value="/WEB-INF/jsp/test.jsp"/> <property name="scope" value="request"/> </bean> <bean id="testServer" class="my.package.TestServer" /> public class TestServer { @GET @Path("/test") public Test getTest() { Test test = new test("hello world"); return test; } } On requesting GET /test/test The method TestServer.getTest() is being invoked and the RequestDispatcherProvider subsequently calls RequestDispactyer.forward() to the /WEB-INF/jsp/test.jsp (which renders the message from the Test object) However, I am then subsequently getting an error : Jan 4, 2010 1:51:31 PM org.apache.cxf.jaxrs.utils.JAXRSUtils findTargetMethod WARNING: .No operation matching request path /WEB-INF/jsp/test.jsp is found As the forward is recycled through the JAXRS interceptor as a redirect or incoming request, resulting in a 404. This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. If you have received it in error, please delete it from your system. Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. Please note that the BBC monitors e-mails sent or received. Further communication will signify your consent to this This e-mail has been sent by one of the following wholly-owned subsidiaries of the BBC: BBC Worldwide Limited, Registration Number: 1420028 England, Registered Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ BBC World News Limited, Registration Number: 04514407 England, Registered Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ BBC World Distribution Limited, Registration Number: 04514408, Registered Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
