You are on page 1of 19

BPEL Hands on Tutorial

Ionut Subasu
ETH Zurich WS&SOA FS2010 1

Outline
Short Intro Basic BPEL process Using Operators Invoking Services Adding control structures Executing activities in parallel Signaling faults Undoing steps
ETH Zurich WS&SOA FS2010 2

BPEL Building blocks


A BPEL Process has a series of steps Declares a set of variables Defines a set of partner links A BPEL process can be
Synchronous or asynchronous
Blocking or non blocking

Each step is an activity

For clients the BPEL process looks like any other WebService

It is actually a WebService that composes other Web Services


ETH Zurich WS&SOA FS2010 3

Partner Links
Used to
invoke operations on other web services receive invocations from clients or other web services

Each BPEL process has at least one Partner Link


<partnerLinks> <partnerLink name="PartnerLink1 xmlns:tns="http://j2ee.netbeans.org/wsdl/MyBpelModule/basicWSDL" partnerLinkType="tns:basicWSDL" myRole="basicWSDLPortTypeRole? partnerRole="basicWSDLPortTypeRole? /> </partnerLinks>

ETH Zurich WS&SOA FS2010

BPEL - Activities
BPEL has a set of primitive steps
Basic constructs and are used for basic tasks
<receive> - wait for a client to make a request <reply> - generate a response <assign> - manipulate data variables <invoke> - invoke other web service <throw> - raise a fault or exception <wait> - a short period of time <terminate> - end the entire process
ETH Zurich WS&SOA FS2010 5

Basic BPEL process - Short Demo


This BPEL process receives a message and sends it back to the sender.

ETH Zurich WS&SOA FS2010

Assign Activity
Allows to
copy data from one variable to another insert new data using expressions

Used to perform simple computations


For an assignment to be valid, data referred by the from and to MUST be of the compatible type
<assign name="Assign1"> <copy> <from>concat('Hello ', $ConcatWSDLOperationIn.part1/arg0)</from> <to>$ConcatWSDLOperationOut.part1/return</to> </copy> </assign> ETH Zurich WS&SOA FS2010

The concatenate operator - Short Demo


This BPEL process receives a message concatenates a string to it and sends the resulting message back to the sender.

ETH Zurich WS&SOA FS2010

Invoking an External Web Service


Can invoke synchronous or a synchronous web services
For the 2nd case we dont have the output variable Can be associated with another action that acts as a compensation action.
<invoke partnerLink="ncname" portType="qname" operation="ncname" inputVariable="ncname"? outputVariable="ncname"? standard-attributes> standard-elements <catch faultName="qname" faultVariable="ncname"?>* activity </catch> <catchAll>? activity </catchAll> <compensationHandler>? activity </compensationHandler> </invoke>

ETH Zurich WS&SOA FS2010

Invoking an external service from a BPEL Process Short Demo


The BPEL process receives a request and invokes an external service. The response of the service is then sent back

ETH Zurich WS&SOA FS2010

10

Control Structures
BPEL uses various expression types
Boolean (while, switch, if) Deadline-valued (until) Duration-valued (for)

ETH Zurich WS&SOA FS2010

11

Using a control sequence in a BPEL process Short Demo


Based on the received message we take the decision to use the assign activity or invoke an external service

ETH Zurich WS&SOA FS2010

12

Some Structured Activities


Sequence
Contains one or more activities that are performed sequentially
<sequence standard-attributes> standard-elements activity+ </sequence>

Flow
Provides concurrency and synchronization
<sequence> <flow standard-attributes> <invoke partnerLink="Seller" .../> <invoke partnerLink="Shipper" .../> </flow> <invoke partnerLink="Bank" .../> </sequence>

ETH Zurich WS&SOA FS2010

13

Using structured activities Short Demo


Invoking two services in a sequence or by using the flow activity

ETH Zurich WS&SOA FS2010

14

Some Structured Activities


Scope
Provides the behavior context for each activity Can have defined variables that live only within that scope Can delineate a part of the behavior
Can reverse actions in an application defined way using compensation handlers

Can have defined fault handlers Can be nested


ETH Zurich WS&SOA FS2010 15

Handling Failures
Signaling Faults
The throw activity can be used to signal internal faults explicitly
<throw faultName="qname" faultVariable="ncname"? standard-attributes> standard-elements </throw>

Compensation Handlers
Can be called to reverse the actions of a scope or invocation
<compensationHandler>? <invoke partnerLink="Seller" portType="SP:Purchasing operation="CancelPurchase" inputVariable="getResponse" outputVariable="getConfirmation"> </compensationHandler>

ETH Zurich WS&SOA FS2010

16

Handling faults
This demo shows how to deal and raise with faults. Once an fault was raised we do a compensate action for the inner scope that contains the invoke to the hello service
ETH Zurich WS&SOA FS2010 17

BPEL vs. Java


We can do all this using Java right?
B2B interactions benefit from this long running, hard to manage

True for very simple processes BPEL processes are portable even outside Java It is designed for business processes

Business processes must also react to alarms or message events Built in support for concurrent activities. BPEL processes are statefull for the duration of the process BPEL cant replace Java
ETH Zurich WS&SOA FS2010 18

synchronization primitives

References
Short Intro to BPEL
http://www.theserverside.com/news/1364554/BPEL-and-Java

BPEL 2.0 Specification


http://docs.oasis-open.org/wsbpel/2.0/wsbpel-v2.0.html

All the sources for the current demo can be found on the lecture web page

ETH Zurich WS&SOA FS2010

19

You might also like