2 Replies Latest reply on Jan 30, 2013 12:05 PM by milanmilas

    JAXB marshaling multiple elements from Camel CXF to Active MQ and unmarshal

    milanmilas

      I have solution for receving element from CXF and marshaling it with JAXB to ActiveMQ as

      well as unmarshal it on the other side.

       

      -Producer

       

                  <jaxb partNamespace="ChatMessage" partClass="com.pocesb.ChatMessage" fragment="true" prettyPrint="false" contextPath="com.allocatesoftware.pocesb"/>

               

                  <jaxb partNamespace="ChatMessage" partClass="com.pocesb.ChatMessage" fragment="true" prettyPrint="false" contextPath="com.pocesb"/>

       

       

      I would need to know how to extract ChatMessage XML from JMS body and Person XML from

      JMS body and then UnMarshal it in Java.

       

      Is there already some mechanism in Fuse Camel already?

        • 1. Re: JAXB marshaling multiple elements from Camel CXF to Active MQ and unmarshal
          davsclaus

          If the ChatMessage POJO is the XML you want, then you can let Camel automatic convert it to/from XML using JAXB (camel-jaxb) with the implicit type converters.

           

          Though as you use CXF there is one caveat is that you need to convert POJO first. And then to XML afterwards, which you can convert to as a String.

           

          <from uri="cxf:bean:serviceEndpoint?dataFormat=POJO"/>
          <convertBodyTo type="com.pocesb.ChatMessage"></convertBodyTo>
          <convertBodyTo type="String"></convertBodyTo>
          <inOnly uri="activemq:topic:Producer"></inOnly>
          

           

          But when sending to a JMS queue you can tell Camel which JMS message type to use. And if you say Text, then Camel will automatic convert to a String, so the route can be

           

          <from uri="cxf:bean:serviceEndpoint?dataFormat=POJO"/>
          <convertBodyTo type="com.pocesb.ChatMessage"></convertBodyTo>
          <inOnly uri="activemq:topic:Producer?jmsMessageType=Text"></inOnly>
          

           

          And on the consumer side you can convert to the POJO. Assuming the POJO class has JAXB annotations.

          <from uri="activemqconsumercxf:queue:Consumer"/>
          <convertBodyTo type="com.pocesb.ChatMessage"></convertBodyTo>
          

           

          And the jmsMessageType option only applies to the producer, so we can remove that.

          • 2. Re: JAXB marshaling multiple elements from Camel CXF to Active MQ and unmarshal
            milanmilas

            That's ok if my method is accepting only ChatMessage

            -Send(ChatMessage message)

             

            but what if my method has two parameters

            -Send(ChatMessage messsage, Person person)

             

            I suppose that ConvertBody to won't work or it can work only for one parameter in the

            List of parameters.

             

            But the question is how to do everything from your sample code for two parameters?