5 Replies Latest reply on Apr 6, 2009 12:37 PM by zurchman

    New message body

    zurchman

      How do you use the Message Body.replace(Body) method?

      The method looks simple enough by iteslf, but how do you go about instantiating a new Body object to pass as the argument?

      I'm trying to reformat a JMS Gateway message in the first action handler, and I'd like to start with an empty Body.

      Body instantiation is not obvious from the documentation, and I haven't been able to find any examples either in the samples directory (ESB 4.4.GA) or on the net.

        • 1. Re: New message body
          tfennelly

          Might be better to avoid that altogether and just create a new message instance, copy what you need, etc etc

          • 2. Re: New message body
            zurchman

            Hi Tom

            Right now I'd like to stick with trying to figure out the body-handling.

            Here's what I came up with based on the source code. The code below works, but leads to more questions about Body manipulation:

            System.out.println("Payload body type: " + Payload.bodyType(message));
            MessagePayloadProxy mpp = new MessagePayloadProxy(_config);
            o = mpp.getPayload(message);
            System.out.println("Payload object type: " + o.getClass().getName());
            System.out.println("Payload location: " + mpp.getSetPayloadLocation());
            String newPayload = args[0] + " " + args[1];
            mpp.setPayload(message, newPayload);

            I still haven't been able to get Body.replace() to work but that might be because I don't understand what I'm trying to do.

            I was able to instantiate a new message Body, but was not able to use it in Body.replace() (throws a message fault).

            ObjectBody newBody = (ObjectBody)
            MessageFactory.getInstance().createBodyType(message,
            Payload.OBJECT_BODY);

            I'm working with the first action handler processing a JMS message. The Payload.bodyType reported is "raw". I wasn't expecting that at all.

            What's a "raw" body type? Could that be one reason that it can't be replaced with a different Body type?

            Incidentally, I started in this direction because I was looking for a way to compensate for not being able to transmit attributes in a JMS MapMessage. I didn't want to have to burden the action with the overhead of XML parsing.

            I just looked at the JMS ObjectMessage processing in the Trailblazer, and the "CSV" parsing with ConfigTree looks like a simple, lightweight solution to my problem. (I've been focusing on the quickstarts).

            I saw a post that indicated that the Trailblazer was going to be removed from newer releases. It might be a good idea to include a quickstart that demonstrates that CSV processing.



            • 3. Re: New message body

              Might I suggest you use the add method instead of replace? (See http://www.jboss.org/jbossesb/docs/4.2GA/javadoc/esb/org/jboss/soa/esb/message/Body.html#add%28java.lang.Object%29) If you use Body.add("") you end up with an empty String as the message content.

              • 4. Re: New message body
                tfennelly

                To be quite honest.... I wasn't even aware of the option to "replace" the message Body and even if I was, I'm not sure I'd ever use it. That message api is way too complex for my liking and is almost guaranteed to be simplified drastically in ESB 5.

                Not sure why creating a new Message instance is not an option, but here's another option that may work... try replacing the message Body using the Body part from a newly created Message instance. If that does not work, then I strongly advice looking at other options to solving your use case (i.e. away from replacing the Body).

                • 5. Re: New message body
                  zurchman

                   

                  Not sure why creating a new Message instance is not an option...

                  I just thought that modifying the Body would be simpler. Guess not.

                  That message api is way too complex for my liking...

                  I'll drink to that!