2 Replies Latest reply on Jun 30, 2008 2:55 AM by dbaryla

    [PROBLEM] Parsing body of message received from camel udp consumer.

    dbaryla

      I've got a service unit using servicemix-camel component.

      What I'm trying to achieve is consume message from UDP, do some extra processing of received message and then store message in a file.

      Camel route looks like this:

       

      from("mina:udp://localhost:16302")

      .process(extraProcessing)

      .process(setFileName)

      .to("file://c:/test");

       

      where:

       

      Processor extraProcessing = new Processor() {

      public void process(Exchange e) throws Exception {

      // I'm trying to get data received from UDP.

      byte{} buffer = e.getIn().getBody(byte{}.class); // I know - it should be square parenthesis instead of {}

      String data = new String(buffer, "utf-8");

      }

      };

       

      Processor setFileName = new Processor() {

      private int messageCount = 0;

      public void process(Exchange e) throws Exception {

      Date now = Calendar.getInstance().getTime();

      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd.HH.mm.ss.SSS");

      String fileName = String.format("msg-%s-%d.txt", sdf.format(now), ++messageCount);

      e.getOut().setHeader(FileComponent.HEADER_FILE_NAME, fileName);

      e.getOut().setBody(e.getIn().getBody());

      }

      };

       

      The problem is that "e.getIn().getBody(byte{}.class)" extra processing returns null. I checked what is the actual class of object returned by getBody() and it is "org.apache.mina.common.PooledByteBufferAllocator$PooledByteBuffer" which is - of course - private and I don't have access to it.

      The only way (which is not impressive) I've found to access data was to call "e.getIn().getBody(String.class)". It's not impressive solution cause I have to parse a string like: "DirectBuffer{pos=0 lim=20 cap=32: 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33}".

       

      Am I missing something?

       

      P.S. I'm using fuse-esb-3.3.1.2 and JDK 1.6.

        • 1. Re: [PROBLEM] Parsing body of message received from camel udp consumer.
          gertv

          L.S.,

           

           

          The Object you get is a ByteBuffer instance, so even though the implementation is private, you can still access the data in there by assigning it to variable of type org.apache.mina.common.ByteBuffer.

           

          Mediation Router (Camel) should support converting this into a byte[], String, InputStream and ObjectInput, so I'm not sure what the problem with the getIn.getBody() as data\[\] is.  Could you enable DEBUG logging in the ESB for the org.apache.camel logger and check if the MinaConverter is actually loaded?  If it is, is there any additional log output when conversion should occur?

           

           

          Regards,

           

          Gert

          • 2. Re: [PROBLEM] Parsing body of message received from camel udp consumer.
            dbaryla

            After logging for camel is enabled on DEBUG I get lot of messages like:

             

            Could not find class 'org/apache/camel/component/mina/MinaComponent$1$1.class'

            Could not find class 'org/apache/camel/component/mina/MinaComponent$1$2.class'

            Could not find class 'org/apache/camel/component/mina/MinaComponent$1.class'

            Could not find class 'org/apache/camel/component/mina/MinaComponent.class'

            Could not find class 'org/apache/camel/component/mina/MinaConsumer$1.class'

            Could not find class 'org/apache/camel/component/mina/MinaConsumer$ReceiveHandler.class'

            Could not find class 'org/apache/camel/component/mina/MinaConsumer.class'

            Could not find class 'org/apache/camel/component/mina/MinaConverter.class'

            etc.

             

            After lot of messages like that there's another one:

             

            Could not examine class 'org/apache/activemq/camel/converter/ActiveMQMessageConverter$1.class' due to a java.lang.NoClassDefFoundError with message: org/apache/camel/Processor

            java.lang.NoClassDefFoundError: org/apache/camel/Processor

             

            Regards,

            Daniel