Sunday, March 31, 2013

In Previous post, I explained how to deal with XmlObject in Java Callout. We can't use the response XmlObject in OSB message flow but we can easily pass that XmlObject to another Java Callout.

In This post, I will explain how we can pass XmlObject response from one Java Callout to another Java Callout action.

1.)  Create one Java class and create one static method that takes XmlObject as input parameter and return String as return type.

Java Class
Java Class

package CustomerAccountInfo;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.apache.xmlbeans.XmlObject;

public class CustomerAccount {
    public CustomerAccount() {
    public static String getAccountInfo(XmlObject customer) {
        String CustomerAccountId = "";
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        try {
            InputStream inputStream = customer.newInputStream();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(inputStream);
            NodeList nList = doc.getElementsByTagName("Customer");
            for (int temp = 0; temp < nList.getLength(); temp++) {
                Node nNode = nList.item(temp);
                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element)nNode;
                    String Name =eElement.getElementsByTagName("Name").item(0).getTextContent();
                    String City =eElement.getElementsByTagName("City").item(0).getTextContent();
                    String Country =eElement.getElementsByTagName("Country").item(0).getTextContent();
                    CustomerAccountId =CustomerAccountId + Name + City + Country;
            return CustomerAccountId;
        } catch (Exception e) {
            return "error";

2.) Package above Java class to jar file and import it to OSB project.

Imported Resources
Imported Resources

3.) Add another Java Callout action in TargetServicePS message flow and assign result variable of above Java Callout to input variable of this Java Callout.

Java Callout
Java Callout

4.) Now assign response from second Java Callout action to input variable of target Service.

Target Service
Target Service


Post a Comment