Initializing a variable with an XML literal

During the initialization phase, the variable receives its initial XML content. This content can be subject to various manipulations during the BPEL process flow. We are able to instantly assign the content of the variable if the source of the data already exists. This recipe explains how to initialize a variable with the XML content.

Getting ready

We create a new synchronous BPEL process (VarInit.bpel). We modify the request and response messages. The request message has the following schema:

<element name = "process">
  <complexType>
    <sequence>
      <element name = "name" type = "string"/>
      <element name = "birthYear" type = "int"/>
    </sequence>
  </complexType>
</element>

We need to provide the name and year of birth when starting the BPEL process instance. Similarly, we change the response message schema as follows:

<element name = "processResponse">
  <complexType>
    <sequence>
      <element name = "firstName" type = "string"/>
      <element name = "age" type = "string"/>
      <element name = "responseTime" type = "dateTime"/>
    </sequence>
  </complexType>
</element>

As a result of the BPEL process execution, we receive a name of the person, his/her age, and at what time the response from the BPEL process was sent.

How to do it…

The following steps show you how to initialize a variable with the XML literal content:

  1. We will initiate the variable by using the assign activity. Open the BPEL process and add the assign activity into it.
  2. Double-click on the added activity and select the icon for adding XML literals in the shape of a puzzle piece.
    How to do it…
  3. A dialog opens which enables us to enter the code for XML. We insert the code for initiating the variable; in our case, the output variable is as shown in thefollowing screenshot:
    How to do it…

    The XML literal must match the XML element definition in the XSD schema, so we must take care of that namespace as well as the tag names matching its definition.

  4. Deploy the BPEL process and test it using the Oracle Enterprise Manager Console. We can inspect the initiated value of the variable in the Audit Trail as shown in the following screenshot:
    How to do it…

How it works…

All data in BPEL is represented in the XML format and so are all the variables. The types of variables are defined through the XML schema. The content of data in the variables is also presented in the XML data. So, whenever we perform an operation over a variable, we also perform an operation over the XML structure. By assigning an XML literal to a variable, we assign the XML content to the XML presentation of the variable.

In the BPEL process, where we assigned the XML literal to the variable, the following code appears:

<assign name = "Literal">
  <copy>
    <from><processResponse xmlns = "http://xmlns.oracle.com/Variables/Global/VarInit">
      <firstName>Jurij</firstName>
      <age>37</age>
      <responseTime>2013-04-15</responseTime>
    </processResponse></from>
    <to variable = "outputVariable" part = "payload" query = "/client:processResponse"/>
  </copy>
</assign>

There's more…

Another possibility is to partially initialize the variable. At some point during the BPEL process execution, we decide to initialize the variable with information we have and amend it later.

We modify the BPEL process by adding an additional assign activity. Now we have two assign activities in the BPEL process for the purpose of clarity. Let us modify the XML literal code in the Literal assign activity to initialize only part of the variable. We only fill the firstName element. The rest of the message consists of empty nodes as follows:

<copy>
  <from>
    <processResponse xmlns = "http://xmlns.oracle.com/Variables/Global/VarInit">
      <firstName>Hello</firstName> 
      <age/>
      <responseTime/>
    </processResponse>
  </from>
  <to variable = "outputVariable" part = "payload" query = "/client:processResponse"/>
</copy>

The rest of the information can be filled in later with the assign activity.

See also

  • For additional techniques regarding variable data manipulation, refer to the Copying content between the variables recipe
..................Content has been hidden....................

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