In this chapter we will cover the following recipes:
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:
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.
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 variableelement
: This refers to the XML schema element variabletype
: This refers to the XML simple type variableThe variables can be used in different BPEL process activities as shown in the following table:
Activity |
Description |
---|---|
invoke |
With the |
receive |
The |
reply |
The |
catch |
In the |
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.