4 Replies Latest reply on Oct 15, 2009 2:56 AM by inalasuresh

    In OUT interceptor of a CXF provider, how can we stop the provider invoking its endpoint and send a response back?

    inalasuresh

      Hi One & All

       

      While we are working on Delegate (for cxfbc:provider) for FUSE, we have some technical issues and need some assistance.

       

      Problem Description

       

      In OUT interceptor of a CXF provider, how can we stop the provider invoking its endpoint and send a response back?

       

      Example:

      I have a cxfbc:provider with some interceptors configured for both IN and OUT flows. When the cxf provider is making a request, the OUT interceptor gets invoked and in this interceptor I would like to stop invoking actual endpoint and send back my own response. That means I should be able to tell the interceptor chain to stop further processing of this flow, set a response message into message exchange and invoke the IN flow. How do I do that?

       

      This kind of mediation/interception is possible in standard specifications like JAX-RPC, JAX-WS, Servlets etc? wondering if CXF provides any sort of this kind.

       

      Also we would like to know who is invoking a provider endpoint in CXF stack in FUSE? Is it an OUT interceptor at the end of interceptor chain or some other transport component after the interceptor chain?

       

      Thanks in Advance

          Suresh

        • 1. Re: In OUT interceptor of a CXF provider, how can we stop the provider invoking its endpoint and send a response back?
          lvisnick

          Have you taken a look at the CXF interceptor demo under samples/configuration_interceptor?

           

          if not, please use that as a starting point.

          Tx,

          Lorinda

          • 2. Re: In OUT interceptor of a CXF provider, how can we stop the provider invoking its endpoint and send a response back?
            ubhole

            Hi Suresh,

            you can interrupt CXF interceptor chain and install your own from your custom interceptor which will stop the invocation. However, you might have to be very careful about few interceptor that might need to be invoked for things like header filtering done for JAX-WS spec. compliance etc. You need to take into account such interceptor and handle them properly in your own interceptor chain. Same is true for some servicemix interceptors in the chain which may be managing normalized message exchange and such things. In your case simple thing I can think of if you want to stop invocation for all request is to add internal CXF-SE SU which will internally accept the requests and return response. It is a proper invocation but atleast would not mess around with the interceptor chain.

             

            Regards,

             

            Ulhas Bhole

            • 4. Re: In OUT interceptor of a CXF provider, how can we stop the provider invoking its endpoint and send a response back?
              inalasuresh

              Hi Every one,

               

              As of your suggesions i am using the 2nd option.

              in this i am able to get the response with the hard coded value like (String xml = "<s12:Envelope> ...</s12:Envelope>).

               

              Example code given below.

              -


              message (Message msgContext){

              MessageImpl messageImpl = new MessageImpl();

              Exchange exchange = msgContext.getExchange();

              exchange.setInMessage(messageImpl);

              messageImpl.setExchange(exchange);

              //byte[] theByteArray = xml.getBytes();

              //messageImpl.setContent(InputStream.class , new ByteArrayInputStream(theByteArray));

              messageImpl.setContent(InputStream.class , new ByteArrayInputStream(context.getMessageBytes()));

              messageImpl.put(PhaseInterceptorChain.STARTING_AT_INTERCEPTOR_ID,BaseCXFLiteInterceptor.class.getName());

              Conduit conduit = exchange.getConduit(messageImpl);

              ((AbstractConduit)conduit).getMessageObserver().onMessage(exchange.getInMessage());

              }

               

              but while response time i am getting following exception. how could i overcome/solve this issue.

               

              Service mix Console

              -


              WARN  - PhaseInterceptorChain          - Interceptor has thrown exception, unwinding now

              org.apache.cxf.binding.soap.SoapFault: "http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper", the namespace on the "message" element, i

              s not a valid SOAP version.

                      at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:102)

                      at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:58)

                      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)

                      at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:104)

                      at org.apache.servicemix.cxfbc.CxfBcConsumer$JbiChainInitiationObserver.onMessage(CxfBcConsumer.java:644)

                      at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:302)

                      at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:266)

                      at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:70)

                      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)

                      at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)

                      at org.mortbay.jetty.handler.HandlerList.handle(HandlerList.java:49)

                      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)

                      at org.mortbay.jetty.Server.handle(Server.java:324)

                      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:534)

                      at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:879)

                      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:828)

                      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:213)

                      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:403)

                      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)

                      at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:522)

              WARN  - PhaseInterceptorChain          - Interceptor has thrown exception, unwinding now

              org.apache.servicemix.cxfbc.interceptors.JbiFault: Fault occured

                      at org.apache.servicemix.cxfbc.CxfBcConsumer$JbiPostInvokerInterceptor.handleMessage(CxfBcConsumer.java:791)

                      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)

                      at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:104)

                      at org.apache.servicemix.cxfbc.CxfBcConsumer$JbiChainInitiationObserver.onMessage(CxfBcConsumer.java:644)

                      at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:302)

                      at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:266)

                      at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:70)

                      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)

                      at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)

                      at org.mortbay.jetty.handler.HandlerList.handle(HandlerList.java:49)

                      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)

                      at org.mortbay.jetty.Server.handle(Server.java:324)

                      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:534)

                      at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:879)

                      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:741)

                      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:213)

                      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:403)

                      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)

                      at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:522)

               

               

              Thanks & Regards

                Suresh