处理消息有效内容
可以在以前存在的调解处理程序中处理消息有效内容以及将消息有效内容从一种消息格式转换为另一种消息格式。
关于此任务
- 找到消息有效内容中的数据对象
- 将有效内容转换为另一种格式
- 例如,如果希望调解记录消息,请将有效内容转换为字节数组。
要处理消息中的特定字段,请使用服务数据对象 (SDO) V1 数据图。有关更多信息,请参阅SDO 数据图。有关受支持消息类型的格式的更多信息以及如何处理这些消息类型的示例,请参阅Web Service 消息的 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
}
}