Initializing a variable with an inline from-spec

In the previous recipe, we explored how variables are initialized in a BPEL process. The recipe explained the initialization of variables using XML literals. This recipe explains the alternative way of initializing variables with an inline from-spec. The difference between the two mentioned recipes is that the initialization of a variable over an XML literal is performed from the assign activity, while initialization over an inline from-spec is performed at the variable definition.

Tip

The initialization of variables using an inline from-spec is only supported for BPEL 2.0 processes!

Getting ready

For this recipe, we will create an empty synchronous BPEL 2.0 process. We will reuse the request and response messages from the VarInit.bpel BPEL process we created in the previous recipe.

How to do it…

In the following steps, we will show you how to initialize a variable using an inline from-spec:

  1. We open the BPEL process and click on the variables icon in the process toolbar.
  2. We define a global variable with the name FromSpecVar as follows:
    <variable name = "FromSpecVar" element = "client:processResponse"/>
  3. In the Variables dialog, we select the FromSpecVar variable and click on the pencil icon to edit the variable configuration.
  4. We select the Initialize tab in the Edit Variable-FromSpecVar dialog. From the Type drop-down selection, we choose the Literal option as shown in the following screenshot:
    How to do it…
  5. Enter the initialization XML code into the Edit Variable dialog and click on the OK button.
    <client:processResponse xmlns:client = "http://xmlns.oracle.com/Variables/Global/FromSpecBPEL" xmlns = "http://docs.oasis-open.org/wsbpel/2.0/process/executable">
      <client:firstName>initName</client:firstName>
      <client:age>0</client:age>
      <client:responseTime>2013-04-16</client:responseTime>
    </client:processResponse>

How it works…

The inline from-spec variable initiation functionality provides the ability to set up the values of a variable prior to making some dynamic changes to the variable. The initialization through literal is also useful when testing some part of a BPEL process for an unusual or unexpected situation.

Note

The initialization of variables using an inline from-spec is covered in BPEL Standard 2.0, Chapter 8.1, available at http://docs.oasis-open.org/wsbpel/2.0/wsbpel-v2.0.html.

The initialization of the variable with an inline from-spec creates the following structure in the BPEL source code:

<variables>
  <variable name = "FromSpecVar" element = "client:processResponse">
    <from>
      <literal>
        <client:processResponse xmlns:client = "http://xmlns.oracle.com/Variables/Global/FromSpecBPEL" xmlns = "http://docs.oasis-open.org/wsbpel/2.0/process/executable">
          <client:firstName>initName</client:firstName>
          <client:age>0</client:age>
          <client:responseTime>2013-04-16</client:responseTime>
        </client:processResponse>
      </literal>
    </from>
  </variable>
</variables>

The variable initialization starts with the <from> tag and continues with <literal> indicating that the variable will be initialized with literal. The definition continues with the variable content itself. The <to> tag is omitted since we already know the name and type of variable we want to initialize.

To test how the initialization works, we deploy the BPEL process to the Oracle SOA Suite server and run an instance of the BPEL process. Inspection of the Audit Trail shows that the initialization of the variable is executed before the BPEL process reads the request messages as shown in the following screenshot:

How it works…

See also

  • Another alternative for the variable initialization presents the transfer of the content using the assign activity. We address this topic in 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