Dynamic XQuery in Oracle Service Bus

Well routing to a dynamic Proxy Service or a Dynamic Business Service was easy in Oracle Service bus and i think everyone using OSB would know about it.

Ever wondered how can your OSB code dynamically invoke a Xquery? Not much difficult. Here is an example to illustrate it.

Let us assume that you have three different XQ’s and depending upon the content you would like one of them to be picked.

Create a RoutingRule xml file and create an entry for these Xqueries. Here is how you can do that

——————————————————————————————————————————————–

<Rules>

<Operations>
<Operation Name=”Operation1″>
<RoutingRules>
<RoutingRule>
<Transformation>
<XQ Name=”Case1_XQ”/>
</Transformation>
</RoutingRule>
</RoutingRules>
</Operation>

<Operation Name=”Operation2″>
<RoutingRules>
<RoutingRule>
<Transformation>
<XQ Name=”Case2_XQ”/>
</Transformation>
</RoutingRule>
</RoutingRules>
</Operation>

<Operation Name=”Operation3″>
<RoutingRules>
<RoutingRule>
<Transformation>
<XQ Name=”Case3_XQ”/>
</Transformation>
</RoutingRule>
</RoutingRules>
</Operation>

<RoutingServices>
<RoutingXQ Name=”Case1_XQ”>
<Address>#ProjectName/#FolderName1/#XqueryName1</Address>
</RoutingXQ>
<RoutingXQ Name=”Case2_XQ”>
<Address>#ProjectName/#FolderName2/#XqueryName2</Address>
</RoutingXQ>
<RoutingXQ Name=”Case3_XQ”>
<Address>#ProjectName/#FolderName3/#XqueryName3</Address>
</RoutingXQ>
</RoutingServices>

</Rules>

——————————————————————————————————————————————–

Now assign this XML file to a variable in OSB. Let us call it routingRules. Let us also suppose that we would like to do a tranformation based on operations. The input to each of the XQ’s is same but depending upon the operation the transformtion would vary.

Write a Xquery to get the source XQ based on the operation and routingRules variable. Here is a sample.

——————————————————————————————————————————————–

xquery version “1.0” encoding “Cp1252″;
(:: pragma  parameter=”$Rules” type=”xs:anyType” ::)
(:: pragma  parameter=”$Operation” type=”xs:anyType” ::)
(:: pragma  type=”xs:string” ::)
declare namespace xf = “http://tempuri.org/Examples/GetRoutingXQ&#8221;;
declare function xf:getServicesXQ($Rules as element(*), $Operation as xs:string)
as xs:string {
let $Result := for $Rule in $Rules//Operations/Operation[@Name= $Operation]/RoutingRules/*
let $TransXQOperation:= $Rule/Transformation/XQ/@Name
for $RoutingAddress in $Rules//RoutingServices/RoutingXQ[@Name = $TransXQOperation]/Address
return $RoutingAddress
return data($Result)
};
declare variable $Rules as element(*) external;
declare variable $Operation as xs:string external;
xf:getServicesXQ($Rules,$Operation)

——————————————————————————————————————————————–

Assign this Xquery by passing the Rules XML and the operation to a variable, say “dynaXQ”.

Now create a normal assign Action in the OSB and click on Dynamic Xquery. Configure the Dynamic Xquery as shown below:

DynamicXQ

where $variable1 and $variable2 are inputs required for the actual Xquery.

So go ahead and add more dynamics to OSB development.

11 thoughts on “Dynamic XQuery in Oracle Service Bus

      • Hi Arun,thanks for reply,i have a requirement like three different format requests converted into one standard format.For this i create three X-queries,but i don’t now how to set condition.In this example you are write a routing rules for the dynamic routing.Please give some more clarification how to write the routing rules for this scenario.Thanks in advance.
        Rohit

        Like

  1. Hi Arun I’m waiting for ur reply.I’m create XML file with ur sample code but I’m not able to assigning it to a variable in osb.

    Like

  2. Hi Arun Thx for ur reply, I’m directly creating the XML file in Eclipse with above sample code i.e Routing Rules XML,I’m try to assign it to the variable say routingRules,for this in take assign,in Expression only Xquery is available. How to make the XML to Xquery.Also I’m create the GetRoutingXQ Xquery and select it in another assign and creating the variable dynaXQ,at end I take replace and in Xpath .(body) and create variable body.In Expression selecting the DynamicXquery,and $dynaXQ in bindings I’m not getting the variables and bindings.In your example you are selecting the variable1 and variable2.Once again thanks…………Rohit.

    Like

If you have any comments, suggestions or feedback about the post, please feel free to type it here and I will do my best to address them asap

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s