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.
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.
In the following steps, we will show you how to initialize a variable using an inline from-spec:
FromSpecVar
as follows:<variable name = "FromSpecVar" element = "client:processResponse"/>
FromSpecVar
variable and click on the pencil icon to edit the variable configuration.<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>
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.
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: