Announcement Announcement Module
Collapse
No announcement yet.
Difficulty passing xml message from AQMP adapter to outbound WS Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Difficulty passing xml message from AQMP adapter to outbound WS

    Hi there,
    I am a newcomer to spring/Integration and AMQP.
    I have a problem with my application which i am hoping someone can help with.
    Within my application, I am passing an XML message (using curl/soapUI) to an MVC / REST controller, which builds a spring integration message (using messagebuilder). I then pass this message to an AQMP fan-out exchange. this all works as planned.

    I am then trying to pass this message to an SI outbound WS adapter which will call an external web service. I am actually trying to pass the message to multiple outbound WS adapters and then use an aggregator pattern to indicate to the MVC controller when all connected outbound WS adapters have returned/received a response. I am trying build a sample app that show that by processing a single message in parallel, will lead to a scalable and more efficient way of calling multiple external web services.

    When I connect directly to the outbound WS, my code works correctly and XML messages are passed correctly. My challenge is that when I attempt to connect an AQMP inbound adapter back to this outbound WS and use AMQP as the transport for , I am getting an 'octet/stream' as the content type in the message when it hits the outbound web service adapter. The other error I was seeing was that a root element was not present in my JAXB classes.
    It as if I have not converted the message correctly when my SI message is coming back through the inbound amqp adapter
    I have tried converting using http converters in my web.xml file and also using a marshaller service within my spring integration context but to no avail.

    Can anyone offer any advice on this as I am looking at this for a number of days and can't get to the bottom of it.



    Many thanks

    John

  • #2
    What is the payload type of the message you are creating with the MessageBuilder ?

    If the message sent to the outbound adapter has a type of byte[], it will get an application/octet-stream header; if it's a String it will get text/plain.

    Regardless, if you want to suppress the contentType header created by the inbound adapter from being propagated to the WS gw, configure the header-mapping to NOT map that header, or add a <header-filter/> to remove it (or add a <header-enricher/> to add the value you want).

    If you turn on debug logging, you can trace the messages (with headers) through your application(s).

    Comment


    • #3
      Gary,
      Thanks a mill for your prompt reply.
      I think that this is the nub of the issue from what I have read i.e that AMQP outbound adapter will default to byte contentType where it has not been explicitly set. Is there a way to configure this content type within the Message object itself rather than having to do this down stream?
      Cheers
      John

      P.S. I am new to this forum. is it appropriate to send a github link publicly.

      Comment


      • #4
        Yes, it's OK to post links.

        Take a look at the default converter (SimpleMessageConverter) to see how it handles content type. You can override the default behavior by providing your own MessageConverter implementation or using one of the others (Json or Marshalling).

        Comment


        • #5
          Gary.
          Thanks again for prompt reply.
          I'm afraid I'm not a developer so need the dummies guide to Spring !. Can you be more specific on the DEBUG option.
          Is an error trapping pattern that can be configured out to a console - is this what you mean? I have log for J enabled in the application. Would org.springframework.integration=DEBUG also do the trick?
          thanks

          Comment


          • #6
            Hi Gary,
            Ok, so I can see that the message contentType is hitting the exchange as a text/plain. it is is being passed to through my controller as an object (SalesTransactionBasket) but when it hits the WS Outbound adapter it pops me back the XML Root element error.
            Do i have a hybrid of things going on here? i.e. should I try set the contentType (a header enricher as you suggested) or should I convert the message in some way prior to it hitting the outbound adapter.
            I would have thought that the outbound web service adapter marshaller/unmarshaller (xjc generated classes) would have handled.

            Thanks again
            John



            DEBUG 2012-12-31 22:16:44,256 org.springframework.integration.channel.DirectChan nel - preSend on channel 'fromRabbit_loyalty', message: [Payload=ie.cit.cloud.pointofsale.SalesTransactionR equest@73aaea][Headers={timestamp=1356992204256, id=e2ca9a96-0ae7-43b8-b351-7cec02f475ad, amqp_receivedRoutingKey=epos.main.exchange.fanout, amqp_deliveryMode=PERSISTENT, amqp_contentType=text/plain, amqp_receivedExchange=epos.main.exchange.fanout, amqp_contentEncoding=UTF-8, amqp_redelivered=false, amqp_deliveryTag=1}]
            DEBUG 2012-12-31 22:16:44,256 org.springframework.integration.ws.MarshallingWebS erviceOutboundGateway - org.springframework.integration.ws.MarshallingWebS erviceOutboundGateway#0 received message: [Payload=ie.cit.cloud.pointofsale.SalesTransactionR equest@73aaea][Headers={timestamp=1356992204256, id=e2ca9a96-0ae7-43b8-b351-7cec02f475ad, amqp_receivedRoutingKey=epos.main.exchange.fanout, amqp_deliveryMode=PERSISTENT, amqp_contentType=text/plain, amqp_receivedExchange=epos.main.exchange.fanout, amqp_contentEncoding=UTF-8, amqp_redelivered=false, amqp_deliveryTag=1}]
            DEBUG 2012-12-31 22:16:44,303 org.springframework.ws.client.core.WebServiceTempl ate - Opening [org.springframework.ws.transport.http.HttpUrlConne ction@1375169] to [http://loyalty.cloudfoundry.com/loyalty/baskets]
            DEBUG 2012-12-31 22:16:44,396 org.springframework.jdbc.core.JdbcTemplate - SQL update affected 1 rows
            DEBUG 2012-12-31 22:16:44,396 org.springframework.jdbc.datasource.DataSourceUtil s - Returning JDBC Connection to DataSource
            DEBUG 2012-12-31 22:16:44,396 org.springframework.integration.jdbc.JdbcMessageHa ndler - Generated keys: [{UPDATED=1}]
            DEBUG 2012-12-31 22:16:44,396 org.springframework.integration.stream.CharacterSt reamWritingMessageHandler - org.springframework.integration.stream.CharacterSt reamWritingMessageHandler#1 received message: [Payload=ServletRequestHandledEvent: url=[/pointofsale/amqp/1]; client=[127.0.0.1]; method=[POST]; servlet=[appServlet]; session=[null]; user=[null]; time=[125ms]; status=[OK]][Headers={timestamp=1356992204240, id=563eb6dd-ccc6-4a6c-99c7-ce8065fcbf32}]
            ServletRequestHandledEvent: url=[/pointofsale/amqp/1]; client=[127.0.0.1]; method=[POST]; servlet=[appServlet]; session=[null]; user=[null]; time=[125ms]; status=[OK]
            DEBUG 2012-12-31 22:16:44,396 org.springframework.integration.channel.PublishSub scribeChannel - postSend (sent=true) on channel 'eventChannel', message: [Payload=ServletRequestHandledEvent: url=[/pointofsale/amqp/1]; client=[127.0.0.1]; method=[POST]; servlet=[appServlet]; session=[null]; user=[null]; time=[125ms]; status=[OK]][Headers={timestamp=1356992204240, id=563eb6dd-ccc6-4a6c-99c7-ce8065fcbf32}]
            DEBUG 2012-12-31 22:16:44,428 org.springframework.integration.channel.DirectChan nel - preSend on channel 'eventErrorChannel', message: [Payload=org.springframework.integration.MessageHan dlingException: error occurred in message handler [org.springframework.integration.ws.MarshallingWebS erviceOutboundGateway#0]][Headers={timestamp=1356992204428, id=86ca3c9a-8137-4525-bfc1-779aac3c10d7}]
            DEBUG 2012-12-31 22:16:44,428 org.springframework.integration.stream.CharacterSt reamWritingMessageHandler - org.springframework.integration.stream.CharacterSt reamWritingMessageHandler#4 received message: [Payload=org.springframework.integration.MessageHan dlingException: error occurred in message handler [org.springframework.integration.ws.MarshallingWebS erviceOutboundGateway#0]][Headers={timestamp=1356992204428, id=86ca3c9a-8137-4525-bfc1-779aac3c10d7}]
            org.springframework.integration.MessageHandlingExc eption: error occurred in message handler [org.springframework.integration.ws.MarshallingWebS erviceOutboundGateway#0]
            at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:79)
            at org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch(UnicastingDispatcher.java :115)
            at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch(UnicastingDispatcher.java:1 02)
            at org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:77)
            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.endpoint.MessagePr oducerSupport.sendMessage(MessageProducerSupport.j ava:92)
            at org.springframework.integration.amqp.inbound.AmqpI nboundChannelAdapter.access$200(AmqpInboundChannel Adapter.java:39)
            at org.springframework.integration.amqp.inbound.AmqpI nboundChannelAdapter$1.onMessage(AmqpInboundChanne lAdapter.java:73)
            at org.springframework.amqp.rabbit.listener.AbstractM essageListenerContainer.doInvokeListener(AbstractM essageListenerContainer.java:527)
            at org.springframework.amqp.rabbit.listener.AbstractM essageListenerContainer.invokeListener(AbstractMes sageListenerContainer.java:472)
            at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer.access$001(SimpleMessageList enerContainer.java:56)
            at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer$1.invokeListener(SimpleMessa geListenerContainer.java:103)
            at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer.invokeListener(SimpleMessage ListenerContainer.java:560)
            at org.springframework.amqp.rabbit.listener.AbstractM essageListenerContainer.executeListener(AbstractMe ssageListenerContainer.java:452)
            at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer.doReceiveAndExecute(SimpleMe ssageListenerContainer.java:436)
            at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer.receiveAndExecute(SimpleMess ageListenerContainer.java:420)
            at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer.access$200(SimpleMessageList enerContainer.java:56)
            at org.springframework.amqp.rabbit.listener.SimpleMes sageListenerContainer$AsyncMessageProcessingConsum er.run(SimpleMessageListenerContainer.java:505)
            at java.lang.Thread.run(Thread.java:722)
            Caused by: org.springframework.oxm.MarshallingFailureExceptio n: JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
            - with linked exception:
            [com.sun.istack.internal.SAXException2: unable to marshal type "java.lang.String" as an element because it is missing an @XmlRootElement annotation]
            at org.springframework.oxm.jaxb.Jaxb2Marshaller.conve rtJaxbException(Jaxb2Marshaller.java:758)
            at org.springframework.oxm.jaxb.Jaxb2Marshaller.marsh al(Jaxb2Marshaller.java:597)
            at org.springframework.ws.support.MarshallingUtils.ma rshal(MarshallingUtils.java:81)
            at org.springframework.integration.ws.MarshallingWebS erviceOutboundGateway$MarshallingRequestMessageCal lback.doWithMessageInternal(MarshallingWebServiceO utboundGateway.java:114)
            at org.springframework.integration.ws.AbstractWebServ iceOutboundGateway$RequestMessageCallback.doWithMe ssage(AbstractWebServiceOutboundGateway.java:215)
            at org.springframework.ws.client.core.WebServiceTempl ate.doSendAndReceive(WebServiceTemplate.java:571)
            at org.springframework.ws.client.core.WebServiceTempl ate.sendAndReceive(WebServiceTemplate.java:537)
            at org.springframework.integration.ws.MarshallingWebS erviceOutboundGateway.doHandle(MarshallingWebServi ceOutboundGateway.java:101)
            at org.springframework.integration.ws.AbstractWebServ iceOutboundGateway.handleRequestMessage(AbstractWe bServiceOutboundGateway.java:176)
            at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A bstractReplyProducingMessageHandler.java:97)
            at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:73)
            ... 21 more
            Caused by: javax.xml.bind.MarshalException
            - with linked exception:
            [com.sun.istack.internal.SAXException2: unable to marshal type "java.lang.String" as an element because it is missing an @XmlRootElement annotation]
            at com.sun.xml.internal.bind.v2.runtime.MarshallerImp l.write(MarshallerImpl.java:311)
            at com.sun.xml.internal.bind.v2.runtime.MarshallerImp l.marshal(MarshallerImpl.java:236)
            at org.springframework.oxm.jaxb.Jaxb2Marshaller.marsh al(Jaxb2Marshaller.java:593)
            ... 30 more
            Caused by: com.sun.istack.internal.SAXException2: unable to marshal type "java.lang.String" as an element because it is missing an @XmlRootElement annotation
            at com.sun.xml.internal.bind.v2.runtime.XMLSerializer .reportError(XMLSerializer.java:237)
            at com.sun.xml.internal.bind.v2.runtime.LeafBeanInfoI mpl.serializeRoot(LeafBeanInfoImpl.java:126)
            at com.sun.xml.internal.bind.v2.runtime.XMLSerializer .childAsRoot(XMLSerializer.java:483)
            at com.sun.xml.internal.bind.v2.runtime.MarshallerImp l.write(MarshallerImpl.java:308)
            ... 32 more

            DEBUG 2012-12-31 22:16:44,428 org.springframework.integration.channel.DirectChan nel - postSend (sent=true) on channel 'eventErrorChannel', message: [Payload=org.springframework.integration.MessageHan dlingException: error occurred in message handler [org.springframework.integration.ws.MarshallingWebS erviceOutboundGateway#0]][Headers={timestamp=1356992204428, id=86ca3c9a-8137-4525-bfc1-779aac3c10d7}]
            D

            Comment


            • #7
              Gary,
              I have modified the way in which I am accepting the XML data into my MVC controller and now have this working by taking your advice on the Marshalling converter.
              Thanks very much for your input.

              John

              Comment

              Working...
              X