多くのメッセージ変換シナリオでは、新規の出力メッセージを構築する必要があります。 「JavaCompute ノード」ウィザードの「作成メッセージ・クラス」テンプレートは、 このためのテンプレート・コードを生成します。
MbMessage outMessage = new MbMessage();
この Java コードに
示されているように、供給されたユーティリティー・メソッド copyMessageHeaders() を使用して、
ヘッダーを着信メッセージからコピーできます。copyMessageHeaders(inMessage, outMessage);
ここで、
新しいメッセージ本体を作成できます。 まず、最上位のパーサー・エレメントを追加します。 XML の場合、これは次のようになります。 MbElement outRoot = outMessage.getRootElement();
MbElement outBody = outRoot.createElementAsLastChild(MbXMLNSC.PARSER_NAME);
その後、
メッセージの残りの部分を createElement メソッドおよび
ブローカー XPath インプリメンテーションの拡張構文を使用して作成できます。 String myMsg = "The Message Data";
MbElement outRoot = outMessage.getRootElement();
// Create the Broker Blob Parser element
MbElement outParser = outRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
// Create the BLOB element in the Blob parser domain with the required text
MbElement outBody = outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", myMsg.getBytes());
MbElement outMsgRootEl = outMessage.getRootElement();
String parserName = MbBLOB.PARSER_NAME;
String messageType = "";
String messageSet = "";
String messageFormat = "";
int encoding = 0;
int ccsid = 0;
int options = 0;
outMsgRootEl.createElementAsLastChildFromBitstream(responseBodyXmlData,
parserName, messageType, messageSet, messageFormat, encoding, ccsid,
options);
JavaCompute ノードに JSON メッセージを追加するには、JSON メッセージの作成を参照してください。