SOA Suite 12c: Support for reusable XQuery Libraries | Modules image190

SOA Suite 12c: Support for reusable XQuery Libraries | Modules

It featured in many forum discussions (such as this one) in the last few years: “The Oracle Service Bus XQuery engine fully supports all of the language features that are described in the World Wide Web (W3C) specification for XQuery with one exception: modules”. See for example the W3C spec. Library Modules would make it possible to create reusable XQuery functions, that are available for use in any XQuery transformation. Unfortunately, Service Bus did not support this before 12c and as a result, useful functions were frequently copied and pasted (oh, the horror…).

In SOA Suite 12c, the XQuery Library Module is a first class citizen in both Service Bus projects and SOA composite applications. Modules can be created:

image

and used from XQuery transformations.

This article will show a simple example of the use of such an XQuery library.

Local functions in XQuery files can be reused locally. It helps to structure an otherwise unwieldy XQuery function – but it does not contribute to reuse. We can however also create a library module with XQuery functions that can be reused across XQuery files. From the New Gallery, create an XQuery Library. Set the name to TimeAndDateLibrary. Specify the namespace – for example saibot.airport/utilities. Define a function called age with a single input parameter called birthdate, of type xs:date. The return type of the function is xs:string.

image

Press OK to create the library module.The XQuery editor opens. Note the module keyword and the namespace definition. The outline for function age is provided based on what was entered in the wizard.

Switch to source mode and complete the function implementation like this:

image

Define Service Interface

For this example, I have created a simple service interface:

image

using this schema:

image

Create Proxy Service and Pipeline

From this WSDL definition, I have created a very simple Service Bus project – generating a Proxy Service with associated Pipeline from the WSDL document:

image

I have next created a simple XQuery transformation, to take the input personType and create the output greetingType:

image

 

image

image

Edit the Pipeline. Add a pipeline pair to the pipeline. Add a Replace activity to the Response pipeline.

image

Set the Location to body. From the dropdown list on the Value element, select XQuery resources.

Select XQuery file Greeting.xqy.

image

provide the mapping details to the input for this xquery function:

image

Press OK to complete the XQuery expression setting for the Replace activity.

Set the Replace Option to Replace node contents.

Right click on the pipeline and select Run from the context menu.

image

The service tester opens after the service is deployed to the Integrated WLS.

image

Enter some sample data and press Execute. The service is invoked and the response is shown:

image

 

Import Libray Module in XQuery file

Now the meat of this article: importing the library module and using the custom defined reusable function in the XQuery transformation.

Open the document Greeting.xqy. Click on the icon for Importing Library.

image

Select the TimeAndDateLibrary.xqy from the Application resources.

Select the expression that maps the target value to the Message element. Open the User Defined Components section in the components palette. This section should now display the TimeAndDateLibrary.xqy and with it the age function.

image

Drag this function to the appropriate position in the concat expression.

Provide the input parameter for this function call by dragging the Birthdate element:

image

The result looks like this:

image

and in source code view -note the import module statement with the namespace definition and the function usage:

image

Test run the pipeline, this time starting the pipeline from the project overview editor:

image

The service project is deployed, the tester is opened. Provide sample data and press Execute:

image

And the result is displayed, indicating that the function age in the XQuery Library Module was invoked:

image

2 Comments

  1. Gobinath November 19, 2015
  2. Pierluigi Vernetto June 29, 2014