【发布时间】:2016-09-29 17:48:33
【问题描述】:
在过去的几个月里,我一直在研究用于转换 XML 的 Java 模块。例如,它应该接受一个soap 请求并用元数据存储库中的其他元素填充soap:header 元素。该模块应该可以在任何中间件中普遍实现(我的本机系统是 SAP PI)。
现在我的任务是将此模块作为 jar 实现到 IBM Integration Bus 中的 JavaCompute 节点中。问题是要导出生成的 XML,我需要将数据放入 JavaCompute 节点的 outMessage 中。但是,我没有找到将 org.w3c.com.Document 转换为 MbElement 或将 Document 或其内容插入 MbElement 的方法。
实际上,如果不按预期使用 IBM API,我根本没有办法在其中放入任何东西(甚至不是 XML 字符串),所以我必须编写代码来读取我已经完成的 Document 并从它。
如下所示:
public void evaluate(MbMessageAssembly inAssembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal alt = getOutputTerminal("alternate");
MbMessage inMessage = inAssembly.getMessage();
// create new empty message
MbMessage outMessage = new MbMessage();
MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly,
outMessage);
try {
// optionally copy message headers
// copyMessageHeaders(inMessage, outMessage);
// ----------------------------------------------------------
// Add user code below
//Create an example output Document
String outputContent = "<element><subelement>Value</subelement></element>";
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(outputContent));
Document outDocument = db.parse(is);
//Get the Document or its content into the outRoot or outMessage somehow.
MbElement outRoot = outMessage.getRootElement();
//Start to iterate over the Document and use Methods like this to build up the MbElement?
MbElement outBody = outRoot.createElementAsLastChild("request");
// End of user code
} catch (MbException e) { ...
【问题讨论】:
-
你有什么问题?您是对的,您只能使用 IBM API 访问传出消息树。
-
问题是我是否不能以某种方式自己不这样做并将 DOM 转换为 outMessage 可以处理的东西,以及如何将其放入消息中。 siarheib 可能有正确答案,我在 ATM 上测试。
标签: java dom ibm-mq messagebroker