Sunday, June 22, 2008

invoking BPEL from java using RMI

I would like to list down some of the issues I faced and their workarounds while trying to invoke a BPEL process from JAVA program using RMI

Some of you would be aware that sample RMI code is available in the samples provided by SOA Suite.I am explaining the steps you need to follow to make the program working.

Create a java project and add the 2 jars required for compilation namely orabpel.jar and xmlparserv2.jar

The code should first set the properties required for RMI invocation

Properties props = new java.util.Properties();

Map map = new HashMap();

map.put("java.naming.factory.initial","com.evermind.server.rmi.RMIInitialContextFactory");

map.put("java.naming.provider.url", "opmn:ormi://$hostname:$opmn_port:$oc4jinstance/orabpel");

map.put("java.naming.security.principal","$username");

map.put("java.naming.security.credentials","$password");

props.putAll(map);


Then use the Locator class to connect to domain with password and properties

Locator locator = new Locator("default","welcome1",props);

IDeliveryService deliveryService = (IDeliveryService)locator.lookupService(IDeliveryService.SERVICE_NAME );


DeliveryService is used for invocation of the process. Will explain the methods during the invocation.

Create the input xml message to be given to the BPEL process

String xml = "<ns1:BPELProcess2ProcessRequest xmlns:ns1=\"http://xmlns.oracle.com/BPELProcess2\">\n" +

" <ns1:input>geo</ns1:input>\n" +

" </ns1:BPELProcess2ProcessRequest>";

You can get the xml snippet by running the process once in you BPEL console and copy the request tags .Now create a NormalizedMessage object which will be passed with the invocation.

NormalizedMessage nm = new NormalizedMessage( );

nm.addPart("payload", xml );


As you would be knowing there are 2 types of invocations.

One-way invocation and two-way invocation


So for one-way invocation use Post method of the DeliveryService


String processid = "OneWayHello";

String operation = "initiate";

deliveryService.post(processid, operation, nm);


For two-way invocation use request method of the DeliveryService

String processid = "TwoWayHello";

String operation = "process";

NormalizedMessage res = deliveryService.request(processid, operation, nm);


To view the response message use XMLHelper

Map payload = res.getPayload();

Element partEl = (Element) payload.get("payload");

System.out.println( "HelloWorld is " + XMLHelper.toXML(partEl) );


To run the RMI program you need to have some more additional jars in your classpath

Oc4j.jar,oc4jclient.jar,,rmic.jar and commons-logging.api.

If the oc4jinstance is wrongly mentioned like you have specified home instead of oc4j_soa then you will be getting following exception

java.lang.Exception: Failed to create "ejb/collaxa/system/DeliveryBean" bean; exception reported is: "javax.naming.NameNotFoundException: ejb/collaxa/system/DeliveryBean not found

Your code should be up and running and be able to interact with BPEL process.

No comments: