2 Replies Latest reply on Sep 28, 2009 5:16 AM by kconner

    Can't retrive message body

    mvackel

      Hello,

      I'm trying my initial steps with Jboss ESB doing the Getting Started guide examples, but I couldn't change the basic action to retrieve the message body.

      I've made a very basic action with this method:


      public Message process(Message msg) {
      System.out.println("Here 1..");
      String aNames[] = msg.getBody().getNames();

      System.out.println("Here 2..");
      for ( String str : aNames )
      System.out.println(str);

      System.out.println("Here 3..");
      System.out.println("=> " + msg.getBody().get("org.jboss.soa.esb.message.defaultEntry"));
      System.out.println("=> " + msg.getBody().get("org.jboss.soa.esb.message.body.content.TextBody"));

      System.out.println("Here 4..");
      System.out.println("Body: " + new String((byte[]) msg.getBody().get(BytesBody.BYTES_LOCATION)));

      Object body = msg.getBody().get();

      System.out.println("Here 5..");
      String sBody = new String((String) body);

      System.out.println("Here 6..");
      System.out.println("String Body: "+ sBody);

      return null;
      }

      The output is the following:

      13:40:11,725 INFO [STDOUT] Here 1..
      13:40:11,725 INFO [STDOUT] Here 2..
      13:40:11,725 INFO [STDOUT] org.jboss.soa.esb.message.defaultEntry
      13:40:11,725 INFO [STDOUT] org.jboss.soa.esb.message.defaultEntry-set-stack
      13:40:11,725 INFO [STDOUT] Here 3..
      13:40:11,725 INFO [STDOUT] => [B@b0a165
      13:40:11,725 INFO [STDOUT] => null
      13:40:11,725 INFO [STDOUT] Here 4..
      13:40:11,725 WARN [ActionProcessingPipeline] No fault address defined for fault message!
      ......

      The main question is: How can I retrive the message body?

      The process was interrupted at "Here 4.." but how can I get the error message, if any?

      Thanks in advance,

      Marcos Ackel

        • 1. Re: Can't retrive message body
          mvackel

          This problem happens if the provider is a FileSystem (FS Provider). If so, to retrive the message, use something like:

          System.out.println("Body: "+ new String( (byte[]) msg.getBody().get() ) );


          BUT, if the provider is a JMS provider, use something like this:

          System.out.println("Body: " + new String((String) msg.getBody().get()));

          in this last case, if you use the former version, it issues an exception. WHY are the message bodies differente?

          • 2. Re: Can't retrive message body
            kconner

            The default composer for the filesystem retrieves the contents and stores them in the message as a byte[]. This can easily be changed however, if you know that the contents are string rather than binary.

            The default composer is LocalFileMessageComposer but you can add a property within the fs-listener element to override it.

            <fs-listener ...>
             <property name="composer-class" value="XXX"/>
            </fs-listener>