Friday, November 20, 2009

How to write a BPEL extension for WSO2 BPS 1.1.0 and Apache ODE

You may always wanted to write your own BPEL activity to handle your scenario. This article will go through step by step process to implement a simple BPEL extension activity for WSO2 BPS and Apache ODE.
WSO2 Business Process Server (BPS) is an easy-to-use open source business process server that executes business processes written using the WS-BPEL standard. It is powered by Apache ODE (open source BPEL engine) and provides a complete Web-based graphical console to deploy, manage and view processes in addition to managing and viewing process instances.

Implementation of Extension Bundle

Create a class by implementing one of the ExtensionOperation interfaces which are available at [1]. The run* method of this class should contain the implementation of the extension activity. You can find a sample implementation of this class at [2].
Then You have to create a class by implementing AbstractExtensionBundle interface. Within this class, the above implemented ExtensionOperation class should be registered. A sample implementation can be found at [3].

Configure WSO2 BPS

There are two methods to expose the extension classes to BPS.
  • Creating a jar.

    Copy the jar to BPS_HOME/repository/components/lib directory.
  • Creating an OSGI bundle

    Copy the bundle to BPS_HOME/repository/components/dropins directory.
Add the following configuration entry to the bps.xml file in BPS_HOME/conf directory. Repalce org.wso2.bps.samples.extension by your extension class name.
Note: By default, the sample extension bundles shipped with WSO2 BPS are copied to BPS_HOME/repository/components/lib. You have to add the following configuration to get them registered in BPS.
<bps xmlns="http://wso2.org/bps/config">
...
<extensionBundles>
<runtimes>
<runtime>org.wso2.bps.samples.extension</runtime>
</runtimes>
</extensionBundles>
...
</bps>
Now, restart WSO2 BPS sever, and you are ready to use the new extension in your BPEL.

The process is almost the same for Apache ODE. But there is a separate configuration file to register the extension. Please refer ODE extensions documentation for more details.

Using the Extension activity in your BPEL

The extension must be declared before, it is used.
<bpel:process...>

<bpel:extensions>
<bpel:extension namespace="#extension-namespace#" 
                        mustUnderstand="yes|no"/>
</bpel:extensions>

...
</bpel:process>
If the mustUnderstand attribute is set to yes, then the extension should be registered in BPS server in order to deploy the BPEL process. Otherwise, it will throws an error at the compilation stage of the process. If the mustUnderstand attribute is set to no, then the BPEL process will be deployed without checking whether there is an extension registered in the server.

Using the activity. According to the sample anyElementQName should be equal to b4ptest
<extensionActivity>
<anyElementQName standard-attributes>
standard-elements
</anyElementQName>
</extensionActivity>
You can find a sample BPEL process at TestExtensionActivity.zip

References:

[1] - extension

4 comments:

  1. Hi
    can you provide the zip file TestExtensionActivity.zip (link is dead) for a fully example, I am having trouble calling my extension?

    Thanks

    ReplyDelete
  2. Hi Gary,
    Can you try now. I fixed the link.

    Thanks

    ReplyDelete
  3. Hi,
    I try to setup your given example(TestExtensionActivity.zip),and my runtime environment consist of eclipse , apache ode 1.3.5 ,tomcat.

    And I put B4PExtensionBundle.jar to /WEB-INF/lib and Registered the extension in /WEB-INF/conf/ode-axis2.properties and add the following lines
    ode-axis2.extension.bundles.runtime = org.wso2.bps.samples.extension.B4PExtensionBundle

    Unfortunately, the BPEL process can be executed successfully but the jar seem not be invoked.

    Could you give me some suggestion?

    Thanks.


    ReplyDelete
    Replies
    1. Hi, BPEL extensions are only supported in Apache ODE 2.x branch. But ODE 2.x is no longer maintained. Therefore you can try WSO2 BPS which is also based on Apache ODE but with extension support. http://wso2.com/products/business-process-server/

      Delete