过去几个月来,我一直在研究Java模块以转换XML。例如,它应该接受一个soap请求并使用元数据存储库中的其他元素填充soap:header元素。该模块应该普遍适用于任何中间件(我的本机系统是SAP PI)。IBM Integration Bus Java计算节点:输出w3c.dom.Document或字符串
现在我的任务是将此模块作为jar实现到IBM Integration Bus中的JavaCompute节点中。问题是导出生成的XML我需要将数据导入JavaCompute节点的outMessage。但是,我没有找到将org.w3c.com.Document转换为MbElement或将文档或其内容插入MbElement的方法。
实际上,我没有看到任何方法可以根据需要使用IBM API,所以我必须编写代码读取已经完成的Document并构建MbElement(甚至不是XML字符串)从中。
这看起来如下:
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。 –