Once BPEL processes are deployed onto servers then they are available in two forms to be invoked
- As a webservice through WSDL/SOAP interface
- Java component
In this article we see basics behind java client to inoke BPEL processes.
Oracle provide java api, also called as 'Java Business Delegates' API to manipulate deployed BPEL processes.This functionality is provided as part of below jars.
- orabpel.jar
- orabpel-common.jar
- oracle_http_client
- orabpel-boot
Major steps involved in using this API are
- Add appropriate Oracle BPEL jar files to your java client application classpath.
- Get the handle to com.oracle.bpel.client.Locator object
- Build com.oracle.bpel.client.util.WhereCondition object to form a query to be executed against SOA data source
- Get tha handle to com.oracle.bpel.client.dispatch.IDeliveryService object from the reference of Locator object
- Build com.oracle.bpel.client.NormalizedMessage to create input message
- Call appropriate method (deliveryService.request(..)/deliveryService.post(...)) to perform BPEL invocation
Note that only 1st nd 2nd steps are mandatory and remaining steps are optional and required depending on tasks you perform on BPM engine.
If you take a task of deleting a bpel process from BPEL domain then following code provides necessary steps
try{
com.oracle.bpel.client.IInstanceHandle instance;
com.oracle.bpel.client.IInstanceHandle[] instances;
String instanceKey = null;
//processInstanceId is a BPEL variable holding process_instance_id to be deleted
instanceKey =(java.lang.String)getVariableData("processInstanceId ");
Locator locator = new Locator("default", "welcome1");
// Set the whereclause
WhereCondition cond1 = new WhereCondition( "cikey = ?" );
WhereCondition cond2 = new WhereCondition( "process_id = ?" );
//set query parameters
cond1.setLong(1,Long.parseLong(instanceKey));
cond2.setString(1,"BPELProcess2");
//I am converting cond1 to process_id= ? and cikey = ?
cond1.prepend("and").prepend(cond2);
// Perform the query using the Locator
instances =locator.listInstances(cond1);
instance = instances[0];
instance.delete(); // deletes instance trace from data source
//instance.abort(); // terminates instance trace from data source
//instance.cancel(); // canceles instance trace from data source
addAuditTrailEntry("BPELProcess2 instance deleted: "+instanceKey);
}catch(Exception e){
addAuditTrailEntry(e.getMessage());
}
If you take a task of recovering BPEL call back messages then following code provides necessary steps
package bpelrecovery;
import com.oracle.bpel.client.*;
import com.oracle.bpel.client.util.SQLDefs;
import com.oracle.bpel.client.util.WhereCondition;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import javax.naming.Context;
public class bpelrecovery {
public bpelrecovery() {
}
public static void main(String[] args) {
bpelrecovery recover = new bpelrecovery();
String rtc = "";
try{
rtc = recover.doRecover();
}
catch (Exception e){
e.printStackTrace();
}
}
private void recoverCallbackMessages(List messages)
throws Exception
{
String messageGuids[] = new String[messages.size()];
for(int i = 0; i < messages.size(); i++)
{
ICallbackMetaData callbackMetadata = (ICallbackMetaData)messages.get(i);
String messageGuid = callbackMetadata.getMessageGUID();
messageGuids[i] = messageGuid;
System.err.println((new StringBuilder()).
append("recovering callback message =").
append(messageGuids[i]).append(" process[").
append(callbackMetadata.getProcessId()).append("(").
append(callbackMetadata.getRevisionTag()).
append(")] domain [").
append(callbackMetadata.getDomainId()).
append("]").toString());
}
Locator locator = getLocator();
IBPELDomainHandle domainHandle = locator.lookupDomain();
domainHandle.recoverCallbackMessages(messageGuids);
System.out.println("Complete RECOVER");
}
public String doRecover() throws Exception{
WhereCondition where = null;
// Connect to domain "default"
try{
System.out.println("doRecover() instantiating locator...");
Locator locator =(Locator) getLocator();
System.out.println("doRecover() instantiated locator for domain " +
locator.lookupDomain().getDomainId());
// look for Invoke messages in need of recovery
StringBuffer buf1 = new StringBuffer();
where = new WhereCondition(buf1.append(SQLDefs.IM_state).append( " = "
).append(IDeliveryConstants.STATE_UNRESOLVED ).toString() );
System.out.println("doRecover() instantiating IInvokeMetaData... with where = "+ where.getClause());
IInvokeMetaData imd1[] = locator.listInvokeMessages(where);
System.out.println("doRecover() instantiated IInvokeMetaData");
// iterate thru the list
List l1 = new ArrayList();
for (Object o:imd1){
l1.add(o);
}
// See how many INVOKES are in the recovery zone
System.out.println("doRecover() instantiated IInvokeMetaData size = " +l1.size());
// look for Callback messages in need of recovery
StringBuffer buf = new StringBuffer();
where = new WhereCondition(buf.append(SQLDefs.DM_state).append( " = "
).append(IDeliveryConstants.TYPE_callback_soap ).append(" and ").
append(SQLDefs.DM_conv_id).append(" = ").append("\'MD5{54017bc3a7bfc4f7f50381287ff28bc7}\'")
.append(SQLDefs.DM_process_id).append(" = ").append("\'BPELProcess3\'")
.append(" and ").append("ROWNUM").append(" < ").append("30").toString() );
System.out.println("doRecover() instantiating ICallbackMetaData... with where = "+
where.getClause());
ICallbackMetaData imd[] = locator.listCallbackMessages(where);
System.out.println("doRecover() instantiated ICallbackMetaData");
//
// recover
//
List l = new ArrayList();
for (Object o:imd){
l.add(o);
}
recoverCallbackMessages(l);
}
catch (Exception e){
e.printStackTrace();
}
return "done";
}
public Locator getLocator(){
System.out.println("getLocator() start");
Locator locator = null;
// set JNDI properties for BPEL lookup
String jndiProviderUrl = "opmn:ormi://127.0.0.1:6003:oc4j_soa/orabpel";
String jndiFactory = "com.evermind.server.rmi.RMIInitialContextFactory";
String jndiUsername = "oc4jadmin";
String jndiPassword = "welcome1";
Hashtable jndi = new Hashtable();
jndi.put(Context.PROVIDER_URL, jndiProviderUrl);
jndi.put(Context.INITIAL_CONTEXT_FACTORY, jndiFactory);
jndi.put(Context.SECURITY_PRINCIPAL, jndiUsername);
jndi.put(Context.SECURITY_CREDENTIALS, jndiPassword);
jndi.put("dedicated.connection", "true");
try{
System.out.println("getLocator() instantiating locator...");
locator = new Locator("default", jndi);
System.out.println("getLocator() instantiated locator@" +locator);
}
catch (Exception e){
System.out.println("getLocator() error");
e.printStackTrace();
}
return locator;
}
}
Hi,
ReplyDeleteIt is good article. We are using some of the features already in 10g. Now we are working on migrating 10g to 11g code and found these classes are not getting recognized. Can you please help us with this, where we can see this classes in 11g ?
I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Same as your blog i found another one Oracle BPM .Actually I was looking for the same information on internet for Oracle BPM and came across your blog. I am impressed by the information that you have on this blog. Thanks once more for all the details.
ReplyDelete