2 Replies Latest reply on Aug 15, 2011 10:34 AM by jamie archibald

    ProducerTemplate + jaxb?

    jamie archibald Apprentice

      I've written a simple client that uses the producer template to send requests to an activemq queue. The client sends objects that were generated using jaxb. the problem is that the object has to be marshalled before sending to activemq, and also the response has to be unmarshalled. Is there anyway to tell the producer template to do this? Also on the database side is there a way to tell camel to unmarshal the response back to the queue?

       

      For example:

       

      // client

      class MyClient {

       

         // sends our jaxb object to the database. the database should reply with the same object as the response

         public MyObject send(MyObject obj) {

            template.requestBody("activemq:database", obj);

         }

      }

       

       

      // database

      class MyDatabase extends RouteBuilder {

       

        // route will listen for MyObject and reply

      public void configure() {

         from("activemq:database")

          .bean(MyDatabase.class, "reply");

      }

       

        public MyObject reply(MyObject obj) {

            return obj;

        }

      }

        • 1. Re: ProducerTemplate + jaxb?
          Claus Ibsen Master

          When you send to the activemq queue, you can tell it to use a javax.jms.TextMessage which forces Camel to automatic marshal JAXB -> String.

           

          Set the jmsMessageType=Text option

          http://camel.apache.org/jms

           

          template.requestBody("activemq:database?jmsMessageType=Text", obj);
          

           

          Make sure you have camel-jaxb on the classpath for this to work.

          • 2. Re: ProducerTemplate + jaxb?
            jamie archibald Apprentice

            I was able to get this to work using jmsMessageType=TEXT however I found out this does not work when the JAXB converter needs to be configured as follows:

             

            JaxbDataFormat jaxb = new JaxbDataFormat(MyObject.class.getPackage().getName());

            jaxb.setPartClass(MyObject.class.getName());

            jaxb.setPartNamespace(new QName("urn:someNamespace/MyObject.xsd","",""));

             

            Edited by: jamie3 on Aug 15, 2011 2:33 PM