0

I have been working on a Java module to transform XMLs for the last few months. It is supposed to take a soap request and fill the soap:header element with additional elements from a metadata repository, for example. The module should be universally implementable into any middleware (my native system is SAP PI).

Now I am tasked with implementing this module as a jar into a JavaCompute Node in IBM Integration Bus. The problem is that to export the resulting XML I need to get the data into the outMessage of the JavaCompute Node. However, I did not find a way to convert an org.w3c.com.Document to MbElement or to insert the Document or its content into the MbElement.

Actually I did not see a way to put anything in there at all (not even an XML String) without using the IBM API as intended, so I would have to write code that reads my already finished Document and builds an MbElement from it.

This looks like the following:

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) { ...
2
  • What is you question? You are correct, you can only access the outgoing message tree with the IBM API. Commented Sep 28, 2016 at 20:25
  • The question was if I can somehow not do that myself and convert the DOM into something the outMessage can handle and how to then put it into the message. siarheib probably has the correct answer, I'm testing it ATM. Commented Sep 30, 2016 at 7:29

1 Answer 1

0

You can cast your org.w3c.com.Document to byte array (example). Then you can use the following code:

        MbMessage outMessage = new MbMessage();
        //copy message headers if required 
        MbElement oRoot = outMessage.getRootElement();  
        MbElement oBody = oRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);  
        oBody.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", yourXmlAsByteArray);
        MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly, inAssembly.getLocalEnvironment(), inAssembly.getExceptionList(), outMessage);
Sign up to request clarification or add additional context in comments.

3 Comments

Interesting, I will try that out and see how the next node deals with a BLOB object. Afaik that is a common content format here, though.
Correct answer. For future readers: the BLOB can then be used in following nodes like a "normal" xml, I have put it directly into a FileOutputNode and it came out like I generated it in Code.
Just a small addition. If you want to use the message in the following nodes as XML (in other words navigate through the message structure using Integration Bus capabilities) then you can use ResetContentDescriptor node to reparse BLOB as XMLNSC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.