Setting the BPEL process variables

This recipe explains how to send the data to the BPEL process variable.

Getting ready

In order to complete the recipe, we will update the BPEL_and_Java_1_1 process schema (BPEL_and_Java_1_1.xsd). The new element in the response message is clientResponseMsg:

<element name="processResponse">
  <complexType>
     <sequence>
      <element name="resultFmtBPEL" type="string"/>
      <element name="resultFmtJava" type="string"/>
      <element name="clientResponseMsg" type="string"/>
    </sequence>
  </complexType>
</element>

The newly defined element will be used to return the changed input message to the client.

How to do it…

Open the BPEL_and_Java_1_1 process and insert the Java Embedding activity (SetVar).

Double-click on the SetVar activity to insert a code snippet.

  1. First we read the input data:
    String input_txt_from_var= (String)getVariableData("Input_Txt_Var");
  2. In the next step we will reverse the input text:
    StringBuilder sb = new StringBuilder();
    for (int i = input_txt_from_var.length() - 1; i >= 0; i--)
     sb.append(input_txt_from_var.charAt(i)); 
  3. Finally, we assign the result to the clientResponseMsg element of the BPEL process output variable:
    setVariableData("outputVariable","payload","/client:processResponse/client:clientResponseMsg", sb.toString());

How it works…

The Java Embedding activity provides three types of setVariableData methods:

  • void setVariableData(String name, Object value)
  • void setVariableData(String name, String part, Object value)
  • void setVariableData(String name, String part, String query, Object value)

Depending on our needs, we choose the appropriate method. The methods have similar signatures to getVariableData, with the difference they don't return any values and contain an additional attribute, value, that is used to set the content of the variable.

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

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