Announcement Announcement Module
No announcement yet.
Spring Integration WebServices Gateway - Handling fault messages Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Integration WebServices Gateway - Handling fault messages

    What is the best way to handle a returned fault message from a webservice? I am using int-ws:outbound-gateway to invoke a soap webservice, so I am interested to handle fault messages and send them to an error channel.

    I can use the fault-message-resolver and in the resolveFault method send the message to a channel bean but not sure if that the right way to do it.


  • #2

    Some tipical usage of ws:outbound-gateway without any fault-message-resolver.
    On the background WebServiceTemplate initializes some default DefaultStrategies.
    One of them is essageResolver from
    in the classpath inside spring-ws-core.jar.
    If you look at this class you'll see it throws SoapFaultClientException.
    This Exception will be thrown in the caller thread and you can wrap ws:outbound-gateway with try ... catch.
    It is first strategy. In this case an error-channel doesn't make sense: it won't be reachable.

    The second can be based on async massage flow which contains ws:outbound-gateway.
    In this case SoapFaultClientException can be sended into error-channel as MessagingException's payload of ErrorMassage.

    And there is some third strategy:
    You can write your own FaultMessageResolver's implementation, where you just return SoapFaultClientException, not throw!
    On ws:outbound-gateway's reply-channel you hang a payload-type-router. And if your payload is SoapFaultClientException you route it to the error-channel.

    Hope, that help.

    Nevertheless, I may miss something...

    Artem Bilan


    • #3

      Thanks for the reply.

      Looking at strategy 3, the SoapFaultMessageResolver or FaultMessageResolver method

      public void resolveFault(WebServiceMessage message)

      has a void return type, so how to return a SoapFaultClientException ?



      • #4
        Ok, thanks for your attentiveness

        What I can propose?

        1. Implement FaultMessageResolver
        2. Inject into him some POJI-Gateway and invoke its with your appropriate parameter.
        3. Map Gateway's method to some error-channel.

        and voila!


        • #5
          Thanks for the quick response.

          As I understand, thats almost the same thing as my original idea, use fault-message-resolver and implement a fault resolver and inject into him the error channel. isn't it?



          • #6
            and inject into him the error channel
            It will be some integration bad practice...

            Do not combine your business-services with messaging system components...


            • #7
              thank you very much Cleric, very helpful


              • #8

                Also there is some interest solution.
                To mark FaultMessageResolver#resolveFault with @Publisher:
                @Publisher(channel = "errorChannel")
                 public void resolveFault(WebServiceMessage message) throws IOException {
                        SoapMessage soapMessage = (SoapMessage) message;
                        throw new SoapFaultClientException(soapMessage);
                In this case the exception will be thrown in the caller thread and the message with exception payload will be send to the errorChannel by the PublisherInterceptor.


                • #9
                  Thanks Cleric, very nice.

                  I tried it but getting this exception, I guess that the fault returned by the service contains unserializable exception within the chain of exceptions, tried to replace it with another exception but that didn't trigger the aop to capture the exception...

                  org.springframework.integration.MessagingException : failed to handle incoming JMS Message
                  at org.springframework.integration.jms.SubscribableJm sChannel$DispatchingMessageListener.onMessage(Subs
                  at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doInvokeListener(AbstractMessageLi
                  at org.springframework.jms.listener.AbstractMessageLi stenerContainer.invokeListener(AbstractMessageList
                  at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doExecuteListener(AbstractMessageL
                  at org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.doReceiveAndExecute(Abstrac
                  at org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.receiveAndExecute(AbstractP
                  at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.invokeL istener(
                  at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.execute OngoingLoop( 050)
                  at org.springframework.jms.listener.DefaultMessageLis tenerContainer$
                  Caused by: org.springframework.integration.MessageHandlingExc eption: error occurred in message handler [org.springframework.integration.jms.JmsSendingMess ageHandler#0]
                  at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:84)
                  at org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch( :110)
                  at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch( 7)
                  at bscribableChannel.doSend(AbstractSubscribableChann
                  at ssageChannel.send(
                  at ssageChannel.send(
                  at org.springframework.integration.core.MessagingTemp late.doSend(
                  at org.springframework.integration.core.MessagingTemp late.send(
                  at org.springframework.integration.aop.MessagePublish ingInterceptor.publishMessage(MessagePublishingInt
                  at org.springframework.integration.aop.MessagePublish ingInterceptor.invoke(MessagePublishingInterceptor .java:116)
                  at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed( :172)
                  at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(
                  at $Proxy39.resolveFault(Unknown Source)
                  at ate.handleFault(
                  at ate.doSendAndReceive(
                  at ate.sendAndReceive(
                  at ate.doSendAndReceive(
                  at ate.sendSourceAndReceiveToResult(WebServiceTemplat
                  at ate.sendSourceAndReceiveToResult(WebServiceTemplat
                  at eOutboundGateway.doHandle(SimpleWebServiceOutbound
                  at iceOutboundGateway.handleRequestMessage(AbstractWe
                  at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A
                  at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:78)
                  at org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch( :110)
                  at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch( 7)
                  at org.springframework.integration.jms.SubscribableJm sChannel$DispatchingMessageListener.onMessage(Subs
                  ... 9 more
                  Caused by: java.lang.RuntimeException:
                  at org.apache.activemq.command.ActiveMQObjectMessage. storeContent(
                  at org.apache.activemq.command.ActiveMQObjectMessage. setObject(
                  at org.apache.activemq.ActiveMQSession.createObjectMe ssage(
                  at ssageConverter.createMessageForSerializable(Simple
                  at ssageConverter.toMessage(SimpleMessageConverter.ja va:73)
                  at org.springframework.jms.core.JmsTemplate$7.createM essage(
                  at org.springframework.jms.core.JmsTemplate.doSend(Jm
                  at org.springframework.jms.core.JmsTemplate$3.doInJms (
                  at org.springframework.jms.core.JmsTemplate.execute(J
                  at org.springframework.jms.core.JmsTemplate.send(JmsT
                  at org.springframework.jms.core.JmsTemplate.convertAn dSend(
                  at org.springframework.integration.jms.JmsSendingMess ageHandler.send(
                  at org.springframework.integration.jms.JmsSendingMess ageHandler.handleMessageInternal(JmsSendingMessage
                  at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:78)
                  ... 34 more
                  Caused by:
                  at org.apache.activemq.command.ActiveMQObjectMessage. storeContent(
                  ... 47 more


                  • #10

                    As you see in the stack-trace you try to send to JMS a non-serializable object - SaajSoapMessage.
                    Now it's not problem of Spring Integration.
                    You should transform that SaajSoapMessage into something serializable...

                    Hope that help

                    Artem Bilan