Friday, February 01, 2008

Getting the name of the parent process

Sometimes you need to known which BPEL process called me. This could be use full to extract information from the calling process. In this example I created a piece a Java code that can be used in the Java Embedded step in the BPEL process.

It determines if it is called from an other BPEL process. If so, it derives the name of the process.
<bpelx:exec name="Java_Get_ParentName"
language="java" version="1.5">
String inputvar1 = "";
String parentId = "";
String parentName = "";

// Define variables to use; instance;[] instances; condition;

parentId = getParentId();
if (parentId == null || parentId.equals(""))
// Process is called via NON BPEL process:
// SoapUI, BPELConsol, external WebService
parentId = String.valueOf(getInstanceId());
parentName = "myself";
// Set the whereclause
addAuditTrailEntry("Set Query to determine parent process");
condition =
new "cikey = ?" );
condition.setLong(1, Long.parseLong(parentId));
// Perform the query using the Locator
"execute the query: cube_instance.cikey = " + parentId);
instances = this.getLocator().listInstances(condition);
"Number of instances found " + instances.length);
if (instances.length == 0)
addAuditTrailEntry("No instances found");
addAuditTrailEntry("Am I called from synchronous process???");
instance = instances[0];
parentName = instance.getProcess().getProcessId().toString();
("The process name of the parent is " + processId);
catch (Exception e) {}

setTitle("I am called from " + parentId + "(" + processId + ")" );
setVariableData("parentId_LocalVariable", parentId);
setVariableData("parentName_LocalVariable", processId);

The trick is as follows. Using the "this.getParentId()" function is used to query the BPEL proces dehydration store. It queries the table CUBE_INSTANCE for those records that matches with the column CIKEY.
If there are no records found, then it is called from a synchronous process, because these type of processes are not dehydrated.
Uf the "this.getParentId()" function returns empty, the BPEL process is not called from a BPEL process, but from an external source; SoapUI, BPEL console or other webservice or client.

Post a Comment