The Java Embedding environment as well as the BPEL functions support the functionality that retrieves information about the running BPEL process instance, such as the process instance ID, process name, composite name, process instance title, and so on. The information can then be used for logging purposes, notification purposes, and error handling.
This recipe explains how to utilize the process instance data inside the Java Embedding activity.
To complete the recipe, we extend the response message schema (BPEL_and_Java_2_0.xsd
) in the BPEL_and_Java_2_0
process with additional fields, as follows:
<element name="processResponse"> <complexType> <sequence> <element name="day_of_date" type="string"/> <element name="exchangeMsg" type="string"/> <element name="prc_inst_id" type="long"/> <element name="prc_inst_title" type="string"/> <element name="prc_inst_creator" type="string"/> </sequence> </complexType> </element>
Open the BPEL_and_Java_2_0
process and add the Java Embedding activity (Java_Process_Data
).
We double click on the Java_Process_Data
activity and put the code from the following steps into the Java Embedding activity code snippet:
long prc_id= getInstanceId();
String prc_title= getTitle();
String prc_creator= getCreator();
Note that creator always returns an empty result for an unknown reason.
if (prc_id > 0) setVariableData("outputVariable", "payload", "/client:processResponse/client:prc_inst_id", prc_id); if (prc_title != null) setVariableData("outputVariable", "payload", "/client:processResponse/client:prc_inst_title", prc_title); if (prc_creator != null) setVariableData("outputVariable", "payload", "/client:processResponse/client:prc_inst_creator", prc_creator);
Let us now deploy and instantiate the BPEL process. In Audit Trail we can observe the output variable filed with data about running the BPEL process:
The information about the BPEL process can also be retrieved from the BPEL process without Java Embedding.
Insert the assign activity (BPEL_Process_Data
) into the BPEL_and_Java_2_0
process.
Double-click on the BPEL_Process_Data
and configure the following expressions for the retrieval of BPEL process information:
<assign name="BPEL_Process_Data"> <copy> <from>ora:getInstanceId()</from> <to>$outputVariable.payload/client:prc_inst_id</to> </copy> <copy> <from>ora:getCompositeName()</from> <to>$outputVariable.payload/client:prc_inst_title</to> </copy> <copy> <from>concat(ora:getCreator(), '')</from> <to>$outputVariable.payload/client:prc_inst_creator</to> </copy> </assign>
If we re-deploy the BPEL process and instantiate it again, we will see the BPEL process information filled into the output variable element directly, without the use of Java Embedding functionality:
We can see that the difference exists with <prc_inst_title>
, because there is no exact function in the BPEL environment.