Friday, November 4, 2011

Java Callout in OSB

Sometime it's handier to implement your algorithm in Java than in OSB. This short tutorial shows you how to call a java class from OSB.

The Java code
Suppose you have implemented your algorithm in a Java class as follow:

package tud;

public class JavaHelper {
public static String occupy(String street){
//do occupy
return street+" is occupied.";
}
}

The method has to be static. Package this class to a jar (e.g. using Ant or Maven or "Eclipse export to jar" or "jar -cf jarname packagename". Deploy this jar in weblogic (go to /console then choose deployment>install).

The Java callout action in OSB
Create a Java callout action in message flow in your proxy:

* In the "method" field you specify the package.class.operation name of your Java jar.
* In the "action expression" field you specify the input parameter for your java class, e.g. I take the "Input" element from the body.
* In the "result value" field you specify the variable that will contain the result, e.g. the "occupy" in this case.

Test
using this input "Sesame street" you will get the occupy variable "Sesame street is occupied." due to the occupy java method.



In this article we use a primitive type (in this case string), you can also pass an XMLobject (e.g. using XMLbeans framework to create java class types from Schema) as described in Eric Elzinga's blog: http://www.xenta.nl/blog/2011/08/29/oracle-service-bus-java-callouts-with-xmlobjects/

Source: Steve's blog http://soa-java.blogspot.com

No comments: