In my previous post, I explained how to invoke simple Java code from Oracle Service Bus using Java Callout action. But in another scenario's we sometime needs to deal with XmlObject using Java Callout, so in this post I will show you how we can leverage OSB Java Callout functionality to handle XmlObjects.
Follow below steps to invoke Java code which in turn return XmlObject.
1.) Create a Java Class and inside it, create one static method which returns XmlObject as return type. Make sure that the Java method is static one.
To compile above Java code you need "xbean-1.0.3" jar file, which you can download from here.
2.) Package above Java class to jar file and import it to OSB project.
3.) Create one target service, same as we created in previous post and import wsdl and xsd of that target service to OSB project.
4.) Create Business and Proxy service from above imported WSDL file.
5.) Now go to "Message Flow" of OSB proxy service and add one "Java Callout" Activity.
6.) Click on "Method" link and It will pop-up a window. Then Select the above imported jar file and choose static method.
7.) Now specify Input and Output parameters.
8.) To check the Result variable simple use one Log activity after Java Callout action and you will get below result.
There are some limitations when we deal with XmlObject in OSB Java Callout. We can't use the Result variable inside Message Flow, we can only pass this Result variable to another Java Callout.
In My next Post, I will explain how to pass above Result variable to another Java Callout action.
Follow below steps to invoke Java code which in turn return XmlObject.
1.) Create a Java Class and inside it, create one static method which returns XmlObject as return type. Make sure that the Java method is static one.
Java Class |
package CustomerInfo;
import org.apache.xmlbeans.XmlObject;
public class CustomerAddressInfo {
public
CustomerAddressInfo() {
super();
}
static
XmlObject newObject;
public
static XmlObject CustomerAddress(String CustId) {
String
xmlString =
String.format("<Customer
xmlns=\"http://www.xmlobject.test/xml\">\n" +
"<Name>" + "Vivek " +
"</Name>\n" +
"<City>" + "Mumbai " +
"</City>\n" +
"<Country>" + "India " + "</Country>\n"
+
"</Customer>\n");
try {
XmlObject object = XmlObject.Factory.parse(xmlString);
return object;
} catch
(Exception e) {
e.printStackTrace();
return newObject;
}
}
}
To compile above Java code you need "xbean-1.0.3" jar file, which you can download from here.
2.) Package above Java class to jar file and import it to OSB project.
3.) Create one target service, same as we created in previous post and import wsdl and xsd of that target service to OSB project.
Imported Resources |
4.) Create Business and Proxy service from above imported WSDL file.
Business and Proxy Services |
5.) Now go to "Message Flow" of OSB proxy service and add one "Java Callout" Activity.
6.) Click on "Method" link and It will pop-up a window. Then Select the above imported jar file and choose static method.
7.) Now specify Input and Output parameters.
Java Callout |
8.) To check the Result variable simple use one Log activity after Java Callout action and you will get below result.
< Customer xmlns ="http://www.xmlobject.test/xml">
< Name>Vivek</ Name>
< City>Mumbai</ City>
< Country>India</ Country>
</ Customer>
There are some limitations when we deal with XmlObject in OSB Java Callout. We can't use the Result variable inside Message Flow, we can only pass this Result variable to another Java Callout.
In My next Post, I will explain how to pass above Result variable to another Java Callout action.
0 comments :
Post a Comment