Wednesday, February 23, 2011

Invoking SOA Composite via EJB Service

Scenario - Invoke a composite via EJB passing a complex payload.

My payload is as follows -

I create a synchronous BPEL process that accepts inputOrder as input/output.

all the BPEL process does is Assign In 2 Out.

I then create an EJB Service (Generate Java interface from WSDL)

Wire together

Review the classes that have been created.

Make InputOrder and OrderType serializable

public class InputOrder implements Serializable{
public class OrderType implements Serializable{

Change the interface (BPELOrderProcess) to get rid of Holder dependency (I had
serialization issues with

public void process(@WebParam(targetNamespace="",
partName="payload", name="inputOrder", mode=Mode.INOUT) payload);

Deploy to SOA Server

Check the JNDI tree using the WLS console to see if our EJB is visible.

Create the EJB Client - I did this in the same project to save time -

Actual Code -

public class MyEJBClient {
public static void main(String [] args) throws Throwable {
try {
final Context context = getInitialContext();

Proxy proxy = (Proxy)context.lookup("ejb/BPELOrderProcessService");

// preparing the method to be called on the remote EJB
Method method =
BPELOrderProcess.class.getDeclaredMethod("process", new Class[] {InputOrder.class});
InputOrder id = new InputOrder();

OrderType ot = new OrderType();
ot.setComments("Good Customer");
ot.setProduct("Oracle SOA Suite 11g");
ot.setProductKey(new Long(12345));


InvocationHandler handler = Proxy.getInvocationHandler(proxy);
InputOrder response = (InputOrder)handler.invoke(proxy, method, new Object[] { id });
} catch (Exception ex) {

private static Context getInitialContext() throws NamingException {
Hashtable env = new Hashtable();
// WebLogic Server 10.x connection details
env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
env.put(Context.PROVIDER_URL, "t3://localhost:7001");
return new InitialContext( env );

Add the Weblgic Thin Client Library to the project

Run the client

Check the instance in em

No comments: