Hello all, I need some help with server-side inbound interceptors.
I am working on a custom interceptor, which performs authentication before invoking the actual service. My problem is: this interceptor must be able to directly send a custom response, generated as a javax.xml.soap.SOAPMessage object, without invoking the service. I already tried some "solutions" based on what I found in an old<http://old.nabble.com/Re:-In-OUT-interceptor-of-a-CXF-provider,-how-can-we-stop-the-provider-invoking-its-endpoint-and-send-a-response-back--p25685633.html> p<http://old.nabble.com/Re:-In-OUT-interceptor-of-a-CXF-provider,-how-can-we-stop-the-provider-invoking-its-endpoint-and-send-a-response-back--p25685633.html> ost<http://old.nabble.com/Re:-In-OUT-interceptor-of-a-CXF-provider,-how-can-we-stop-the-provider-invoking-its-endpoint-and-send-a-response-back--p25685633.html>, but I cannot achieve to send my message correctly. Here is what I tried: // 1- Get the generated response as a javax.xml.soap.SOAPMessage object SOAPMessage response = // Get the generated response to send // 2- Create a CXF-specific response (SoapMessage) // I tried this solution: MessageImpl msg = new MessageImpl(); SoapMessage outMessage = new SoapMessage(msg); // And this other solution: Exchange exchange = this.currentMessage.getExchange(); // this.currentMessage is actually the CXF-specific request being processed (SoapMessage object) Endpoint ep = exchange.get(Endpoint.class); Message outMessage = exchange.getOutMessage(); if (outMessage == null) { outMessage = ep.getBinding().createMessage(); } // 3- Set the SOAPMessage response into a CXF-specific response outMessage.setContent(SOAPMessage.class, response); // 4- Put the CXF-specific message into the current message exchange exchange.setOutMessage(soapResponseMsg); soapResponseMsg.setExchange(exchange); // 5- Not being able to send the response through the conduit (which, if I understand, only exists on the client-side), I tried to remove the service invocation from the interceptor chain: InterceptorChain inchain = this.currentMessage.getInterceptorChain(); ListIterator<Interceptor<? extends Message>> it = inchain.getIterator(); while (it.hasNext()) { Interceptor<? extends Message> icept = it.next(); if (icept instanceof ServiceInvokerInterceptor) { inchain.remove((ServiceInvokerInterceptor)icept); break; } } // I also tried to indicate that the exchange is over, but it just stopped the processing (this seems to be the solution when working on a server-side *out*bound interceptor) exchange.put("exchange.finished", Boolean.TRUE); I tried many variations, but I keep getting exceptions (mainly caused by NPEs) when I try to access a webservice. This seems to come from my message content type (javax.xml.soap.SOAPMessage) or most probably from the way I am trying to set it inside the response (CXF SoapMessage). The exceptions I get when using the code(s) above are of this kind in the outbound chain ( org.ow2.jonas.example.jaspic.ws contains the service I am actually requesting): 2010-08-23 14:46:43,231 : LogUtils.log : Interceptor for { http://ws.jaspic.example.jonas.ow2.org/}NewWebServiceService#{http://ws.jaspic.example.jonas.ow2.org/}testOperationhas thrown exception, unwinding now org.apache.cxf.interceptor.Fault at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:119) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243) at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:78) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243) at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:110) at org.ow2.jonas.ws.cxf.http.JOnASDestination.invoke(JOnASDestination.java:111) at org.ow2.jonas.ws.cxf.jaxws.CXFWSEndpoint.invoke(CXFWSEndpoint.java:151) at org.ow2.jonas.ws.jaxws.http.servlet.JAXWSServlet.invokeDestination(JAXWSServlet.java:113) at org.ow2.jonas.ws.jaxws.http.servlet.JAXWSServlet.doPost(JAXWSServlet.java:75) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.ow2.jonas.web.tomcat6.CheckOpenResourcesValve.invoke(CheckOpenResourcesValve.java:73) at org.ow2.jonas.web.tomcat6.tx.TransactionValve.invoke(TransactionValve.java:90) at org.ow2.jonas.web.tomcat6.ResetAuthenticationValve.invoke(ResetAuthenticationValve.java:95) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 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:341) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:595) Caused by: java.lang.NullPointerException at org.ow2.jonas.example.jaspic.ws.jaxws_asm.TestOperationResponse_WrapperTypeHelper1.createWrapperObject(Unknown Source) at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:103) ... 25 more 2010-08-23 14:46:43,234 : PhaseInterceptorChain.unwind : Invoking handleFault on interceptor org.apache.cxf.jaxws.interceptors.wrapperclassoutintercep...@4db282 [Other fault handling invocations...] Actually, I think that most of the interceptors in the chains (in- and out-bound) just cannot handle a SOAPMessage, but only Lists or XML content. So my questions are: is it possible to create a CXF response message from a SOAPMessage object ? If so, what would be the best way to do it ? How can I tell CXF runtime to directly send the response message ? Thank you very much. -- Marian MULLER SERLI
