Announcement Announcement Module
Collapse
No announcement yet.
Spring Integration WebServices Gateway - Handling fault messages Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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.

    ideas?

  • #2
    Hello.

    Some tipical usage of ws:outbound-gateway without any fault-message-resolver.
    On the background WebServiceTemplate initializes some default DefaultStrategies.
    One of them is org.springframework.ws.soap.client.core.SoapFaultM essageResolver from WebServiceTemplate.properties
    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

    Comment


    • #3
      Hello,

      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 ?

      Thanks

      Comment


      • #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!

        Comment


        • #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?

          Thanks

          Comment


          • #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...

            Comment


            • #7
              thank you very much Cleric, very helpful

              Comment


              • #8
                Hello

                Also there is some interest solution.
                To mark FaultMessageResolver#resolveFault with @Publisher:
                Code:
                @Publisher(channel = "errorChannel")
                @Payload("#exception")
                 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.

                Comment


                • #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 cribableJmsChannel.java:116)
                  at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doInvokeListener(AbstractMessageLi stenerContainer.java:560)
                  at org.springframework.jms.listener.AbstractMessageLi stenerContainer.invokeListener(AbstractMessageList enerContainer.java:498)
                  at org.springframework.jms.listener.AbstractMessageLi stenerContainer.doExecuteListener(AbstractMessageL istenerContainer.java:467)
                  at org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.doReceiveAndExecute(Abstrac tPollingMessageListenerContainer.java:325)
                  at org.springframework.jms.listener.AbstractPollingMe ssageListenerContainer.receiveAndExecute(AbstractP ollingMessageListenerContainer.java:243)
                  at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.invokeL istener(DefaultMessageListenerContainer.java:1058)
                  at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.execute OngoingLoop(DefaultMessageListenerContainer.java:1 050)
                  at org.springframework.jms.listener.DefaultMessageLis tenerContainer$AsyncMessageListenerInvoker.run(Def aultMessageListenerContainer.java:947)
                  at java.lang.Thread.run(Thread.java:662)
                  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(UnicastingDispatcher.java :110)
                  at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch(UnicastingDispatcher.java:9 7)
                  at org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:61)
                  at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:157)
                  at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:128)
                  at org.springframework.integration.core.MessagingTemp late.doSend(MessagingTemplate.java:288)
                  at org.springframework.integration.core.MessagingTemp late.send(MessagingTemplate.java:149)
                  at org.springframework.integration.aop.MessagePublish ingInterceptor.publishMessage(MessagePublishingInt erceptor.java:147)
                  at org.springframework.integration.aop.MessagePublish ingInterceptor.invoke(MessagePublishingInterceptor .java:116)
                  at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
                  at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:202)
                  at $Proxy39.resolveFault(Unknown Source)
                  at org.springframework.ws.client.core.WebServiceTempl ate.handleFault(WebServiceTemplate.java:733)
                  at org.springframework.ws.client.core.WebServiceTempl ate.doSendAndReceive(WebServiceTemplate.java:559)
                  at org.springframework.ws.client.core.WebServiceTempl ate.sendAndReceive(WebServiceTemplate.java:496)
                  at org.springframework.ws.client.core.WebServiceTempl ate.doSendAndReceive(WebServiceTemplate.java:451)
                  at org.springframework.ws.client.core.WebServiceTempl ate.sendSourceAndReceiveToResult(WebServiceTemplat e.java:395)
                  at org.springframework.ws.client.core.WebServiceTempl ate.sendSourceAndReceiveToResult(WebServiceTemplat e.java:386)
                  at org.springframework.integration.ws.SimpleWebServic eOutboundGateway.doHandle(SimpleWebServiceOutbound Gateway.java:69)
                  at org.springframework.integration.ws.AbstractWebServ iceOutboundGateway.handleRequestMessage(AbstractWe bServiceOutboundGateway.java:104)
                  at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A bstractReplyProducingMessageHandler.java:98)
                  at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:78)
                  at org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch(UnicastingDispatcher.java :110)
                  at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch(UnicastingDispatcher.java:9 7)
                  at org.springframework.integration.jms.SubscribableJm sChannel$DispatchingMessageListener.onMessage(Subs cribableJmsChannel.java:109)
                  ... 9 more
                  Caused by: java.lang.RuntimeException: org.springframework.ws.soap.saaj.SaajSoapMessage
                  at org.apache.activemq.command.ActiveMQObjectMessage. storeContent(ActiveMQObjectMessage.java:104)
                  at org.apache.activemq.command.ActiveMQObjectMessage. setObject(ActiveMQObjectMessage.java:155)
                  at org.apache.activemq.ActiveMQSession.createObjectMe ssage(ActiveMQSession.java:330)
                  at org.springframework.jms.support.converter.SimpleMe ssageConverter.createMessageForSerializable(Simple MessageConverter.java:166)
                  at org.springframework.jms.support.converter.SimpleMe ssageConverter.toMessage(SimpleMessageConverter.ja va:73)
                  at org.springframework.jms.core.JmsTemplate$7.createM essage(JmsTemplate.java:643)
                  at org.springframework.jms.core.JmsTemplate.doSend(Jm sTemplate.java:565)
                  at org.springframework.jms.core.JmsTemplate$3.doInJms (JmsTemplate.java:536)
                  at org.springframework.jms.core.JmsTemplate.execute(J msTemplate.java:466)
                  at org.springframework.jms.core.JmsTemplate.send(JmsT emplate.java:534)
                  at org.springframework.jms.core.JmsTemplate.convertAn dSend(JmsTemplate.java:641)
                  at org.springframework.integration.jms.JmsSendingMess ageHandler.send(JmsSendingMessageHandler.java:99)
                  at org.springframework.integration.jms.JmsSendingMess ageHandler.handleMessageInternal(JmsSendingMessage Handler.java:90)
                  at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:78)
                  ... 34 more
                  Caused by: java.io.NotSerializableException: org.springframework.ws.soap.saaj.SaajSoapMessage
                  at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1164)
                  at java.io.ObjectOutputStream.defaultWriteFields(Obje ctOutputStream.java:1518)
                  at java.io.ObjectOutputStream.writeSerialData(ObjectO utputStream.java:1483)
                  at java.io.ObjectOutputStream.writeOrdinaryObject(Obj ectOutputStream.java:1400)
                  at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1158)
                  at java.io.ObjectOutputStream.writeObject(ObjectOutpu tStream.java:330)
                  at org.apache.activemq.command.ActiveMQObjectMessage. storeContent(ActiveMQObjectMessage.java:98)
                  ... 47 more

                  Comment


                  • #10
                    Hello

                    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

                    Comment

                    Working...
                    X