Reading the process instance data

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.

Getting ready

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>

How to do it…

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:

  1. Read the BPEL process instance ID with the following:
    long prc_id= getInstanceId(); 
  2. Read the BPEL process title with the following:
    String prc_title= getTitle(); 
  3. Read the creator name with the following:
    String prc_creator= getCreator();

    Note that creator always returns an empty result for an unknown reason.

  4. Finally, we set the values to the output variable elements:
    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);

Tip

It is recommended to use an if statement guard, since the BPEL engine throws RuntimeException in case of null values.

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:

How to do it…

There's more…

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:

There's more…

We can see that the difference exists with <prc_inst_title>, because there is no exact function in the BPEL environment.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset