This recipe explains how to utilize the BPELX extensions in order to manipulate content of the variables.
For this recipe, we will amend the BPEL processes from the Copying content between the variables recipe. Remember we designed two synchronous BPEL processes: one that supports BPEL 1.1 and one that supports BPEL 2.0. We will amend those two processes with a set of BPELX extensions.
For both the BPEL processes, we will extend the response message. We open the schema file (VarCopy_1_1.xsd
and VarCopy2_0.xsd
) and amend the content of the response schema element as follows:
<element name = "processResponse">
<complexType>
<sequence>
<element name = "firstName" type="string"/>
<element name = "age" type="int"/>
<element name = "responseTime" type="dateTime"/>
<element name = "child" type = "string" minOccurs = "1" maxOccurs = "unbounded"/>
</sequence>
</complexType>
</element>
The child
element presents a list of string values.
The following steps show you how to update variables with various Oracle SOA Suite extension functions:
CopyList
extension. Open the VarCopy_1_1
BPEL process and add the assign activity.Var_CopyList
which is used as the manipulation variable for the XML data.firstName
, age
, and responseTime
information.Var_CopyList
global variable to the child
list of the response message by using the copyList
operation. With this copy rule, change the operation to CopyList
.<Var_CopyList> <processResponse xmlns:client = "http://xmlns.oracle.com/Variables/Global/VarCopy_1_1" xmlns = "http://xmlns.oracle.com/Variables/Global/VarCopy_1_1"> <client:firstName>initName</client:firstName> <client:age>0</client:age> <client:responseTime>2013-04-16</client:responseTime> <client:child>Ajda</client:child> <client:child>Urban</client:child> </processResponse> </Var_CopyList>
CopyList
rule has been executed, the response message is updated as follows:<outputVariable> <part name = "payload" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"> <processResponse xmlns = "http://xmlns.oracle.com/Variables/Global/VarCopy_1_1"> <firstName>Jurij</firstName> <age>1975</age> <responseTime>2013-04-18</responseTime> <client:child xmlns:client = "http://xmlns.oracle.com/Variables/Global/VarCopy_1_1">Ajda</client:child> <client:child xmlns:client = "http://xmlns.oracle.com/Variables/Global/VarCopy_1_1">Urban</client:child> </processResponse> </part> </outputVariable>
The CopyList
operation is especially useful in cases where we operate on a list of the same Element type. An alternative to using CopyList
would be either to use the XSLT transformations or to create a set of copy rules where we would iterate through the list.
The source code in the BPEL 1.1 process for the CopyList
operation is as follows:
<bpelx:copyList> <bpelx:from variable = "Var_CopyList" query = "/client:processResponse/client:child"/> <bpelx:to variable = "outputVariable" part = "payload" query = "/client:processResponse/client:child"/> </bpelx:copyList>
The BPELX extension is seen as the namespace of the extension. The two additional elements that are used for the CopyList
operation are from
and to
.
In BPEL 2.0, the same operation looks different due to the variable access simplification as follows:
<extensionAssignOperation> <bpelx:copyList> <bpelx:from>$Var_CopyList/client:child</bpelx:from> <bpelx:to>$outputVariable.payload/client:child</bpelx:to> </bpelx:copyList> </extensionAssignOperation>
We can also use the bpelx:append
and bpelx:InsertAfter
extensions for variable data manipulation.
The append
extension is used for adding additional information into already existing XML content. With the copy operation, the content might get deleted or overwritten; however, appending the extension ensures that the XML content is appended as expected. It is possible to append the content of a variable, expression, or XML fragment as follows:
The code generated in VarCopy_1_1
is as follows:
<bpelx:append> <bpelx:from> <client:child xmlns:client = "http://xmlns.oracle.com/Variables/Global/VarCopy_1_1">Bob</client:child> </bpelx:from> <bpelx:to variable = "outputVariable" part = "payload" query = "/client:processResponse"/> </bpelx:append>
The code generated in VarCopy2_0
is as follows:
<extensionAssignOperation> <bpelx:append> <bpelx:from> <bpelx:literal> <client:child xmlns:client = "http://xmlns.oracle.com/Variables/Global/VarCopy2_0">Bob</client:child> </bpelx:literal> </bpelx:from> <bpelx:to>$outputVariable.payload</bpelx:to> </bpelx:append> </extensionAssignOperation>
The InsertAfter
extension is also used for adding additional information into already existing XML content. It is possible to insert the content of a variable, expression, or XML fragment. The XML content is inserted immediately after the element defined by the <to>
expression in the InsertAfter
extension:
<child>
element after first exiting the <child>
element in the result variable.The code generated in VarCopy_1_1
is as follows:
<bpelx:insertAfter> <bpelx:from> <client:child xmlns:client = "http://xmlns.oracle.com/Variables/Global/VarCopy_1_1">Hope</client:child> </bpelx:from> <bpelx:to variable = "outputVariable" part = "payload" query = "/client:processResponse/client:child[1]"/> </bpelx:insertAfter>
The code generated in VarCopy2_0
is as follows:
<extensionAssignOperation> <bpelx:insertAfter> <bpelx:from> <bpelx:literal> <client:child xmlns:client = "http://xmlns.oracle.com/Variables/Global/VarCopy2_0">Hope</client:child> </bpelx:literal> </bpelx:from> <bpelx:to>$outputVariable.payload/client:child[1]</bpelx:to> </bpelx:insertAfter> </extensionAssignOperation>