IBM Integration Bus Java计算节点:输出w3c.dom.Document或String

时间:2016-09-28 14:29:56

标签: java dom ibm-mq messagebroker

过去几个月我一直致力于Java模块转换XML。例如,它应该接受soap请求并使用元数据存储库中的其他元素填充soap:header元素。该模块应该可以普遍实现到任何中间件(我的本机系统是SAP PI)。

现在我的任务是将此模块作为jar实现到IBM Integration Bus中的JavaCompute节点。问题是要导出生成的XML,我需要将数据放入JavaCompute节点的outMessage中。但是,我没有找到将org.w3c.com.Document转换为MbElement或将Document或其内容插入MbElement的方法。

实际上,如果没有按预期使用IBM API,我根本没有看到任何放置任何东西(甚至不是XML String)的方法,所以我必须编写代码来读取我已经完成的Document并从中构建一个MbElement它

如下所示:

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) { ...

1 个答案:

答案 0 :(得分:0)

您可以将org.w3c.com.Document转换为字节数组(std::basic_string::c_str())。然后您可以使用以下代码:

Dns