6 Replies Latest reply on Apr 12, 2013 9:30 AM by dako_t

    FUSE-ESB 4.4.1: can't create specific fault for cxf web service

    dako_t

      Hi all,

       

      I can't create a specific fault message for a cxf web service. The web service works fine but if an error occurs I get always

      a common soap error. I've tested it with soapUI and got the following response after an Exception within my camel route:

       

       

        <soap:Fault>

          <faultcode>soap:Server</faultcode>

          <faultstring>Fault occurred while processing.</faultstring>

        </soap:Fault>

       

           

       

        This is my route which starts with an cxf web service invocation in OSGI module A.

       

       

              <camelContext xmlns="http://camel.apache.org/schema/spring">

                      <route id="getPositions4ShipsEndpointRoute">

                              <from uri="cxf:bean:getPositions4ShipsEndpoint"/>

                              <bean ref="consumerLayerService" method="fillExchangeWithMinDateOfData"/>

                              <to uri="activemq:queue:getPositions4Ships"/>

                      </route>

              </camelContext>

              

       

               

              In OSGI module B I have a route and an exception handler. within the method "getPositions4Ships" I create a StringIndexOutOfBoundsException.

               

              <camelContext xmlns="http://camel.apache.org/schema/spring">

              

                      <propertyPlaceholder id="properties" location="ref:props"/>

                      

                      <onException>

                              <exception>java.lang.Exception</exception>

                              <handled><constant>true</constant></handled>

                              <transform>

                                      <simple>$</simple>

       

                              </transform>

                              <to uri="activemq:queue:exceptionHandlerQueue"/>

                      </onException>

                      

                      <route id="getPositions4ShipsDataRoute">

                              <from uri="activemq:queue:getPositions4Ships" />

                              <bean ref="aisDataService" method="getPositions4Ships"/>

                      </route>

       

              </camelContext>

       

               

              After the exception is thrown the route ends within the "errorService".

         

        <camelContext xmlns="http://camel.apache.org/schema/spring">

              

                      <route id="exceptionHandlerRoute">

                              <from uri="activemq:queue:exceptionHandlerQueue" />

                              <bean ref="errorService" method="returnErrorMessage"/>

                      </route>

              

              </camelContext>

       

               

              This is the code of the method "returnErrorMessage".

        The expected StringIndexOutOfBoundsException was logged but the web service returns always the fault string listed above "Fault occurred while processing.".

               

              public void returnErrorMessage(Exchange exchange) {

                      

                      Throwable cause = exchange.getIn().getBody(Exception.class);

                      String errorMessage = cause.getMessage();

                      log.error("returnErrorMessage, exception:", exchange.getIn().getBody());

                      

                      SoapFault fault = new SoapFault(errorMessage, new QName("ff", "dd"));

                      fault.setMessage(errorMessage);

                      

                      exchange.getOut().setFault(true);

                      exchange.getOut().setBody(fault);

              }

       

              

              What should I change to return a specific error?

              

              After invoking the method "returnErrorMessage" I have the following warning within my ServiceMix log:

              

              13:11:55,995 | WARN  | qtp4895594-292   | PhaseInterceptorChain | 141 - org.apache.cxf.bundle - 2.4.6 | Interceptor for GetAisPositions4DVElbeEndpointService#getPositions4Ships has thrown exception, unwinding now

      org.apache.cxf.interceptor.Fault

              at org.apache.cxf.databinding.AbstractWrapperHelper.createWrapperObject(AbstractWrapperHelper.java:107)[141:org.apache.cxf.bundle:2.4.6]

              at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:105)[141:org.apache.cxf.bundle:2.4.6]

              at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)[141:org.apache.cxf.bundle:2.4.6]

               

               

              Within my Karaf console I see the following stack trace:

       

      java.lang.IllegalArgumentException: argument type mismatch

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

              at java.lang.reflect.Method.invoke(Method.java:597)

              at org.apache.cxf.databinding.AbstractWrapperHelper.createWrapperObject(AbstractWrapperHelper.java:99)

              at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:105)

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

              at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)

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

              at org.apache.cxf.phase.PhaseInterceptorChain.resume(PhaseInterceptorChain.java:232)

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

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

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

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

              at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:939)

              at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:875)

              at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)

              at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:185)

              at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)

              at org.eclipse.jetty.server.Server.handleAsync(Server.java:391)

              at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:594)

              at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:393)

              at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535)

              at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)

              at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529)

              at java.lang.Thread.run(Thread.java:619)

       

      Edited by: akunze on Mar 14, 2013 10:42 AM