Dynamic Routing in OSB or How to invoke a webservice which has multiple endpoint URI’s from OSB

I want to be able to accept an input of country code, and based on that input, route to one of the three services

I want to be able to add additional endpoints without having to change the code.

For example, if I submit this payload with an input of “EU”, I expect it to route to the second web service on the list above:

<soapenv:Envelope
xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/&#8221;
xmlns:hel=”http://xmlns.oracle.com/SOA11g/HelloWorld/HelloWorld”&gt;
<soapenv:Header/>
<soapenv:Body>
<hel:process>
<hel:input>EU</hel:input>
</hel:process>
</soapenv:Body>
</soapenv:Envelope>

Steps:

Create an XML file called HelloWorldMap.xml with the following contents (using the endpoint, not WSDL). This is essentially an XML Resource which maps the country code to the endpoint.

Enter a New Project Name (e.g., HelloWorldDynamicRouting) and click Add ProjectClick on HelloWorldDynamicRouting

Create Resource of type XQuery, and browse for and import the XML file (e.g., HelloWorldMap.xml)

This file is the mapping between country code and endpoint.

Create Resource of type Resources from URL and enter one of the WSDLs up top and enter a Resource Name

This is used as the WSDL for my business service. Essentially, you will have only 1 business service in the entire project, regardless of how many actual endpoints may exist. This WSDL is also used as the interface for my proxy service.

Create Resource of type Proxy Service, give it a name (e.g., HelloWorldPS), and browse for and import the WSDL Web Service that was just imported in the step above
Create Resource of type Business Service, give it a name (e.g., HelloWorldBS), and browse for and import theWSDL Web Service in the project

Edit Message Flow of the proxy service and Add Pipeline Pair

In the Request Pipeline, Add Stage then Edit Stage

Add an  Assign action

Click on Expression

Click on XQuery Resources

Browse for and select the XML Resource (e.g., HelloWorldMap)

Save this and assign this to the variable MyMap

Add 2 more actions, with the expression and variable as follows:

Expression:    $body/hel:process/hel:input
Variable:        MyInput

Expression:    $MyMap/row[country/text()=$MyInput]/endpoint/text()
Variable:        MyMapResult

Your stage should now look like this:

Click on your pipeline pair and Add Route > Edit Route > Add an Action > Communication > Routing

Click on Service and choose the business service (e.g., HelloWorldBS) and operation

Under Request Actions, Add an Action > Communication > Routing Options and enter a URI expression as$MyMapResult

Now you are ready to test your service.

Advertisements

2 thoughts on “Dynamic Routing in OSB or How to invoke a webservice which has multiple endpoint URI’s from OSB

  1. This sample is correct, but how can i change the urls between development environment and production environment? these urls will be different and they don´t appears in the “customization file”

    Like

  2. In this approach all the URL’s are hard coded and we can retrieve those values from the xml file based on the input value. If your input contains the value related to Production then it will retrieve the production URL.

    Like

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