With the Oracle Service Bus (OSB) it is possible to extend the functionality by using java callouts.
Java callouts are static operations implemented in Java and packaged in a jar file. The jar file and all dependencies have to be included into the OSB project. Then it is possible to select the operation in the java callout node.
Basic types like int and String are supported for the parameters and the return value of the callout (the full list and a good tutorial is available at Simple Java Callout Example). But much more interesting, because in OSB everything is about XML processing, is to use XML snippets for parameter and return value.
First we create a proxy service with a java callout.
Then we implement the java class for the java callout.
The static method called by the OSB:
1publicstatic XmlObject test(String name, final XmlObject inputXmlData) { 2 Element inputElement = (Element) inputXmlData.getDomNode().getFirstChild(); 3 processInput(inputElement); 4final XmlObject result = createOutput(); 5return result; 6}
We need a method processing the input XmlObject and doing something with the containing elements:
1privatestaticvoid processInput(Element inputElement) { 2// Iterate over input 3final NodeList fieldsNodeList = inputElement.getChildNodes(); 4for (int i =0; i < fieldsNodeList.getLength(); i++) { 5final Node fieldsNode = fieldsNodeList.item(i); 6if (fieldsNode.getNodeType() == Node.ELEMENT_NODE) { 7 String nodeName = fieldsNode.getLocalName(); 8if (nodeName ==null) { 9 nodeName = fieldsNode.getNodeName(); // Depends on XML library10 } 11// Do something with it12 } 13 } 14}
For the return value we create a new XmlObject containing e single resultElement element. Inside this element the real return values are located.
1privatestatic XmlObject createOutput() { 2// Create XmlObject and wrapping element 3final XmlObject result = XmlObject.Factory.newInstance(); 4final Node resultDomNode = result.getDomNode(); 5final Document resultDocument = resultDomNode.getOwnerDocument(); 6final Element resultElement = resultDocument.createElement(„resultElement„); 7 resultDomNode.appendChild(resultElement); 8// Create result nodes 9for(int i=0; i<10; i++) { 10 String name =„test„+ i; 11 String value = Integer.toString(i); 12final Element element = resultDocument.createElement(name); 13 resultElement.appendChild(element); 14 element.appendChild(resultDocument.createTextNode(value));; 15 } 16return result; 17}
After compiling this class to a jar file and adding the jar file, xmlbeans and stax-api to the OSB project we can select our implemented method inside the java callout.
Finally we can deploy the whole thing to OSB and test it with the debug window.