Advanced Activities in BPEL

[ Share this article ]

Share this page via Facebook, Twitter or LinkedIn.

[ Send this article ]

Your message has been sent.

How would you like to send this article:
[ Save this article ]
Save this article to your account for easy access.

Send this article

Complete the form below to send this article, Advanced Activities in BPEL, to a friend (or to yourself). We will never share your details (or your friend's) with anyone. For more information, read our Privacy Policy.

Your details (so we can tell your friend who this is from) *
Sign up to receive the Packt Newsletter.
Your friend's details (so we can e-mail your friend) *
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
G
F
W
G
4
W
Enter the code without spaces and pay attention to upper/lower case.
by Matjaz B. Juric | November 2010 | BPEL Enterprise Articles IBM SOA

Business Process Execution Language (BPEL, aka WS-BPEL) has become the de facto standard for orchestrating services in SOA composite applications. BPEL reduces the gap between business requirements and applications and allows better alignment between business processes and underlying IT architecture.

In this article by Matjaz B. Juric, author of the book WS-BPEL 2.0 for SOA Composite Applications with IBM WebSphere 7, we will familiarize ourselves with some important activities offered by BPEL, particularly activity names, loops, delays, empty activities, and process termination. We will not discuss concrete use cases where these activities can be used, because they are well known to developers. Let us first look at loops.

WS-BPEL 2.0 for SOA Composite Applications with IBM WebSphere 7

WS-BPEL 2.0 for SOA Composite Applications with IBM WebSphere 7

Define, model, implement, and monitor real-world BPEL 2.0 business processes with SOA-powered BPM

  • Develop BPEL and SOA composite solutions with IBM's WebSphere SOA platform
  • Automate business processes with WS-BPEL 2.0 and develop SOA composite applications efficiently
  • Detailed explanation of advanced topics, such as security, transactions, human workflow, dynamic processes, fault handling, and more—enabling you to work smarter

 

Appendix

        Read more about this book      

(For more resources on IBM, see here.)

Loops

When defining business processes, we will sometimes want to perform a certain activity or a set of activities in a loop; for example, perform a calculation or invoke a partner web service operation several times, and so on.

BPEL supports three types of loops:

  • <while> loops
  • <repeatUntil> loops
  • <forEach> loops

The <while> and <repeatUntil> loops are very similar to other programming languages. The <forEach> loop, on the other hand, provides the ability to start the loop instances in parallel.

Loops are helpful when dealing with arrays. In BPEL, arrays can be simulated using XML complex types where one or more elements can occur more than once (using the maxOccurs attribute in the XML Schema definition). To iterate through multiple occurrences of the same element, we can use XPath expressions.

Let us now look at the <while> loop.

While

The <while> loop repeats the enclosed activities until the Boolean condition no longer holds true. The Boolean condition is expressed through the condition element, using the selected expression language (the default is XPath 1.0). The syntax of the <while> activity is shown in the following code excerpt:

<while>
<condition> boolean-expression </condition>
<!-- Perform an activity or a set of activities enclosed by
<sequence>, <flow>, or other structured activity -->
</while

Let us consider a scenario where we need to check flight availability for more than one person. Let us also assume that we need to invoke a web service operation for each person. In addition to the variables already present in the example, we would need two more NoOfPassengers to hold the number of passengers and Counter to use in the loop. The code excerpt with variable declarations is as follows:

<variables>
<variable name="NoOfPassengers" type="xs:int"/>
<variable name="Counter" type="xs:int"/>
</variables>

We also need to assign values to the variables. The NoOfPassengers can be obtained from the Employee Travel web service. In the following code, we initialize both variables with static values:

<assign>
<copy>
<from>number(5)</from>
<to variable="NoOfPassengers"/>
</copy>
<copy>
<from>number(0)</from>
<to variable="Counter"/>
</copy>
</assign>

The loop to perform the web service invocation is shown in the following code excerpt. Please remember that this excerpt is not complete:

<while>
<condition>$Counter &lt; $NoOfPassengers</condition>
<sequence>
<!-- Construct the FlightDetails variable with passenger data -->
...
<!-- Invoke the web service -->
<invoke partnerLink="AmericanAirlines"
portType="aln:FlightAvailabilityPT"
operation="FlightAvailability"
inputVariable="FlightDetails" />
<receive partnerLink="AmericanAirlines"
portType="trv:FlightCallbackPT"
operation="FlightTicketCallback"
variable="FlightResponseAA" />
...
<!-- Process the results ... -->
...
<!-- Increment the counter -->
<assign>
<copy>
<from>$Counter + 1</from>
<to variable="Counter"/>
</copy>
</assign>
</sequence>
</while>

Repeat Until

The <repeatUntil> loop repeats the enclosed activities until the Boolean condition becomes true. The Boolean condition is expressed through the condition element, the same way as in the <while> loop. The syntax of the <repeatUntil> activity is shown in the following code excerpt:

<repeatUntil>
<!-- Perform an activity or a set of activities enclosed by
<sequence>, <flow>, or other structured activity -->
<condition> boolean-expression </condition>
</repeatUntil>

A similar example of a loop as mentioned in the previous section, but using <repeatUntil>, is as follows:

<repeatUntil>
<sequence>
<!-- Construct the FlightDetails variable with passenger data -->
...
<!-- Invoke the web service -->
<invoke partnerLink="AmericanAirlines"
portType="aln:FlightAvailabilityPT"
operation="FlightAvailability"
inputVariable="FlightDetails" />
<receive partnerLink="AmericanAirlines"
portType="trv:FlightCallbackPT"
operation="FlightTicketCallback"
variable="FlightResponseAA" />
...
<!-- Process the results ... -->
...
<!-- Increment the counter -->
<assign>
<copy>
<from>$Counter + 1</from>
<to variable="Counter"/>
</copy>
</assign>
</sequence>
<condition>$Counter &gt;= $NoOfPassengers</condition>
</repeatUntil>

For Each

The <forEach> loop is a for type loop, with an important distinction. In BPEL the <forEach> loop can execute the loop branches in parallel or serially. The serial <forEach> is very similar to the for loops from various programming languages, such as Java. The parallel <forEach> executes the loop branches in parallel (similar to <flow>), which opens new possibilities in relatively simple parallel execution (for example, invocation of services).

The <forEach> loop requires us to specify the BPEL variable for the counter (counterName), the startCounterValue, and the finalCounterValue. The <forEach> loop will execute (finalCounterValue – startCounterValue + 1) times.

The <forEach> requires that we put all activities, which should be executed within the branch, into a <scope>. The <scope> allows us to perform group-related activities.

The syntax of <forEach> is shown in the following:

<forEach counterName="BPELVariableName" parallel="yes|no">
<startCounterValue>unsigned-integer-expression</startCounterValue>
<finalCounterValue>unsigned-integer-expression</finalCounterValue>
<scope>
<!-- The activities that are performed within forEach have to be
nested within a scope. -->
</scope>
</forEach>

Such a <forEach> loop will complete when all branches (<scope>) have completed.

A similar example of a loop as in the previous section is as follows:

<forEach counterName="Counter" parallel="no">
<startCounterValue>number(1)</startCounterValue>
<finalCounterValue>$NoOfPassengers</finalCounterValue>
<scope>
<sequence>
<!-- Construct the FlightDetails variable with passenger data
-->
...
<!-- Invoke the web service -->
<invoke partnerLink="AmericanAirlines"
portType="aln:FlightAvailabilityPT"
operation="FlightAvailability"
inputVariable="FlightDetails" />
<receive partnerLink="AmericanAirlines"
portType="trv:FlightCallbackPT"
operation="FlightTicketCallback"
variable="FlightResponseAA" />
...
<!-- Process the results ... -->
...
</sequence>
</scope>
</forEach>

Sometimes it would be useful if the <forEach> loop would not have to wait for all branches to complete. Rather, it would wait until at least some branches complete. In <forEach> we can specify that the loop will complete after at least N branches have completed. We do this using the <completionCondition> . We specify the number N of <branches>. The <forEach> will complete after at least N branches have completed. We can specify if we would like to count only successful branches or all branches. We do this using the successfulBranchesOnly attribute. If set to yes, only successful branches will count. If set to no (default), successful and failed branches will count. The syntax is as shown in the following:

<forEach counterName="BPELVariableName" parallel="yes|no">
<startCounterValue>unsigned-integer-expression</startCounterValue>
<finalCounterValue>unsigned-integer-expression</finalCounterValue>
<completionCondition> <!-- Optional -->
<branches successfulBranchesOnly="yes|no">
unsigned-integer-expression
</branches>
</completionCondition>
<scope>
<!-- The activities that are performed within forEach have to be
nested within a scope. -->
</scope>
</forEach>

WS-BPEL 2.0 for SOA Composite Applications with IBM WebSphere 7

WS-BPEL 2.0 for SOA Composite Applications with IBM WebSphere 7 Define, model, implement, and monitor real-world BPEL 2.0 business processes with SOA-powered BPM for IBM WebSphere 7 with this book and eBook
Published: October 2010
eBook Price: £26.99
Book Price: £43.99
See more
Select your format and quantity:
        Read more about this book      

(For more resources on IBM, see here.)

Delays

Sometimes a business process may need to specify a certain delay. In BPEL, we can specify delays either for a specified period of time or until a certain deadline is reached, by using the <wait> activity. Typically, we could specify delays to invoke an operation at a specific time, or wait for some time and then invoke an operation; for example, we could choose to wait before we pool the results of a previously initiated operation or wait between iterations of a loop.

The i><wait> activity can be:

  • for: We can specify duration, that is, we specify a period of time.

    <wait>
    <for> duration-expression </for>
    </wait>

  • until: We can specify a deadline; we specify a certain date and time.

    <wait>
    <until> deadline-expression </until>
    </wait>

Deadline and duration expressions

To specify deadline and duration expressions, BPEL uses lexical representations of corresponding XML Schema data types. For deadlines, these data types are either dateTime or date. For duration, we use the duration data type. The lexical representation of expressions should conform to the XPath 1.0 (or the selected query language) expressions. The evaluation of such expressions should result in values that are of corresponding XML Schema types: dateTime and date for deadline and duration for duration expressions.

All three data types use lexical representation inspired by the ISO 8601 standard, which can be obtained from the ISO web page http://www.iso.ch. ISO 8601 lexical format uses characters within the date and time information. Characters are appended to the numbers and have the following meaning:

  • C represents centuries.
  • Y represents years.
  • M represents months.
  • D represents days.
  • h represents hours.
  • m represents minutes.
  • s represents seconds. Seconds can be represented in the format ss.sss to increase precision.
  • Z is used to designate Coordinated Universal Time (UTC). It should immediately follow the time of day element.

For the dateTime expressions there is another designator:

T is used as time designator to indicate the start of the representation of the time.

Examples of deadline expressions are shown in the following code excerpts:

<wait>
<until>'2004-03-18T21:00:00+01:00'</until>
</wait>
<wait>
<until>'18:05:30Z'</until>
</wait>

For duration expressions, the following characters can also be used:

  • P is used as the time duration designator. Duration expressions always start with P.
  • Y follows the number of years.
  • M follows the number of months or minutes.
  • D follows the number of days.
  • H follows the number of hours.
  • S follows the number of seconds.

To specify a duration of 4 hours and 10 minutes, we use the following expression:

<wait>
<for>'PT4H10M'</for>
</wait>

To specify the duration of 1 month, 3 days, 4 hours, and 10 minutes, we need to use the following expression:

<wait>
<for>'P1M3DT4H10M'</for>
</wait>

The following expression specifies the duration of 1 year, 11 months, 14 days, 4 hours, 10 minutes, and 30 seconds:

<wait>
<for>'P1Y11M14DT4H10M30S'</for>
</wait>

Empty activities

When developing BPEL processes, you may come across instances where you need to specify an activity as per rules, but you do not really want to perform the activity. For example, in <if> activities, we need to specify an activity for each branch. However, if we do not want to perform any activity for a particular case, we can specify an <empty> activity. Not specifying any activity in this case would result in an error, because the BPEL process would not correspond to the BPEL schema. Empty activities are also useful in fault handling, when we need to suppress a fault.

The syntax for the <empty> element is rather straightforward:

<empty/>

Ending a process

BPEL provides the <exit> activity to immediately end a business process, before it has finished. We can use it to immediately terminate processes that are in execution. Often we use <exit> in conditional branches, where we need to exit a process when certain conditions are not met.

The <exit> activity ends the current business process instance and no fault and compensation handling is performed.

The syntax is very simple and is as follows:

<exit/>

Summary

This article familiarized us with the advanced concepts of BPEL, such as loops, process termination, delays, and deadline and duration expressions.


Further resources on this subject:


WS-BPEL 2.0 for SOA Composite Applications with IBM WebSphere 7

WS-BPEL 2.0 for SOA Composite Applications with IBM WebSphere 7 Define, model, implement, and monitor real-world BPEL 2.0 business processes with SOA-powered BPM for IBM WebSphere 7 with this book and eBook
Published: October 2010
eBook Price: £26.99
Book Price: £43.99
See more
Select your format and quantity:

About the Author :


Matjaz B. Juric

Matjaz B. Juric holds a Ph.D. in computer and information science. He is Full Professor at the university and head of the Cloud Computing and SOA Competence Centre. Matjaz is Java Champion and Oracle ACE Director. He has more than 15 years of work experience. He has authored/coauthored Business Process Driven SOA using BPMN and BPEL, Business Process Execution Language for Web Services (English and French editions), BPEL Cookbook: Best Practices for SOA-based integration and composite applications development (award for best SOA book in 2007 by SOA World Journal), SOA Approach to Integration, Professional J2EE EAI, Professional EJB, J2EE Design Patterns Applied, and .NET Serialization Handbook. He has published chapters in More Java Gems (Cambridge University Press) and in Technology Supporting Business Solutions (Nova Science Publishers). He has also published in journals and magazines, such as SOA World Journal, Web Services Journal, Java Developer's Journal, Java Report, Java World, eai Journal, theserverside.com, OTN, ACM journals, and presented at conferences such as OOPSLA, Java Development, XML Europe, OOW, SCI, and others. He is a reviewer, program committee member, and conference organizer. Matjaz has been involved in several large-scale projects. In cooperation with IBM Java Technology Centre, he worked on performance analysis and optimization of RMI-IIOP, integral part of the Java platform. Matjaz is also a member of the BPEL Advisory Board.

Books From Packt


WS-BPEL 2.0 for SOA Composite Applications   with Oracle SOA Suite 11g
WS-BPEL 2.0 for SOA Composite Applications with Oracle SOA Suite 11g

BPEL PM and OSB operational management with   Oracle   Enterprise Manager 10g Grid Control
BPEL PM and OSB operational management with Oracle Enterprise Manager 10g Grid Control

Oracle SOA Suite 11g R1 Developer's Guide
Oracle SOA Suite 11g R1 Developer's Guide

Service Oriented Architecture: An     Integration Blueprint
Service Oriented Architecture: An Integration Blueprint

IBM Lotus Notes 8.5 User Guide
IBM Lotus Notes 8.5 User Guide

IBM Lotus Notes and Domino 8.5.1
IBM Lotus Notes and Domino 8.5.1

SOA and WS-BPEL
SOA and WS-BPEL

IBM InfoSphere Replication Server and Data Event Publisher
IBM InfoSphere Replication Server and Data Event Publisher


No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
N
L
u
i
f
8
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software