Tech Ads

Back to Article List

Originally published November 2005 [ Publisher Link ]

BPEL: Web Services orchestration, hands-on with ActiveBPEL

Designing Web services in the context of an SOA entails striking a balance between a series of issues -- mainly reusability and flexibility -- but once this initial design is done coordinating individual services to play out their role in an aggregated manner implies another set of requirements, most of which can be addressed through BPEL, Business Process Execution Language.

BPEL was created as a joint effort by IBM, Microsoft and BEA in 2003, but since its inception, BPEL has gained traction among Web services standards. Currently under the auspices of OASIS and in its 2.0 version, more than thirty five companies are shaping the future direction this standard will take in addressing Web services orchestration.

But what does Web services orchestration through BPEL, or as some other companies term it Web services workflow or choreography, mean for someone already using the basic Web services stack SOAP/WSDL/UDDI? Lets tackle the issue, assuming you are assigned the task of migrating a credit application system and enabling it with Web services.

By its very nature, our credit application will surely be interacting with third party systems and in this same process have tens or hundreds of call variations based on these same Web services that need to be fulfilled in order to satisfy the requirements made by different system users.

Structuring these Web services decision chains or workflows is what BPEL has been designed for. However, before we delve further into its concrete use, you should be aware of one important aspect, perhaps even prerequisite, to realizing the value proposition behind BPEL: Reusability.

In order to structure as many Web services-based business processes and glue them together with BPEL a very fine balance needs to be achieved on each individual service. Having coarse-grained Web services may defeat the whole purpose of using BPEL for creating different decision chains since they may be complete business processes unto themselves. Similarly, fine-grained services may prove unwieldy to reuse and structure with BPEL workflows.

This process is similar in nature to that of object-orientated design, where an object needs to do enough work to justify its existence while holding off from trying to be an Über-object. You should think of Web service design in the same fashion. As a matter of course, Web service reusability is one of SOA's primary tenets, but the case proves more evident when using BPEL as we will see shortly.

At its core, BPEL provides the necessary XML grammar to express Web service interactions and as such has provisions for declaring variables, flow control, transactions and error handling among other things you would expect from a language charged with orchestrating cooperation.

Since this also implies a paradigm shift from the basic SOAP/WSDL/UDDI approach to Web services, BPEL requires its own environment in which to execute these instructions, properly named BPEL engine.

Currently, BPEL engines vary in maturity and deployment complexity. While some vendors in the SOA landscape are tightly integrating their BPEL engines with other core offerings such as ESB's - a term loaded with controversy to say the least - others are creating standalone products in this same space.

In order to obtain a firm grasp on BPEL we will take the latter approach and exemplify BPEL through the most neutral and non-invasive approach possible, a Java open source BPEL engine named: ActiveBPEL.

ActiveBPEL, being a standalone BPEL engine, is designed to operate under any Java/J2EE application server in the form of a Web application (WAR file). Given ActiveBPEL's roots in open source, it has strong ties to the de facto Java/J2EE open source container Tomcat , Apache's Web services framework Axis and the popular build tool Ant .

These characteristics make ActiveBPEL an excellent alternative for exploring BPEL's functionalities since its operation depends on well known and readily available technologies. In case you don't have these packages on your workstation, download them and follow the basic installation instructions. We wont stray into fancy configurations, since the whole point of this choice is to get you up to speed on BPEL as quickly as possible.

Let's take a high-level view at the orchestration process we will be trying to achieve through ActiveBPEL. Your banking system needs to execute a credit application process that returns either a simple "yes" or a "no" based on a series of elaborate chained decisions that are taken from such things as the amount of a loan, a solicitor's credit history or a branch location, all of which are fulfilled by calling individual Web services.

Due to market conditions or bank policies this business process will more than likely change the manner in which it qualifies or disqualifies a credit application. Having an Über Web service that returns the results would be an extremely inflexible approach since it would imply continuous modification to the business logic behind the Web service each time a modification is required. On the other hand, having a BPEL process orchestrate the application logic gives us two main benefits.

BPEL's XML grammar grants us a level of indirection in which to alter the application's workflow without the need to modify behind the scenes business logic while also leaving us the door open for later reuse of a set of core Web services in more complex workflow scenarios.

Let's assume we have arrived at a final design -- the difficult part -- for our core Web services. Our two Web services will be composed of an approver and an assessor. The initial analysis shows that both can easily be reused for other credit evaluation processes. So now it's time to look at BPEL pseudo-code and see what we need to create in BPEL-XML syntax.

if (creditapplication < $10,000) {
        if (assessor returns "lowrisk")
                return "yes"
                return approver response
        return approver response

Our first step is checking the credit application amount. If this quantity is above a $10,000 threshold we hand of the input data to the approver Web service in order to obtain a response. On the other hand, if the application amount is below $10,000 we first invoke the assessor Web service, at which point, after returning an answer, if the response is "lowrisk" the application is immediately approved. Otherwise we need to make a further call to the approver Web service.

This is a very straightforward business process for our application, but one that clearly illustrates the power BPEL can achieve orchestrating different calling scenarios to our core Web services. Now lets take a look at the actual BPEL-XML syntax.

<?xml version="1.0" encoding="UTF-8"?> 
<process name="loanApprovalProcess" suppressJoinFailure="yes" 
      <partnerLink myRole="approver" name="customer" 
      <partnerLink name="approver" 
      <partnerLink name="assessor"

      <variable messageType="loandef:creditInformationMessage" 
      <variable messageType="asns:riskAssessmentMessage" 
      <variable messageType="apns:approvalMessage" 
      <variable messageType="loandef:loanRequestErrorMessage" 

      <catch faultName="apns:loanProcessFault" 
         <reply faultName="apns:loanProcessFault" 
       portType="apns:loanApprovalPT" variable="error"/>

         <link name="receive-to-approval"/>
         <link name="receive-to-assess"/>
         <link name="approval-to-reply"/>
         <link name="assess-to-setMessage"/>
         <link name="assess-to-approval"/>
         <link name="setMessage-to-reply"/>
      <receive createInstance="yes" name="receive1" 
                  operation="approve" partnerLink="customer"
      portType="apns:loanApprovalPT" variable="request">

      <source linkName="receive-to-approval" 
     <source linkName="receive-to-assess" 

      <invoke inputVariable="request" name="invokeapprover" 
         <target linkName="receive-to-approval"/>
         <target linkName="assess-to-approval"/>
         <source linkName="approval-to-reply"/>

      <invoke inputVariable="request" name="invokeAssessor" 
             operation="check" outputVariable="riskAssessment"
         <target linkName="receive-to-assess"/>
         <source linkName="assess-to-setMessage" 
         <source linkName="assess-to-approval" 
      <reply name="reply" operation="approve" 
         partnerLink="customer" portType="apns:loanApprovalPT" 

         <target linkName="approval-to-reply"/>
         <target linkName="setMessage-to-reply"/>
      <assign name="assign">
         <target linkName="assess-to-setMessage"/>
         <source linkName="setMessage-to-reply"/>

            <from expression="'approved'"/>
            <to part="accept" variable="approvalInfo"/>


Notice the various BPEL elements : <partnerLink>, <variable>, <faultHandler>, <flow>, >target>, among others. Obviously going into an exhaustive description of BPEL syntax would go beyond the scope of this article, but if you follow closely you will see the same patterns described in our pseudo-code. It should also be noted that most BPEL process are created using special editors in order to avoid the error prone process of writing XML by hand.

Having seen the actual BPEL process you might now be asking yourself were is the relation to our actual Web services -- the URI's, or WSDL descriptors? In the specific case of ActiveBPEL, this requires you define a Process Deployment Descriptor file which tells the BPEL engine about your processes. The following section shows this PDD file.

<process location="bpel/loanapproval.bpel" 

  <!-- Partner Link for inbound request from customer -->

    <partnerLink name="customer">
      <myRole allowedRoles="" binding="RPC" 

    <!-- Partner Link for outbound request to 
            delegate approver -->
    <partnerLink name="approver">

      <partnerRole endpointReference="static">
   <wsa:ServiceName PortName="SOAPPort">


    <!-- Partner Link for outbound request
            to risk assessment process -->
    <partnerLink name="assessor">
      <partnerRole endpointReference="static">

   <wsa:ServiceName PortName="SOAPPort">

    <wsdl location="project:/wsdl/loandefinitions.wsdl" 
    <wsdl location="project:/wsdl/loanapproval.wsdl" 

    <wsdl location="project:/wsdl/loanapprover.wsdl" 
    <wsdl location="project:/wsdl/loanassessor.wsdl" 

Notice how this descriptor associates the location of the BPEL process we saw earlier in the declaration <process location="bpel/loanapproval.bpel"> defines physical addresses for each <partnerLink> and declares various WSDL descriptors.

In essence, this last file ties together the BPEL process with our actual Web services. With this last illustration, you should also realize that Web services WSDL files form the backbone of any BPEL process.

The previous statement holds true because WSDL contracts describe the methods, messages and characteristics of a Web service. And a BPEL process, through its engine, makes ample use of the information contained in these standard Web services documents in order to orchestrate the desired business process.

That concludes our look at BPEL through ActiveBPEL. Having looked at the Loan Approval Application for ActiveBPEL and addressed its inner workings, you should now be in a position to realize the value BPEL can bring to your Web services and SOA developments.

Originally published November 2005 [ Publisher Link ]

Back to Article List