メッセージ・ペイロードの使用
既存のメディエーション・ハンドラー内のメッセージ・ペイロードを処理し、メッセージ・ペイロードを別のメッセージ・フォーマットに変換することができます。
始める前に
このタスクについて
- メッセージ・ペイロード内のデータ・オブジェクトの配置
- 別のフォーマットへのペイロードの変換
- バイト配列へのペイロードの変換。例えば、メディエーションでメッセージをログに記録する場合など。
メッセージ内の特定のフィールドを使用するには、サービス・データ・オブジェクト (SDO)バージョン 1 データ・グラフを使用します。 詳しくは、SDO データ・グラフを参照してください。サポートされるメッセージ・タイプのフォーマットについての 詳細、およびそれらの使用例については、Web サービス・メッセージ用の SDO データ・グラフのマッピングを参照してください。
メッセージ・ペイロードを使用するには、以下のステップを実行します。
手順
メッセージ・フィールドのコード例
public boolean handle(MessageContext context) throws MessageContextException {
/* Get the SIMessage from the MessageContext object */
SIMessage message = ((SIMessageContext)context).getSIMessage();
/* Get the message format string */
String messageFormat = message.getFormat();
/* If you have a JMS TextMessage then extract the text contained in the message. */
if(messageFormat.equals("JMS:text"))
{
/* Retrieve the DataGraph object from the message */
DataGraph dataGraph = message.getDataGraph();
/* Navigate down the DataGraph to the DataObject named 'data'. */
DataObject dataObject = dataGraph.getRootObject().getDataObject("data");
/* Retrieve the text information contained in the DataObject. */
String textInfo = dataObject.get("value");
/* Use the text information retrieved */
System.out.println(textInfo);
}
/* Return true so the MessageContext is passed to any other mediation handlers
* in the handler list */
return true;
}
メッセージ・ペイロードをバイトのストリームとして使用する完全なメディエーション機能コードは、以下の例のようになります。 public boolean handle(MessageContext context)throws MessageContextException {
/* Get the SIMessage from the MessageContext object */
SIMessage message = ((SIMessageContext)context).getSIMessage();
if (!SIApiConstants.JMS_FORMAT_MAP.equals(msg.getFormat()))
{
try
{
dumpBytes(msg.getDataGraphAsBytes());
}
catch(Exception e)
{
System.out.println("The message contents could not be retrieved due to a "+e);
}
}
else
{
System.out.println("The bytes for a JMS:map format message cannot be shown.");
}
return true;
}
private static void dumpBytes(byte[] bytes)
{
// Subroutine to dump the bytes in a readable form to System.out
}
}