Saturday, March 22, 2008

Tips on the Oracle BPEL Java API - Part 2 - Using the Locator class to get a list of processes

In part 1, we saw how to use the Server class to connect to the BPEL server and get a list of BPEL domains configured on that server. The Server class is useful for performing administrative tasks on the BPEL server. If we want to perform process oriented tasks, we need to use the Locator class and it's methods.

First, you'll need to import several BPEL API classes:

import com.oracle.bpel.client.IBPELProcessHandle;
import com.oracle.bpel.client.Locator;

And, as in our discussion in part 1, next task is to configure a java.util.Properties object with the connection information for your BPEL server, as well as a String object containing the security credentials (password):

Properties props = new java.util.Properties();
props.put("orabpel.platform", "ias_10g" );
props.put("java.naming.factory.initial",
"com.evermind.server.rmi.RMIInitialContextFactory" );
props.put("java.naming.provider.url",
"opmn:ormi://bpelserver:6003:home/orabpel" );
props.put("java.naming.security.principal", "oc4jadmin" );
props.put("java.naming.security.credentials", "password123" );

String securityCredentials = "password123";

When we use the Locator class to search for processes, we need to specify which BPEL domain to look in. Here we initialize a String to use the default domain:

String selectedDomain = "default";

Now we can get our instance of the Locator. We'll need to pass it the domain we're interested in, the server password, and our Properties object to make the connection:

Locator locator = new Locator(selectedDomain, securityCredentials, props);

Once we have our Locator reference, we can lookup processes, instances, and services. For our example, we'll be getting a list of processes, represented as an array of IBPELProcessHandle objects, loaded in our default domain:

IBPELProcessHandle procs[] = locator.listProcesses();

We can now iterate through our array of process handles and print out the name of each one:

for (int i=0; i<procs.length; i++ ) {
System.out.println( "Process Name="+procs[i].getProcessId().getProcessId() );
}

You should note that calling locator.listProcesses() does not guarantee that an array of fully loaded process handle objects will be returned to the caller. If you intend to use the methods in the IBPELProcessHandle interface, you should first ensure that the process handle was loaded by calling the method isLoaded() first.

No comments: