When using the Java Embedding activity, we need to read data from the BPEL process in order to perform the designed operation. This recipe explains how to read data from the BPEL variables.
Open the BPEL_and_Java_1_1
process and add the Java Embedding activity (ReadVar
) into the BPEL process.
getVariableData
function in the ReadVar
code snippet:oracle.xml.parser.v2.XMLElement input_var= (oracle.xml.parser.v2.XMLElement)getVariableData("inputVariable","payload","/client:process/client:input");
getVariableData
returns the Object
type, and in our case it is XMLElement
to which we also cast the result. The XMLElement
class contains convenient methods to access the content:String input_var_txt= input_var.getTextContent();
The Java Embedding activity provides three types of getVariableData
methods:
Object getVariableData(String name) throws BPELFault
Object getVariableData(String name, String partOrQuery) throws BPELFault
Object getVariableData(String name, String part, String query)
Depending on our needs, we choose the proper method. All three methods return the content of the variable depending on the parameters we provide.
A more convenient way of reading the BPEL process variables is through the use of intermediate variables inside the BPEL process.
In the BPEL process we define a variable. For our example, the BPEL definition of the variable would be as follows:
<variable name="Input_Txt_Var" type="xsd:string"/>
We also add the assign activity (ReadInput
), which copies the content of the input BPEL variable to the Input_Txt_Var
variable:
<assign name="ReadInput"> <copy> <from variable="inputVariable" part="payload" query="/client:process/client:input"/> <to variable="Input_Txt_Var"/> </copy> </assign>
Let us now amend the ReadVar
activity in order to read data from the BPEL variable:
String input_txt_from_var= (String)getVariableData("Input_Txt_Var");
The code is now much simpler and easier to understand.
We have just completed the recipe for reading data from the BPEL process variable. As soon as we perform the operation on the data, we wish to send the result back to the BPEL process variable. To learn how to send data to the BPEL process variable refer to our next recipe, Setting the BPEL process variables.