Updating the variables using the BPELX extensions

This recipe explains how to utilize the BPELX extensions in order to manipulate content of the variables.

Getting ready

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.

How to do it…

The following steps show you how to update variables with various Oracle SOA Suite extension functions:

  1. For this recipe, we will use the CopyList extension. Open the VarCopy_1_1 BPEL process and add the assign activity.
  2. Add the Element-type global variable Var_CopyList which is used as the manipulation variable for the XML data.
  3. Add the assign activity into the BPEL process and add the following copy rules:
    • Initialize the global variable with a literal value.
    • Initialize the response message with the firstName, age, and responseTime information.
    • Copy the content of the 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.
    How to do it…
  4. Click on OK to close the dialog.
  5. Deploy the BPEL process to Oracle SOA Suite and execute it. In the Audit Trail of the BPEL process, we see that the global variable is initialized with a literal value as follows:
    <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>
  6. After the global variable is updated and the 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>

How it works…

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>

There's more…

We can also use the bpelx:append and bpelx:InsertAfter extensions for variable data manipulation.

Tip

In both the example BPEL processes, we add an additional assign activity for each BPELX extension for clarity. However, there is nothing to stop you from in using a different BPELX extension in a single assign activity.

bpelx:append

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:

  1. In the BPEL process edit the assign activity.
  2. Use the XML fragment to assign the content to the variable.
  3. For the copy rule type, select Append.
  4. Click on OK to close the dialog and confirm the assign configuration.

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>

bpelx:InsertAfter

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:

  1. In the BPEL process edit the assign activity.
  2. Use the XML fragment to assign the content to the variable.
  3. For the copy rule type, select InsertAfter. We insert a new <child> element after first exiting the <child> element in the result variable.
  4. Click on OK to close the dialog and confirm the assign configuration.

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>
..................Content has been hidden....................

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