OSB Dynamic Routing

OSB can do dynamic routing based on the abstract wsdl which means that any proxy or business service that is based on the same abstract wsdl can be used included in the set of dynamic routes.

As for example, if there are two business services eg. MultipleOperationsViaBranching and ServiceCalloutsWithErrorHandling that are each based on the same interface, we can use dynamic routing.

The core of this feature is built on the following XML element:

<ctx:route>
<ctx:service isProxy=”true|false”>{$proxy|$businessService}</ctx:service>
<!– Optional : –>
<ctx:operation>OperationName</ctx:operation>
</ctx:route>

The isProxy is true or false according to whether the dynamic route is to a Proxy Service or to a business Service.
I have no idea why it has to be either a proxy or a business service. There can be cases where we might actually need both.

Anyways, the way to go is to put the above element in the expression of a dynamic routing action inside a route node, etc.
As for eg.

<ctx:route>
<ctx:service isProxy=”false”>ServiceCalloutTest/BusinessService1</ctx:service>
</ctx:route>

Case1:

The portion denoted by ServiceCalloutTest/BusinessService1 is hardcoded for simplicity.
The same can be achived at runtime by using XQuery expressions to evaluate the input to the ProxyService.

The benefit, XQuery resources are easy to maintain. And any new business or proxy service routings can be added on the fly.

Case 2:

Now, then, lets move to a little advanced  version. In this new Dynamic Routing example, we will use an XQuery Resource as a holder for all the Dynamic Proxy Services based on the same abstract wsdl. We will then use XQuery assigns in the Dynamic Proxy Service to find a suitable Proxy based on the input. The main benefit of this sample being that we can add additional dynamic services to the Proxy Service by a simple edit of the XQuery Resource.

The flow is shown below:

The XQuery Resource used as a Routing Table is as follows:

The CopyRoutingTable stage copies the above XQueryResource into a variable called RoutingTable. This is achieved by just pointing the above XQueryResource file in the XQuery expression window.

The GetLogicalName stage then copies the Proxy Service input to the variable LogicalName.

Finally, the GetPhysicalService stage creates the Dynamic Routing XQuery into the variable PhysicalService via the expression:

The next action is a Dynamic Routing with the $PhysicalService in the Service expression.

The good thing about this setup is that it allows us to add or remove Dynamic Proxy Services in the XQueryResource and also change the logic of mapping the Logical to the Physical Service without having to change the Dynamic Proxy Service itself.

Case 3:

The above samples have not used the Operation setting for the dynamic endpoint.

Let us take a more concrete use case. Dynamic Endpoint definitions are maintained in an XQuery Resource Map as before. The user can select which service he wants to invoke based on the input. In addition, the user also specifies the operation and messages to be exchanged.  The OSB Dynamic Proxy takes the input, maps to a Physical Service and invokes it.

The XQuery Resource for the Routing Map is now changed to:

<Services>
<Service>
<logical>Service1</logical>
<physical>ServiceCalloutTest/ProxyService1</physical>
<isProxy>true</isProxy>
</Service>
<Service>
<logical>Service2</logical>
<physical>ServiceCalloutsWithErrorHandling/ProxyServices/ProxyService1</physical>
<isProxy>true</isProxy>
</Service>
</Services>

The above config contains two endpoints viz. ServiceCalloutTest/ProxyService1 and ServiceCalloutsWithErrorHandling/ProxyServices/ProxyService1 each of which is based on the same abstract wsdl and exposes operations viz. getGreeting(String name) and getCurrentGreeting(). These methods are implemented differently.

The Dynamic Proxy service is designed to accept any WSDL with SOAP 1.1.  The input looks like below:

<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<soap:Header xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
</soap:Header>
<soapenv:Body>
<ds:DynamicRoute xmlns:ds=”http://www.osbLabs.DynamicProxy”&gt;
<Service>Service1</Service>
<osb:getGreeting xmlns:osb=”http://www.osbLabs.WebServices”&gt;
<!–Optional:–>
<arg0>Sandeep</arg0>
</osb:getGreeting>
</ds:DynamicRoute>
</soapenv:Body>
</soapenv:Envelope>

The Service element is a direct logical reference to the Service element in the XQuery Resource Routing Map.
This is followed by the operation to be invoked and the relevant arguments. This makes sure operations can be invoked dynamically as well.

Another input with an operation getCurrentGreeting is shown below:

<soapenv:Envelope      xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<soap:Header      xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
</soap:Header>
<soapenv:Body>
<ds:DynamicRoute      xmlns:ds=”http://www.osbLabs.DynamicProxy”&gt;
<Service>Service1</Service>
<osb:getCurrentGreeting xmlns:osb=”http://www.osbLabs.WebServices”&gt;
</osb:getCurrentGreeting>
</ds:DynamicRoute>
</soapenv:Body>
</soapenv:Envelope>

The flow below shows the Dynamic Proxy Service:

The flow shows a series of assigns. Let me break it down bit by bit:

Heres a sample run:

Input1:

<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<soap:Header xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
</soap:Header>
<soapenv:Body>
<ds:DynamicRoute xmlns:ds=”http://www.osbLabs.DynamicProxy”&gt;
<Service>Service1</Service>
<osb:getGreeting xmlns:osb=”http://www.osbLabs.WebServices”&gt;
<!–Optional:–>
<arg0>Sandeep</arg0>
</osb:getGreeting>
</ds:DynamicRoute>
</soapenv:Body>
</soapenv:Envelope>

Output from Service1 on operation getGreeting:

<soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/&#8221;>
<soapenv:Header/>
<S:Body xmlns:S=http://schemas.xmlsoap.org/soap/envelope/&#8221;>
<ns2:getGreetingResponse xmlns:ns2=http://www.osbLabs.WebServices&#8221;>
<return>How are you Sandeep</return>
</ns2:getGreetingResponse>
</S:Body>
</soapenv:Envelope>

Input2:

<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<soap:Header xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
</soap:Header>
<soapenv:Body>
<ds:DynamicRoute xmlns:ds=”http://www.osbLabs.DynamicProxy”&gt;
<Service>Service2</Service>
<osb:getGreeting xmlns:osb=”http://www.osbLabs.WebServices”&gt;
<!–Optional:–>
<arg0>Sandeep</arg0>
</osb:getGreeting>
</ds:DynamicRoute>
</soapenv:Body>
</soapenv:Envelope>

Output from Service2 on operation getGreeting:

<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<soapenv:Header/>
<S:Body      xmlns:S=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<ns2:getGreetingResponse      xmlns:ns2=”http://www.osbLabs.WebServices”&gt;
<return>Hola! Sandeep</return>
</ns2:getGreetingResponse>
</S:Body>
</soapenv:Envelope>

Input 3:

<soapenv:Envelope      xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<soap:Header      xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
</soap:Header>
<soapenv:Body>
<ds:DynamicRoute  xmlns:ds=”http://www.osbLabs.DynamicProxy”&gt;
<Service>Service2</Service>
<osb:getCurrentGreeting xmlns:osb=”http://www.osbLabs.WebServices”/&gt;
</ds:DynamicRoute>
</soapenv:Body>
</soapenv:Envelope>

Output from Service2 on operation getCurrentGreeting:

<soapenv:Envelope      xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<soapenv:Header/>
<S:Body      xmlns:S=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<ns2:getCurrentGreetingResponse      xmlns:ns2=”http://www.osbLabs.WebServices”&gt;
<return>Hola!</return>
</ns2:getCurrentGreetingResponse>
</S:Body>
</soapenv:Envelope>

Input4:

<soapenv:Envelope      xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<soap:Header      xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
</soap:Header>
<soapenv:Body>
<ds:DynamicRoute  xmlns:ds=”http://www.osbLabs.DynamicProxy”&gt;
<Service>Service1</Service>
<osb:getCurrentGreeting xmlns:osb=”http://www.osbLabs.WebServices”/&gt;
</ds:DynamicRoute>
</soapenv:Body>
</soapenv:Envelope>

Output from Service1 on operation getCurrentGreeting:

<soapenv:Envelope      xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<soapenv:Header/>
<S:Body      xmlns:S=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<ns2:getCurrentGreetingResponse      xmlns:ns2=”http://www.osbLabs.WebServices”&gt;
<return>How are you</return>
</ns2:getCurrentGreetingResponse>
</S:Body>
</soapenv:Envelope>

The above examples shows how easy it is to get OSB dynamic routing up and running quickly. This can serve as a good use case for complicated Proxy Services that does a lot of processing. When new endpoints arrive, the code is left untouched and the new service can be added directly in the XQuery resource.

About these ads
Comments
9 Responses to “OSB Dynamic Routing”
  1. mani says:

    Hi sandeep,
    Hi shiva,
    Thanks for nice blog,can you please post the jar file of the project .

  2. Steve says:

    Sandeep, Can you please upload the source code for this sample.

  3. jayanth says:

    can you please send me this project jar file to jayanth.512@gmail.com

  4. souvik says:

    Hi,
    I am looking for dynamic routing and dynamic publish good tutorial for a long,These blog is really help me a lot to understand.
    can you please send me this dynamic routing jar file to souvik06@gmail.com

  5. SJ says:

    Sandeep, can you please send the source code for dynamic routing example ?

  6. Swapnil says:

    Hi Shiva, when I do above and passed following expression to my Dynamic Routing action code-
    {$bsName}
    {$operation}
    what error i get is

    BEA-382510

    OSB Assign action failed updating variable “body”: com.bea.wli.common.xquery.XQueryException: Error parsing XML: {err}FORG0005: expected exactly one item, got 0 items

    request-pipeline
    true

    I guess body is not passed to service. Can you please help? What am I missing here!

Leave a Reply

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: