Simplifying Error Handling with Custom XPath Function

How many times have you developed error handling logic in a BPEL process and want to collect error information to pass to an error handler service?  There are many xpath functions that are currently available and can be utilized individually to collect all the necessary data, however this can become a time consuming task when you have several catch blocks and many processes.  This is a case where re-use is a must.  Simplifying the collection of the error data will ensure that the error handling is completed and performed in a consistent manner across processes.

Re-using the logic doesn’t imply copying the logic to another process, this leads to maintenance problems since we will inherently forget every place it was copied.  You could create small utility BPEL processes that manage the logic but that can be a bit heavy weight and probably overkill.

Custom XPath functions come to the rescue and solve this problem by providing a framework to generate a custom java class that can perform the collection of all the error data and return a XML document in the structure of the specific error handler.

Now we know we want to create a custom XPath function to populate the following CommonErrorHandler.xsd, so here are the steps required.

<?xml version=”1.0″ encoding=”UTF-8″ ?>
<xsd:schema xmlns:xsd=””

<xsd:element name=”CommonErrorHandler”>
<xsd:element name=”interfaceName” type=”xsd:string”/>
<xsd:element name=”instanceId” type=”xsd:string”/>
<xsd:element name=”messageId” type=”xsd:string”/>
  • Create a java project in JDeveloper called BlogXpathFunctions.
  • Open up Project Properties the newly created project
    • Default package name: mycompany
    • Click on Libraries and Classpath
    • Click on Add Library, add BPEL Runtime and SOA Runtime to the project


  • Create a java class
    • Name: Helpers
    • Package name:
    • Add the following methods to this class, these methods will help in creating the return document.
public static Element createElementWithValue(Document document, String nodeName, String namespaceURI, String value){

   Element elem = document.createElementNS(namespaceURI, nodeName);
   Text text = document.createTextNode(value);
   return elem;

public static Document prepareDocument() throws ParserConfigurationException {
   try {
      DocumentBuilderFactory factory =
      DocumentBuilder builder = factory.newDocumentBuilder();
      return builder.newDocument();
   } catch (Exception e) {
      throw new ParserConfigurationException(e.getMessage());
  • Create a java class
    • Name: BlogFunctions
    • Package:
    • Add below method to class. BPEL and XSLT require very specific signatures and implementation to work properly.
public static class PopulateErrorDataFunction implements IXPathFunction
   public Object call(IXPathContext iXPathContext, List list) throws XPathFunctionException
         return BlogFunctionsImpl.populateErrorData(iXPathContext);
      catch (Exception e)
         throw new XPathFunctionException(e.getMessage());
  • Create a java class
    • Name: BlogFunctionsImpl
    • Package:
    • Add below method to class. Make sure that the namespace in this class matches your xsd namespace.
public static final String sERROR_DATA_NAME_SPACE = “”;

public BlogFunctionsImpl()
public static Object populateErrorData(IXPathContext pIXPathContext)
         throws XPathFunctionException, ParserConfigurationException
  Node rootNode = null;
  try {
     Map props = (Map)pIXPathContext.getVariableValue(null, null, “xpath-function-data”);

     ICubeContext cubeContext = (ICubeContext)props.get(“ICubeContext”);
     ICubeInstanceImpl cubeInstance = CubeContextHelper.getCubeInstance(cubeContext);

     Document document = Helpers.prepareDocument();
     rootNode = document.createElementNS(sERROR_DATA_NAME_SPACE,
                                                     “interfaceName”, sERROR_DATA_NAME_SPACE,
                                                    “instanceId”, sERROR_DATA_NAME_SPACE,
                                                     “messageId”, sERROR_DATA_NAME_SPACE,
   catch (Exception e)
      throw new XPathFunctionException(e.getMessage());
   return rootNode;

Need to create a descriptor file to let SOA know about the new XPath function that was created, so it can be utilized. It needs to be saved in a META-INF folder in the src directory.  The file name is ext-soa-xpath-functions-config.xml.  The contents must match below:

  • Important to make sure the package name from the BlogFunctions class is added as shown.
  • This is the name that will show up in the expression builders.
  • This is the class name from the BlogFunctions class.
<?xml version=”1.0″ encoding=”UTF-8″?>
<soa-xpath-functions xmlns=””        xmlns:blog=””>
  <function name=”blog:populateErrorData”>
    <return type=”node-set”/>
    <desc>Returns a error handler object</desc>
  • Deploy the project to a jar
    • Click on Deploy
    • Click on New Deployment Profile
    • Click on Jar File
    • Name the deployment profile the same as the project
  • Add xpath functions to JDeveloper
    • Click on Tools
    • Click on Preferences
    • Click on SOA
    • Click on Add and search for the newly created jar file
    • Recycle jdev to take effect
  • Add xpath functions to Server
    • Copy newly created jar file to $OracleHome/Oracle_SOA/soa/modules/oracle.soa.ext_11.1.1/classes
    • Run build.xml from the oracle.soa.ext_11.1.1 directory, this will register your new class with the server
$OracleHome/modules/org.apache.ant_1.7.1/bin/ant –buildfile build.xml
  • Recycle the server to take effect

You can now utilize your new custom xpath functions.

In my next blog, we will enhance the xpath functions to include parameters.

2 thoughts on “Simplifying Error Handling with Custom XPath Function”

    1. Rebecca Pruess

      Hi Kumar,


      import oracle.fabric.common.xml.xpath.IXPathContext;
      import oracle.fabric.common.xml.xpath.IXPathFunction;
      import oracle.fabric.common.xml.xpath.XPathFunctionException

      depending in what you want to do, add the following jars:


      the paths depend upon your installation, so I just provided the jar names.

      Let me know if you need something else.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top