Custom XSLT functions in Oracle BPEL and ESB

In the Oracle SOA Suite there is a Custom XSLT function example. You can find it in bpel/samples/demos/XSLMapper/ExtensionFunctions. It is not immediately obvious that this approach of enabling access to static methods on a java class works for transformations in the ESB too. This is because both BPEL and ESB use the same Oracle XSLT processor.

The principle is simple:

To illustrate how straight forward this is I’ll go through an example that converts HEX to Decimal. So, with a class called xsltfunctions.HEX2DEC the namespace is defined in an XSL file as xmlns:sample = “http://www.oracle.com/XSL/Transform/java/xsltfunctions.HEX2DEC”.

The class HEX2DEC has static method called toDecimal:


public static String toDecimal(String hex) {
String dec = new BigInteger(hex, 16).toString(10);
return dec;
}

In the XSL file this method is invoked like this:

Note that the namespace prefix ‘sample’ is defined as mentioned earlier using the http://www.oracle.com/XSL/Transform/java/ combined with the classname.

So, you could compile the HEX2DEC class, add it to a jar and put that jar in /j2ee/home/applib so that any transform using the custom function in BPEL or ESB will work. It’s that simple.

All that’s left is to inform JDeveloper of your custom function so that you can easily refer to it in the XSL Mapper to do this you need to do two things:

  1. Create an XML file detailing the extension functions you have and tell JDeveloper about it in the “User Defined Extension Functions Config File” field of the XSL Map preferences (Tools->Preferences->XSL Map). This will list the functions in the User Defined Extension Functions section of the XSL Map component palette so you can drag and drop it into the XSLT at design time.
  2. Add the class to the JDeveloper classpath so that you can run the transform using the test feature with JDeveloper.

The extension functions XML looks like this:

To add the class to the JDeveloper classpath involves defining a JDeveloper extension. For JDeveloper 10.1.3.2 the extension needs to be a valid JSR 198 extension. Documentation on this can be found in /doc/extension/ide-extension-packaging.html.

Do this by defining a simple ‘extension.xml’ like this:

<extension version="1.0" esdk-version="1.0" id="xstlfunctions"
xmlns=”http://jcp.org/jsr/198/extension-manifest”&gt;
SOAStationXSLTFunctions
Peter O’Brien

The extension.xml (naming convention for these files) needs to be in the meta-inf folder of the jar containing the classes. The filename for the jar needs to be a combination of the extention id and esdk-version so in this case it would be xsltfunctions.1.0.jar. This jar should then be copied into the /extension directory.

Restart JDeveloper to pick up the changes for both the ‘User Defined Extension Functions Config File’ and the JDeveloper extension and you’re ready to go.

Generating IFX RqUID in Oracle ESB

Interactive Financial eXchange (IFX) is an XML based inter bank communication standard used by a number of banks around the world. You can find out more about IFX at the IFX Forum. An IFX message must have a request identifier called RqUID. A client uses RqUID to uniquely identify a request message. It is a universally unique ID (UUID) that is generated by the client and is used to correlate responses with requests.

Often with integration exercises the interfaces do not match. Take the simple case where one system must send a request to another system but the request structures are defined differently for both. One example is when a system sends a customer search message which must be provisioned by an IFX system. The customer search message has to be tranformed into a CustInqRq message for the IFX system. This can be facilitated through the ESB. The transformation performed by the ESB can be used to generate field values that are not supplied in the initial request.

To include an IFX RqUID using Oracle ESB you can take advantage of the XPath Extension Function orcl:generate-guid() and format it accordingly like this:



<xsl:variable name="rquid"
select="orcl:format-string(
'{0}-{1}-{2}-{3}-{4}',
substring($guid,1,8),
substring($guid,9,4),
substring($guid,13,4),
substring($guid,17,4),
substring($guid,21, 12))" />

This will create a variable called rquid with the required XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX format. You can now assign this variable to the relevant RqUID fields in the transformation. e.g.





Note: If there are mutlitple requests to be sent at the same time then redefine the variable each time it is needed. Otherwise just defined it once at the beginning of the transformation.