Custom XPath Functions in OSB

Wikipedia says “Extensibility is a system design principle where the implementation takes into consideration future growth.Extensions can be through the addition of new functionality or through modification of existing functionality”.

The extensibility is possible even in case of OSB and custom XPath functions is one of the ways to extend the out-of-the-box functionality provided with OSB. In this  post, we talk about the procedure to come up with the custom XPath functions. Though the example taken in this post (division of numbers)does not represent the real-world case but sufficient enough to stress the point.

During the IDE and server start up, OSB checks for custom functions in the path $OSB_HOME/config/xpath-functions.

Creating the custom XPath functions involves coming up with an xml file and the java code that does the required task. The xml file is going to be similar to the file osb-built-in.xml provided in above path that contains OSB functions. So let us create a xml file custom-func-demo.xml with the below contents and place it the folder mentioned above.

<?xml version="1.0" encoding="UTF-8"?>
<xpf:xpathFunctions xmlns:xpf="
http://www.bea.com/wli/sb/xpath/config">
    <xpf:category id="Custom Functions">
       <xpf:function>
        <xpf:name>DivideNumbers</xpf:name>
        <xpf:comment>Function used for division of numbers</xpf:comment>
        <xpf:namespaceURI>
http://www.oracle.com/custom/custom-functions</xpf:namespaceURI>
        <xpf:className>demo.DivideNumbers</xpf:className>
        <xpf:method>java.lang.Double divide(java.lang.Double,java.lang.Double)</xpf:method>
            <xpf:isDeterministic>true</xpf:isDeterministic>
            <xpf:scope>Pipeline</xpf:scope>
            <xpf:scope>SplitJoin</xpf:scope>
            </xpf:function>
        </xpf:category>
</xpf:xpathFunctions>

The above XML fragment shows the custom XPath function name (Divide Numbers), Class Name, Java Method and the namespace that should be used to access the function in the message flow. ‘isDeterministic’ specifies whether the function is deterministic or non-deterministic. Deterministic functions always provide the same results where as Non-Deterministic functions return the unique results.

Create a simple java class with the following code. Make sure that class name (including the package) and method signature matches with the above xml contents. Create a jar of this and place it in the above mentioned location so that IDE and server can detect the custom function.

package demo;

import java.lang.Double;

public class DivideNumbers {
    public static Double divide(Double a, Double b) {
        return a/b;
    }
  }

On restart of Eclipse IDE and OSB server, we should be able to see the custom XPath function that we just defined.

           Xpath1

           Xpath4

           Xpath2

            Xpath3
Use the custom XPath function and run the proxy service to see the expected results as shown below.

            Xpath5

Advertisement

7 Responses to “Custom XPath Functions in OSB”


  1. 1 Vijay February 23, 2016 at 1:26 PM

    Excellent Post. Thank you very much for sharing…

  2. 2 koya November 18, 2013 at 4:49 PM

    Hi siva,

    same thing happened to me, jar file in the $OSB_HOME/config/xpath-functions path doesn’t reflect the changes in the sbconsole(even after restarting the server). Please suggest a solution.

  3. 5 Mani October 16, 2012 at 4:49 PM

    hi siva,
    Thanks for nice post,it’s ver helpful.I got the prefix as cus5e,is it possible to change to our own custom prefix,any suggestions?

    Thanks
    Mani

  4. 7 Chandrika Mitra November 16, 2011 at 7:51 PM

    Hi,
    This blog has been extremely helpful to me. However, I have a query, keeping the jar file in the $OSB_HOME/config/xpath-functions path doesn’t reflect the changes in the sbconsole(even after restarting the server). Please suggest a solution.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.




Pages

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 379 other subscribers

Enter your email address to follow this blog and receive notifications of new posts by email.


%d bloggers like this: