OSB: Configuration with custom XQuery functions

The OSB supports a mechanism of customization. Unfortunately this mechanism is very limited and is not able to change all values. There are hundreds of situations where some kind of configuration is needed and which can’t be solved with customization:

  • A configurable value need to be added to a request
  • Username and password can’t be provided with a service account because they are not transferred as basic authentication
  • The behavior of a proxy service should be able to be changed by a switch
  • Paths for reading and writing files from should be configurable

For these cases we decided to implement an old fashioned configuration file.  But how should we access the values from the configuration file?

One possibility would be java callouts. But it is cumbersome to add a java callout for each needed value.

A better solution for this kind of framework functionality is custom XQuery functions.

First we create a java project in our favorite java development tool. For the XQuery we have to create a class with static methods. Simple parameters are supported and overloading the methods is ok. For our configuration XQuery we use this java class ConfigXQueryFunctions:

The class references here another class holding the real configuration information. It is a good idea to implement an auto-reload of the configuration to support on the fly changes. The method signatures in the example don’t have a parameter for a file or a OSB project, so there can be only one configuration file for the OSB. 

After writing the java code and some unit tests (unit tests are a very good idea here because it is much work to do a redeployment of the XQuery lib for doing a change) the code should be compiled into a jar file.

Additionally we need a xml file describing the XQuery functions.

The category id while be the text shown in eclipse while using the functions. And also the namespace is important: Eclipse is generating while using the function a prefix out of the namespace. If you change the namespace afterwards you have to change the prefix on every location you used the XQuery function.

The names of the XQuery functions should NOT be overloaded here. Overloaded names didn’t work for me and I have not found out how to fix it.

Now we have to deploy the XQuery to the OSB and to Eclipse. It is a drop in deployment: You have to copy the JAR archive and the XML file to the folder Oracle_OSB1/config/xpath-functions. After that a restart of the OSB / Eclipse is necessary.

Now you can use your custom XQuery functions inside of XQuerys

BLOG_OSB_CustomXQuery_01

or inside the proxyservice

BLOG_OSB_CustomXQuery_02

 

Bernhard Mähr @ OPITZ-CONSULTING published at http://thecattlecrew.wordpress.com/

Leave a Reply