1 Reply Latest reply on Aug 19, 2011 10:57 AM by Claus Ibsen

    Feature Request: Camel and messages with Payloads

    jamie archibald Apprentice

      I've run into a case where I have an incoming message that contains a payload. The payload in many cases could be different for the same message type and I want to unmarshal the payload of the message into an object (e.g. byte[] to SomeObject.class)

       

      I'd like to make use of camel's type converters making it easier to perform payload conversions. For example:

       

      class MyObject {

         public String msgType;

         public byte[] payload;

       

         public byte[] getPayload() {

            return payload;

         }

      }

       

       

      @Converter

      class PayloadConverter {

       

         @Converter

         public static PayloadFoo(byte[] bytes) {

            ...

         }

       

         @Converter

         public static PayloadBar(byte[] bytes) {

            ...

         }

      }

       

      // body is MyObject

      from("direct:input")

      // call the method getPayload on the object

      .choice()

         // invoke the method get payload for passing result to the camel type converter

         // the payload will get stored in the setPayload

        .when(header("PayloadType").isEqualTo("Foo")).convertBodyPropertyTo(PayloadFoo.class, "getPayload")

       

       

       

      If there is a way I can implement this and submit it to the community where would be a good place to start digging in the code?