Introducing BPEL4WS 1.0: building on WS-Transaction and WS-Coordination – Feature
In July 2002, BEA, IBM, and Microsoft released a trio of specifications designed to support business transactions over Web services. These specifications, BPEL4WS, WS-Transaction, and WS-Coordination (see WSJ, Vol. 3, issues 5-7), form the bedrock for reliably choreographing Web services-based applications, providing business process management, transactional integrity, and generic coordination facilities, respectively.
The value of BPEL4WS is that if a business is the sum of its processes, the orchestration and refinement of those processes is critical to an enterprise’s continued viability in the marketplace. Those businesses whose processes are agile and flexible will be able to adapt rapidly to and exploit new market conditions. This article introduces the key features of Business Process Execution Language for Web Services, and shows how it builds on the features offered by WS-Coordination and WS-Transaction.
The BPEL4WS Stack
The BPEL4WS model is built on a number of layers, each one building on the facilities of the previous. Figure 1 shows the fundamental components of the BPEL4WS architecture, which consists of the following:
* A means of capturing enterprise interdependencies with partners and associated service links
* Message correlation layer that ties together messages and specific workflow instances
* State management features to maintain, update, and interrogate parts of process state as a workflow progresses
* Scopes where individual activities (workflow stages) are composed to form actual algorithmic workflows
[FIGURE 1 OMITTED]
We’ll explore the features of this stack, starting with the static aspects of the application –capturing the relationship between the Web services participating in workflows –and on to the creation of workflows using the BPEL4WS activities.
Mapping Interenterprise Relations
To create workflows that span enterprises, we must understand how those enterprises are related. BPEL4WS provides a means of capturing the roles played by business partners in a Web services-based workflow through service linking, partners, and service references.
Figure 2 shows the relationship between service links, partners, and service references. Service links are the most abstract relationship supported in BPEL4WS, and link two parties by specifying the roles of each party and the (abstract) interface that each provides. serviceLinkType definitions can either be part of a service’s WSDL interface, or defined separately and referenced by the WSDL. Embedding this definition directly in a WSDL description leverages WSDL’s extensibility mechanism, allowing serviceLinkType elements to become a direct child of the wsdl:definitions element.
[FIGURE 2 OMITTED]
The actual content of a serviceLinkType is straightforward. It usually defines a link between two services, qualified by the targetNamespace of the WSDL document; and then exposes that relationship as two roles. In some cases, a serviceLinkType may specify a single role, which indicates that the workflow is willing to bind to any other service, without placing any requirements on that service.
In Listing 1 (the code for this article can be found online at www.sys-con.c om/webservices/sourcec.cfm), two sample serviceLinkType elements are defined. The first defines a link between a WidgetSeller and a WidgetBuyer service. When a WidgetBuyerSellerLinkType is used in a workflow, it will implicitly associate a WidgetSellerPortType with a WidgetBuyerPortType, and enforce the appropriate operation and message constraints. The second defines an Enquiry-LinkType that is used to model the link between the widget manufacturer and a third party making widget-related enquiries. Note that in this case, there is only one role specified, WidgetAuthority, which indicates that the widget manufacturing service is willing to link to any other service without placing any further constraints on the interface exposed by that service.
A BPEL4WS partner refines a serviceLinkType declaration by defining the roles played by actual partners at the endpoints of the relationship. A partner is declared within the workflow script because it forms part of the behavior of that workflow. Partnerships only make sense within the scope of the workflow where business partners interact. A sample partner declaration for a user authentication system is presented in Listing 2.
Inside the partners element we have individual partner declarations that specify the role of our enterprise and its partners on a per-serviceLinkType basis. Of the two partners defined in Listing 2, a customer specifies roles for both ends of the corresponding serviceLinkType declaration, in preparation for the bilateral exchanges that purchasing widgets necessitates. However, while enquiring about widgets the manufacturer is not fussy about who binds to and uses it, and so the partner declaration is unilateral, specifying only the myRole attribute as WidgetAuthority.
The final step in cementing our business interrelationships is to specify the network locations of our partners so that we can discover and consume their Web services.
Of course, physical network address locations change over time (and indeed sometimes change very rapidly over time), and WSDL has a means of supporting this through a separation of portType (abstract network interface) and port (physical, protocol-bound interface on the network), which are mapped through bindings and later exposed as services. The service consumer must understand the portType section of a WSDL document before it can consume a service, though the binding to an actual port can be delayed right up until that client needs to invoke that service at runtime. The information needed to create the runtime binding can be accessed in a number of ways, including out-of-band communication between users and directory services like UDDI. The point is, given the distinction between abstract and concrete in WSDL, BPEL4WS needs a means of bridging the same gap between abstract partner declarations and exchanging messages over the network with real services at runtime. This is addressed by ServiceReference elements, which are part of a workflow that acts as typed references to a specific service. ServiceReferences allow consuming services to bind abstractly defined partners to physical network endpoints, and expose those endpoints (along with other useful data) to workflow activities.
Listing 3 shows a minimal ServiceReference declaration where the service provided by a particular partner is statically embedded. In this case, the wsdl:service element defined in a service’s WSDL interface is used to create a “Web pointer” that can be used within the activities of a single workflow and passed amongst collaborating services as part of their message exchanges.
However, the real potency of ServiceReference comes to light when we dynamically compute or discover the endpoint or business process instance that we want to communicate with. We can thus augment the minimal ServiceReference shown in Listing 3 with specific instance information such as the ws:existingCustomer shown in Listing 4.
The ServiceReference shown in Listing 4 has additional information held by property elements within the referenceProperties element that identifies a specific resource hosted by a service. In BPEL4WS, that resource is likely to be an instance of a workflow. However, it may be a process or object identifier, or other identifier that has significance to both ends of the interaction. It is important to understand that while the computational aspects of BPEL4WS provide the ability to be able to obtain and utilize such properties, BPEL4WS does not place any semantics on them.
Message Properties and Property Aliases
Once we’ve captured the relationships between our enterprise and its partners, we can begin to exchange messages through the conduits defined by those relationships. Whether we are dealing with an invoice or a dispatch note, there is often a field or set of fields within that note that can be used to unambiguously differentiate that note from piles of other similar looking ones. For instance, an invoice number is usually used in correspondence rather than the date and address of the sender of the invoice since it is both simpler and more likely to resolve to a unique result. This notion of “distinguished” data is supported through message properties. Put simply, a message property is a unique name (within the workflow) that has a specific type from XML Schema (e.g., xs:postive Integer) and whose name has significance to the workflow (e.g., invoice number; see Listing 5).
Having a friendly name and type information for our property is akin to having object references in traditional programming languages. However, just like object references need to be bound to objects before we can use them, we need to bind properties to values before workflow scripts can access those values. In BPEL4WS we have a way of binding typed friendly names to values that we can use within our workflows–property aliases. A property alias binds the value of a property to the value of an element in a message using an XPath query. For instance, we may be interested in the invoice number from a purchase order and want to expose that value to the workflow.
Listing 6 shows you how to bind properties to values through propertyAlias declarations. The attributes in the element declare the property name that we are binding to (InvoiceNumber), the message (PurchaseOrderMessage), and the specific message part (invoice) where the value that we wish to bind to is located. The final step to complete the binding is to specify the XPath query (specified in the query attribute) that returns the value from the specified message part. In Listing 6 this is calculated by the expression/invoice number, which evaluates the contents of the first invoice-number element from the root context, where context is provided by the preceding messageType and part attributes. Now when PurchaseOrderMessage messages are processed, the property InvoiceNumber will be assigned the value of the corresponding invoicenumber in the message, or conversely may be used to assign such a value to the invoicenumber element, just like an object reference.
Once properties have been defined, they can be used to correlate messages. Using a property like an invoice number allows the underlying BPEL4WS implementation to route messages to particular workflow instances at the application level without relying on sophisticated conversational transports to manage that mapping. As we shall see, the BPEL4WS communication activities encapsulate this behavior to further simplify matters
Containers and Data Handling
In dealing with Web services-based workflows we encounter a significant philosophical difference between the two technologies: workflows are inherently stateful applications, whereas Web services are inherently stateless. Of course many Web services do actually maintain state between invocations, but do so in a proprietary manner in databases, files, statically allocated program variables, and so on, all of which requires programmer effort and is likely to be inaccessible to the business analyst. BPEL4WS has abstracted these proprietary approaches and replaced them with a generic state management facility based on containers.
A BPEL4WS container is a typed data structure that stores messages associated with a workflow instance. The underlying notion of containers is that in a workflow the state of the application is simply a function of the messages that have been exchanged. Containers begin their lives uninitialized, and are populated over time by the arrival of messages, or computations being executed that populate them.
Listing 7 shows a simple container declaration that could be used by a cable operator to store requests for package updates. This container is used for holding incoming channel addition requests from customers while our workflow process goes about the business of updating the customer’s billing details and set-top box software accordingly.
Declaring a container is straightforward. It consists of a name for the container that is unique within the scope of the workflow process definition, and the type of the message as defined in the corresponding WSDL document. For this example the WSDL interface identified by the coprefix resolves to http://cableoperator. example.org/wsdl which is the address at which our fictitious cable operator resides.
Generally, the messages stored in containers are the same messages that are exchanged with partners. However, there is nothing to prevent a programmer from concocting a message type purely to store local variables during computations. Such messages are never exchanged with partners, and are usually declared in-line with their associated containers (see Listing 8).
BPEL4WS defines a set of communication activities that deal with the sending and receiving of messages so that a workflow process instance can communicate with partners’ Web services. BPEL4WS provides three activities–invoke, receive, and reply–each of which handles a different type of interaction between partners in a workflow.
The invoke activity allows a workflow instance to call a synchronous or asynchronous operation on a remote Web service. An asynchronous one-way operation is the simplest form of invoke since it only requires a single input container to send messages. Look at the example shown in Listing 9 where a request for additional cable TV channels is sent from a set-top box to a cable operator’s system. The invoke activity calls the add-Channel operation from the ChannelManagementPortType portType exposed by its CableOperator partner, sending a message from the Re-quested Channels container to request additions to the subscriber’s package.
Web service operations are exposed to the outside world by a receive activity. The receive activity is the workflow entity that a WSDL operation maps onto. In Listing 10 we show the receive activity that the cable operator exposes as its addChannel operation (the operation invoked by customers in Listing 9). The cable operator uses a container called addChannelOrders to hold incoming AddChannelMessage messages from customers. When the receive activity is activated by the arrival of an AddChannelMessage from a customer, a new instance of the cable operator’s channel adding workflow is created and executed.
A receive activity is blocking, which does not allow the workflow graph it precedes to progress until the messages it requires have been received. Such activities may be used to trigger the creation of a new workflow instance in response to an incoming message, or they may deal with the message delivery to an existing instance.
A reply activity sends synchronous responses to messages received through a receive activity. Correlation between a receive and a reply is handled by the underlying BPEL4WS implementation.
Listing 11 shows an example reply activity, where a message from CustomerSubscriptionDetails is sent back to a customer partner in response to a prior incoming message to a receive activity.
In order to execute a process, we need a means of describing its behavior. We have to understand the features that the workflow language provides to manipulate data, iterate, call external functions, and so on; and how to compose these primitives into meaningful workflows. To support this, theBPEL4WS specification defines a number of fundamental activities that are the basic building blocks of the workflow. It is beyond the scope of this article to look at every facet of each language construct defined by BPEL4WS, but we will give you an idea of what kinds of things are possible.
BPEL4WS control flow activities are responsible for serializing and paralleliz-ing activities, choosing from alternative paths in a workflow, iterating commands, and so on. The simplest construct is the sequence activity that executes subactivities serially, as shown in Listing 12.
Parallelizing activities that have no dependencies is achieved by enclosing the parallel activities within a flow element. For example, a customer’s computing system, which initiated a hotel reservation, may also have been organizing flights and car rentals simultaneously. If we assume these activities are independent, we can execute them in parallel with a flow activity like that shown in Listing 13.
A scope is a means of explicitly packaging activities together so that they can share common error handling and compensation routines. The full structure for a scope is shown in Figure 3 and consists of a set of optional fault handlers, a single optional compensation handler, and the primary activity of the scope, which defines its behavior.
[FIGURE 3 OMITTED]
In the absence of a scope declaration, each activity is implicitly associated with its own scope with the same name as, and delimited by, the activity. An example scope that captures the booking process for a ticket is shown in Listing 14.
The normal behavior for the scope shown in Listing 14 is for the booking activity near the bottom of the example to be executed and for flight tickets to be reserved. However, this scope declares a number of exception handlers with catch activities that allow a variety of faults that might occur while booking tickets to be rectified before they cause further problems. For instance, these catch activities deal with such matters as a flight number being incorrectly specified, a flight already being fully booked, or a fault in the payment method used to purchase the tickets. We can assume here that these fault handlers are able to correct any problems so that the scope can complete normally. The catchAll handler is a little different in that it handles any faults other than those that are explicitly handled by the preceding catch activities. Since the nature of the fault is unknown, the designer of this scope has decided that the safest thing to do is to compensate the inner scopes by calling the logic held in their compensation-Handler activities to restore the system to the same state (or a logically equivalent state) as it was before the top-level scope executed. The skeleton for a compensationHandler is shown in Listing 15.
Compensation handlers are a fundamental component of BPEL4WS work-flows to support reliable long-lived business processes. During the execution of a workflow, data in the various systems that the workflow encompasses changes. Since we have no knowledge of the underlying computing systems (databases, queues, etc.) that the workflow is utilizing, we must compensate at the application level by performing the logical reverse of each scope that was executed as part of our workflow, from the most recently executed scope back to the earliest executed scope.
Where fault handlers provide alternative forward execution paths through a scope, compensation handlers, when invoked, undo the work performed by a scope. Since a compensationHandler for a specific scope reverses that scope’s work, the handler can potentially be as complex and intricate as the scope’s normal original activity.
A compensationHandler can also be set to compensate an entire business process after its normal completion (instead of individual scopes).
As we saw in an earlier article in this series, the BPEL4WS specification suggests WS-Transaction as the protocol of choice for coordinating distributed transactions across workflow instances. Thus, when a scope containing invocations on a partner’s Web services is compensated, the underlying BPEL4WS engine should ensure that the appropriate WS-Transaction messages are sent to the transaction coordinator so that any partner’s systems can be informed of the need to compensate the invoked activities.
BPEL4WS is at the top of the WS-Transaction stack and utilizes WS-Transaction to ensure reliable execution of business processes over multiple workflows, which BPEL4WS logically divides into two distinct aspects. The first is a process description language with support for performing computation, synchronous and asynchronous operation invocations, control-flow patterns, structured error handling, and saga-based long-running business transactions. The second is an infrastructure layer that builds on WSDL to capture the relationships between enterprises and processes within a Web services-based environment.
Taken together, these two aspects support the orchestration of Web services in a business process, where the infrastructure layer exposes Web services to the process layer, which then drives that Web services infrastructure as part of its workflow activities.
The ultimate goal of business process languages like BPEL4WS is to abstract underlying Web services so that the business process language effectively becomes the Web services API. While such an abstract language may not be suitable for every possible Web services-based scenario it will certainly be useful for many, and if tool support evolves it will be able to deliver on its ambition to provide a business analyst-friendly interface to choreographing enterprise systems.
RELATED ARTICLE: BPEL4WS 1.1 and OASIS WSBPEL.
The original BPEL4WS 1.0 specification that we considered in this article has been superceded as part of the original vendors’ efforts to standardize the technology. IBM, Microsoft, BEA, and their partners have submitted a version 1.1 BPEL to OASIS under the WSBPEL (Web Services Business Process Execution Language) Technical Committee. The most obvious changes in BPEL4WS 1.1 are that the term “container” has been replaced with the more traditional term “variable,” although its type is still considered in terms of messages. These variables are now supported at arbitrary scope, unlike BPEL4WS, which only supported containers at the global process scope.
In addition to variables, the specification authors have added event handlers into the activity set by introducing the activity. An eventHandlers activity is similar to a pick activity insofar as it contains a number of onMessage or onAlarm activities, but it differs from the standard pick activity in that an eventHandler can be executed concurrently with the currently running scope. This allows concurrent processing within a single scope where previously concurrent “threads” of control were not permitted. Of course, there are some standard caveats with the use of an eventHandler, like the fact that one cannot be used to call a compensate activity, but these are minor and will easily be handled by tool support. BPEL4WS 1.1 and OASIS WSBPEL
Dr. Jim Webber is an architect and Web services fanatic at Arjuna Technologies, where he works on Web services transactioning and Grid computing technology. Prior to joining Arjuna Technologies, he was the lead developer with Hewlett-Packard working on their BTP-based Web Services Transactions product–the industry’s first Web Services Transaction solution. An active speaker and Web Services proponent, Jim is the coauthor of Developing Enterprise Web Services. JIM.WEBBER@ARJUNA.COM
Dr. Mark Little is chief architect, transactions, for Arjuna Technologies Limited, a spin-off from Hewlett-Packard that develops transaction technologies for J2EE and Web services. Previously, Mark was a distinguished engineer and architect at HP Middleware, where he led the transactions teams. He is a member of the expert group for JSR 95 and JSR 117, is the specification lead for JSR 156, and is active on the OTS Revision Task Force and the OASIS Business Transactions Protocol specification. Mark is the coauthor of J2EE 1.4 Bible and Java Transactions for Architects. MARK.LITTLE@ARJUNA.COM
COPYRIGHT 2003 Sys-Con Publications, Inc.
COPYRIGHT 2003 Gale Group