Writing BPEL Extensions
This topic provides instructions on how to write your own BPEL activity to handle your scenario. This provides step-by-step instructions to implement a BPEL extension activity for WSO2 BPS.
Implementation of an extension bundle
Create a class by implementing the ExtensionOperation
interface. The run()
method of this class should contain the implementation of the extension activity. A sample implementation of this class is given below.
package org.wso2.bps.samples.extension; import org.w3c.dom.Element; import org.apache.ode.bpel.runtime.extension.ExtensionContext; import org.apache.ode.bpel.extension.ExtensionOperation; import org.apache.ode.bpel.common.FaultException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class B4PExtensionOperation implements ExtensionOperation { protected final Log log = LogFactory.getLog(getClass()); public void run(Object o, String cid, Element element) throws FaultException { log.info("Executing \"b4ptest\" activity"); ExtensionContext tempEC = (ExtensionContext)o; ((ExtensionContext)o).complete(cid); //complete the activity /* //To complete with a fault Exception e = new Exception("Test Exception for the Extension activity"); ((ExtensionContext)o).completeWithFault(e); */ } }
Now create a class by implementing AbstractExtensionBundle
interface. The above implemented ExtensionOperation
class should be registered within this class. A sample implementation is given below.
package org.wso2.bps.samples.extension; import org.apache.ode.bpel.runtime.extension.AbstractExtensionBundle; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class B4PExtensionBundle extends AbstractExtensionBundle { protected final Log log = LogFactory.getLog(getClass()); public static final String NS = "http://ode.apache.org/extensions/b4ptest"; public String getNamespaceURI() { return NS; } public void registerExtensionActivities() { log.info("Registering B4PExtensionBundle."); registerExtensionOperation("b4ptest", B4PExtensionOperation.class); } }
Configure WSO2 BPS
There are several ways to expose the extension classes into BPS.
- Method 1: Creating a jar and copying it to theÂ
BPS_HOME/repository/components/lib
directory. - Method 2: Creating an OSGI bundle and copying it to theÂ
BPS_HOME/repository/components/dropins
directory.
Add the following configuration entry to the bps.xml file in the BPS_HOME/conf
directory. Replace org.wso2.bps.samples.extension
by your extension class name.
<bps xmlns="http://wso2.org/bps/config"> ... <extensionBundles> <runtimes> <runtime>org.wso2.bps.samples.extension</runtime> </runtimes> </extensionBundles> ... </bps>
Restart the BPS server. Now you are ready to use the newly created extension in your BPEL process.
Using the extension in your BPEL workflow
The extension must be declared before it is used. Put the extension namespace that you have configured in the ExtensionBundle class.
<bpel:extensions> <bpel:extension namespace="http://ode.apache.org/extensions/b4ptest" mustUnderstand="yes" /> </bpel:extensions> …... …… <bpel:extensionActivity> …<any elements or tags />..... </bpel:extensionActivity>
If the mustUnderstand
attribute is set to yes
, the extension should be registered in the BPS server in order to deploy the BPEL process. If this is not done, it will throw a compilation error. If the mustUnderstand
attribute is set to no
, the BPEL process will be deployed without checking whether there is an extension registered in the server.