Wednesday, June 06, 2007

Calling BPEL/ESB Webservice from standalone java client

In this article a sample is give how we call BPEL/ESB process from a java standalone program. The example is based on the HelloWorld process that accepts a single string as input.

The reason why I wrote this example, is that I did not find a straight forward simple java program to do this. Examples are supplied with BPEL (no 102) but not exactly what I want.

To run the example, open in JDeveloper a new project and add the following java class into your project. Make sure you add the following libraries to your project to make to java program runnable.
Here is the property file, to make the connection to your SOA Server.

context.properties
orabpel.platform=ias_10g
java.naming.factory.initial=com.evermind.server.rmi.RMIInitialContextFactory
java.naming.provider.url=opmn:ormi://edison.eurotransplant.nl:6003:oc4j_soa/orabpel
java.naming.security.principal=oc4jadmin
java.naming.security.credentials=scanner1


Here is the class file.

RMIClient.java

package nl.orasoa.bpel;

import com.collaxa.xml.XMLHelper;
import com.oracle.bpel.client.Locator;
import com.oracle.bpel.client.NormalizedMessage;
import com.oracle.bpel.client.delivery.IDeliveryService;

import java.util.Map;
import java.util.Properties;

import org.w3c.dom.Element;

public class RMIClient
{
public static

void main(String[] args)
throws Exception
{
try
{
String who = "Marc";
System.out.println("Who is " + who);

// properties in the classpath
Properties props = new java.util.Properties();

java.net.URL url =
ClassLoader.getSystemResource("context.properties");
props.load(url.openStream());
System.out.println(props);

String xml =
"<HelloWorldProcessRequest
xmlns=\"http://bpel.eurotransplant.nl/HelloWorld\">";
xml = xml + "<input>" + who + "</input>";
xml = xml + "</HelloWorldProcessRequest>";

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

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

NormalizedMessage nm = new NormalizedMessage();
nm.addPart("payload", xml);

NormalizedMessage res =
deliveryService.request("HelloWorld", "process", nm);

Map payload = res.getPayload();

System.out.println("BPELProcess HelloWorld executed!<br>");
Element partEl = (Element) payload.get("payload");
System.out.println("The Result was " + XMLHelper.toXML(partEl));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

11 comments:

srini said...

This java program calls only BPEL process using RMI. How you call ESB process using java program?

Anonymous said...

what about ldap authentication?
I cannot connect to API, but I tried it many ways...


java.lang.Exception: Failed to create "ejb/collaxa/system/FinderBean" bean; exception reported is: "javax.naming.NamingException: Lookup error: javax.naming.AuthenticationException: Not authorized; nested exception is:
javax.naming.AuthenticationException: Not authorized [Root exception is javax.naming.AuthenticationException: Not authorized]
at com.evermind.server.rmi.RMIClientContext.lookup(RMIClientContext.java:64)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.oracle.bpel.client.util.BeanRegistry.lookupFinderBean(BeanRegistry.java:337)
at com.oracle.bpel.client.Locator.getFinder(Locator.java:920)
at com.oracle.bpel.client.Locator.lookupProcess(Locator.java:255)

Marc Kelderman SOA Blog said...

Make sure you have the correct roles set to the user who wants to connect to the application server

Janos said...

It is strange, because the Console works fine, but this rmiclient not.
So I think oc4jadmin has the correct roles...

Janos said...

I have found the solution.
I had to give the grant in
soasuite\j2ee\oc4j_soa\config\system-jazn-data.xml the rmipermisson to the LDAP sec provider, and the corresponding group.

Anonymous said...

how do you interact with an esb process in Oracle SOA Suite using java?

Anonymous said...

The above code talks about synchronous Bpel Process .If you can help with the code for the getting response message for Asynchronous Bpel Process it wouldn solve my issues thanks.

Marc Kelderman SOA Blog said...

A-Sync processing is rather complex. Because it is fired and the result comes later. This means that you should have a process/thread running in your application that waits for incoming requests and act on that.
That's why I wrote the note only for sync.

Marc

Anonymous said...

Good example and it's exactly what I think I need. Stuck on the first step. Where did you get all those jars to add to your project? For example the orabpel jars.

Nimi said...
This comment has been removed by the author.
Anonymous said...

This is really good article. i tried exactly same. but i am getting following exception.

ec 22, 2008 2:14:50 PM oracle.j2ee.rmi.RMIMessages EXCEPTION_ORIGINATES_FROM_THE_REMOTE_SERVER

Post a Comment

Post a Comment