This article is more than 1 year old

Programming constructs in BPEL

Part 3: BPELJ and Compensation

In this column in our series examining BPEL and its use within Service Oriented Architecture (SOA) systems, I'll will be looking at BPELJ and Compensation.

BPELJ is an extension to the core BPEL (Business Process Execution Language), which allows the direct inclusion of Java code within a BPEL script. Compensation is actually a core element of BPEL that provides an undo-like facility for situations where part of a BPEL script fails and other parts require their effects to be undone.

BPELJ

The aim of BPELJ is to let you embed Java and J2EE processes in a BPEL process. The intention is to allow portable integration of Java and J2EE applications into BPEL across application servers. In practice, most BPEL engines have allowed integration with programming languages such as Java in one form or another for some time, but via their own proprietary extensions. Thus, there have been BPEL extensions without portability, which I personally find extremely frustrating - because I need to support multiple application server environments.

BPELJ offers a glimmer of hope, in that it aims to provide a standard extension to BPEL for inline Java. The aim of BPELJ is to combine the power of a general purpose programming language such as Java with the orchestration and integration facilities of BPEL. By doing this, developers are free to select the appropriate "programming" language for the level of task they are implementing.

The Design of BPELJ

The design of BPELJ allows Java code to be embedded directly within a BPEL script in similar way to the embedding of Java within a JSP page. That is, BPELJ allows sections of Java code, called Java snippets, to be included in BPEL process definitions. Snippets are expressions or small blocks of Java code used for such things as loop conditions, branching conditions, variable initialisation, calling methods on Java objects etc.

Within BPEL standard extension points are used to support BPELJ. For example, a new partner link type is defined that references Java code; variables can now be typed as being of a specific Java class; and BPELJ code snippets can contain valid Java code statements, with the ability to invoke methods on Java classes from within BPEL statements.

BPELJ Examples

The following BPEL script illustrates the concepts presented in the above section. I've omitted much of this example for clarity, however, the core BPELJ elements remain:


<process name="BookCheck" 

expressionLanguage="http://jcp.org/java"

bpelj:package="com.regdev.example"

xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"

targetNamespace="http://regdev.com/bp/BookCheck"

xmlns:bpelj="http://schemas.xmlsoap.org/ws/2003/03/business-process/java"

xmlns:pq="http://regdev.com/ws/external/BookCheck">

<partnerLinks>

      ...

      <partnerLink name="lookup"  

              partnerLinkType="bpelj:com.regdev.BookLookup"/>

<variables>

   ....

   <variable name="message" type="bpelj:com.regdev.TextMessage"/>

</variables>

<sequence>

...

<flow>

...

</flow>

<bpelj:snippet name="Calculate Total">

   <bpelj:code>

      ...

      subtotal = subtotal * (1 – discount.getRate());

      response.setSubtotal(subtotal);

      float taxes = subtotal * taxRate;

      float total = subtotal + taxes;

      response.setTax(taxes);

      response.setTotal(total);

      ...

   </bpelj:code>

</bpelj:snippet>

...

<invoke partnerLink="BookLookup" operation="checkRegistration">

    <input part="Title" variable="title"/>

    <input part="ISBN" variable="isbn"/>

</invoke>

...

</sequence>

</process>
Next page: Compensation

More about

TIP US OFF

Send us news


Other stories you might like