Thursday, April 14, 2011

Setting Up Custom XPATH functions in OSB

Custom XPath functions can be setup in OSB11g by following this link : http://eelzinga.wordpress.com/2010/05/10/oracle-service-bus-11g-using-custom-xpath-functions/

Main Steps for deploying custom Xpath functions for Base64 conversion are:

1. Copy the following files - OSBUtilities.jar , OSBUtililies.properties, and OSBUtilities.xml from D:\opt\app\osb11R1\OSB_HOME\config\xpath-functions on soaosbdev1  to the corresponding path in the target environment. If the target environment has multiple machines these files needs to be copied to the $OSB_HOME\config\xpath_functions directory on each of the machine.
2. Update setDomainEnv for each of the domains to include OSBUtilities.jar on Weblogic server's classpath.
3. Restart the whole domain - admin servers and managed servers.

OSBUtilies.jar and the xml and properties file can be extended to include more custom xpath functions in future. Currently the jar contains only 1 class file - Base64Converter.class. New classes implementing new custom functions can be added to  this jar and the xml files and properties file can be extended.

Attaching the source code for Base64 converter which if you want you can put in version control..

Base64Converter.java
public class Base64Converter
{
public static String encodeBase64(String input)
{
try
{
String encoded =new sun.misc.BASE64Encoder().encode(input.getBytes( ));
return(encoded);
}
catch (Exception ex)
{
 return("error");
}
}

public static String decodeBase64(String input)
{
try
{
String decoded =new String(new sun.misc.BASE64Decoder().decodeBuffer(input));
return(decoded);
}
catch (Exception ex)
{
 return("error");
}
}

}