Chapter 7. Accessing and Updating the Variables

In this chapter we will cover the following recipes:

  • Defining global variables in a BPEL process
  • Defining local variables in a BPEL process
  • Initializing a variable with an XML literal
  • Initializing a variable with an inline from-spec
  • Copying content between the variables
  • Accessing the fields within Element-based variables
  • Accessing the fields within Message Type-based variables
  • Assigning numerical values to the variables
  • Applying mathematical calculations on data in the variables
  • Assigning Boolean values to the variables
  • Assigning date or time to the variables
  • Updating the variables using the BPELX extensions
  • Dynamic indexing of the variables

Introduction

The main role of a BPEL process is to orchestrate web services. Web services are presented in the BPEL processes as partner links. The orchestration is performed through the exchange of messages from one partner link to another. The variables hold the messages received from the partner links or from the message that is to be sent to the partner links. Of course, a variable can hold both types of messages at once. It is also possible that a variable can hold information that does not correspond to either the receiving or sending message.

A variable is described by the type of information it holds. The types of variable can be as follows:

  • A WSDL message type
  • An XML schema element
  • An XML schema simple type

The variables belonging to the outermost scope (defined inside the <scope> element) are called global variables. They can be accessed from anywhere within a BPEL process. Alternatively, we define a local variable that is accessible only within the enclosing scope. We define the global variables when information needs to be accessible across a whole BPEL process. On the contrary, the local variables are defined when we need information only in some limited part of a BPEL process, usually inside the <scope> activity. We can actually draw a parallel with the Java programming language. In Java, the global variables are defined at the class level, while the local variables are defined inside the code block or methods.

The variables are tightly related to the scope definition, so the name of the variable must be unique within the scope definition. The variables are resolved against the nearest enclosing scope. If a global and local variable have the same name, the local variable takes precedence over the global when resolving the content of the variable.

Tip

Giving the same name to a global and local variable is bad practice, as the names can be ambiguous to the designer as well as to the developer of the BPEL process.

A variable is defined with the <variable> tag in a BPEL process. The type of the variable is defined through three exclusive attributes as follows:

  • messageType: This refers to the WSDL message type variable
  • element: This refers to the XML schema element variable
  • type: This refers to the XML simple type variable

The variables can be used in different BPEL process activities as shown in the following table:

Activity

Description

invoke

With the <invoke> activity, we can define two variables (with attributes), input and output, depending on the type of partner link (one-way or two-way) we call.

receive

The <receive> activity definition contains the variable attribute where we define the name of the variable to hold the content of the request.

reply

The <reply> activity contains the variable attribute where we define the name of the variable that holds information to be sent back to the client calling the BPEL process.

catch

In the <catch> activity, the variable is defined through the faultVariable attribute. When a fault occurs in the BPEL process, the specific fault is assigned to the fault variable.

Generally, the global and local variables are uninitialized at the beginning of a BPEL process. To initialize the variables, we have a number of . One is at the instantiation of the BPEL process. At that time, the variable for the <receive> activity is initialized with the content of the request message. Another possibility is to assign some content to a variable within the BPEL process. This can be achieved through the <assign> activity or via the XSLT transformation. It is desirable to completely initialize the variable. However, when we don't have the complete information, we can also partially initialize the variable with the amount of data we currently have.

..................Content has been hidden....................

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