Creating a new message using a JavaCompute node

Many message transformation scenarios require a new outgoing message to be built. The Create Message Class template in the JavaCompute node wizard generates template code for this.

In the template code, the default constructor of MbMessage is called to create a blank message, as shown in the following Java code:
MbMessage outMessage = new MbMessage();  
The headers can be copied from the incoming message using the supplied utility method, copyMessageHeaders(), as shown in this Java code:
copyMessageHeaders(inMessage, outMessage);
The new message body can now be created. First, add the top level parser element. For XML, this is:
MbElement outRoot = outMessage.getRootElement();
MbElement outBody = outRoot.createElementAsLastChild("XMLNSC");
The remainder of the message can then be built up using the createElement methods and the extended syntax of the broker XPath implementation.
Related tasks
Accessing elements in a message tree from a JavaCompute node
Related reference
JavaCompute node