Dynamic Routing in OSB can be used when we want to determine the business service at runtime in the message flow. To store the information about the business services that can be used, we can use XQuery resource.
Consider a scenario where OSB has to route the incoming requests to 2 different services based on the CustomerType element value sent in the payload. So create a XQuery resource with the following contents. Observe that we are using the absolute path of business service in configuration as required by dynamic routing.
<Configuration>
<CustomerType value =’Privileged’>
<Service>DynamicRoute/BSSystem1</Service>
</CustomerType>
<CustomerType value =’Ordinary’>
<Service>DynamicRoute/BSSystem2</Service>
</CustomerType>
</Configuration>
Following is the XML schema that we use.
<xsd:schema targetNamespace=”http://xmlns.oracle.com/schema/Customer”
xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:ns1=”http://xmlns.oracle.com/schema/Customer”>
<xsd:complexType name=”Customer”>
<xsd:sequence>
<xsd:element name=”CustomerId” type=”xsd:string” />
<xsd:element name=”FirstName” type=”xsd:string” />
<xsd:element name=”LastName” type=”xsd:string” />
<xsd:element name=”MiddleName” minOccurs=”0″ type=”xsd:string” />
<xsd:element name=”CustomerType” type=”xsd:string” />
<xsd:element name=”Email” minOccurs=”0″ type=”xsd:string” />
<xsd:element name=”Mobile” minOccurs=”0″ type=”xsd:string” />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name=”StatusMsg”>
<xsd:sequence>
<xsd:element name=”CustomerId” type=”xsd:string” />
<xsd:element name=”Response” type=”xsd:string” />
<xsd:element name=”ErrorCode” type=”xsd:string” minOccurs=”0″/>
<xsd:element name=”ErrorMessage” type=”xsd:string” />
</xsd:sequence>
</xsd:complexType>
<xsd:element name=”Customer” type=”ns1:Customer” />
<xsd:element name=”StatusMsg” type=”ns1:StatusMsg” />
</xsd:schema>
Following is the WSDL that we will use for the proxy service:
<wsdl:definitions name=”CustomerService”
targetNamespace=”http://xmlns.oracle.com/wsdl/CustomerService” xmlns:wsdl=”http://schemas.xmlsoap.org/wsdl/”
xmlns:ns1=”http://xmlns.oracle.com/schema/Customer” xmlns:xsd=”http://www.w3.org/2001/XMLSchema”
xmlns:tns=”http://xmlns.oracle.com/wsdl/CustomerService” xmlns:soap=”http://schemas.xmlsoap.org/wsdl/soap/”>
<wsdl:types>
<xsd:schema>
<xsd:import namespace=”http://xmlns.oracle.com/schema/Customer”
schemaLocation=”Customer.xsd” />
</xsd:schema>
</wsdl:types>
<wsdl:message name=”CustomerCreate”>
<wsdl:part name=”parameters” element=”ns1:Customer” />
</wsdl:message>
<wsdl:message name=”CustomerCreateResponse”>
<wsdl:part name=”parameters” element=”ns1:StatusMsg” />
</wsdl:message>
<wsdl:portType name=”CustomerServicePort”>
<wsdl:operation name=”CustomerCreate”>
<wsdl:input message=”tns:CustomerCreate” />
<wsdl:output message=”tns:CustomerCreateResponse” />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name=”CustomerServiceBinding” type=”tns:CustomerServicePort”>
<soap:binding style=”document”
transport=”http://schemas.xmlsoap.org/soap/http” />
<wsdl:operation name=”CustomerCreate”>
<soap:operation soapAction=”CustomerCreate” />
<wsdl:input>
<soap:body use=”literal” />
</wsdl:input>
<wsdl:output>
<soap:body use=”literal” />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
</wsdl:definitions>
Create the required resources a proxy service based on the above WSDL, 2 business services and a XQuery resource with the contents shown above.
Create the message flow as shown below.
The first assign activity loads the XQuery resource and stores the contents of the file in variable ‘varConfig’. The second assign activity stores the value of customer type element in the payload in ‘varType’ variable using the xpath expression $body/cus:Customer/CustomerType/text().
For the dynamic routing the expression should resolve to the following XML snippet. The attribute isProxy has to be set to ‘true’ if routing the request to proxy service or ‘false’ if routing the request to business service. Operation name is optional as business service might not be WSDL service always.
<ctx:route>
<ctx:service isProxy=’false’>absolute path of business service</ctx:service>
<ctx:operation>operation name</ctx:operation>
</ctx:route>
So for our case use the XML contents as shown in the below screenshot along with the XPath expressions to get the required values.
Deploy the configuration jar and test it from test console to verify its working as expected.
The sample jar can be download from the following location.
Hi shiva,
Thanks for great blog,can you please email me the source the project or jar file to mail Id jesus.orellana.lopez@gmail.com. I appreciate it.
Thanks
Jesus O.
you can get it from the link https://drive.google.com/open?id=0B-JxCNrHSh7yM25GU2NhNEsyX0U
Hi.
How different is it if instead of doing this way, we use routing options in request action of routing, and pass the URL as $URI. That way also, the URL will be decided at run time only based on the customer type input.
If we create an Xquery, and use dvm look up function to fetch the url and store that url in $uri variable and instead pass that variable in routing options, that way also dynamic routing could be achieved.
could you please confirm if my conceptualization is correct in this regard.
you can do as you mentioned too. I think only difference is scalability.
Hi Shiva ,i have a question on dynamic routing,
How to handle if customer type is not generating in incoming XML request.
as per the example we have only 2 destinations based on
CustomerType value =’Ordinary’>
Scenario:
If CustomerType value is null how to handle
Its something like default routing..if we don’t have that CustomerType should always be mandatory.
Hi shiva,
We also did route to different business service based on the value in the xml message received at the source. But in our case we did it using if-else conditions in the message flow like fetching the value from xml and assigning it to the xquery gving in the if statement (ex: if($body/Configuration/CustomerType/Service/text() = ‘DynamicRoute/BSSystem1’). Can u please tell me what make this dynamic routing action better than using if-else condition. OSB is new to me, as far i see both way it does dynamic routing to business services based on a value in the incoming message. please light up the advantage of using dynamic routing action in any terms.
One of the advantages is the scalability of the approach when multiple business services are there and how fast you can make the changes. Since the configuration file xml based, we can automate the generation of it using scripts in cases where we have no.of business services.
Thanks so much for this very useful blog.
I am getting the following error while trying this example:
“Tried all: ‘2’ addresses, but could not connect over HTTP to server: ‘localhost’, port: ‘8088’”
Here is the payload I passed in:
1
John
Doe
Nathan
Ordinary
xyz@gmail.com
9999999999
Do I have to change the port in the CustomerService.wsdl?
Thanks.
Make sure that service accessible at that location..otherwise use soap mock service..
Hi Siva, Thanks for your explanation. I’m facing issue to download the .jar file. can you please send me to sarathkumar71@gmail.com
Thanks In Advance
Hi Shiva,
WIth your code only i understood the Dynamic Routing functionality.
Thank you very much :)
regards,
KiranKumarReddy.B
09037094569.
Hi Shiva,
Thanks for this detailed explanation. But i am finding some difficuilties while implementing . Could you please send me the jar file for reference?
The post also have a download link to get the sample jar. Let me know if you see any issues in downloading the same.
Hi,
You have detials very well explained, but still I have query in my mind
All the things what you told can also be implemented using Routing Table right ?
For example:
—————
Xpath/CustomerType=Privilege
then route to BSS1
Xpath/CustomerType=Ordinary
then route to BSS2
In this case ,What makes Dynamic Routing to service unique from Routing Table.
Moreover you have a xquery file which is static. I dint find any dymaic routing here.
Please excuse me if I am wrong and I am new to OSB.
What do you expect from the word dynamic? Are you expecting command line entry by the user. OSB proxy dynamically determines the business service to be called.
Hi Shiva,
Since i’m new to OSB got nice ideas through this post… Thank you so much… Can u mail me the configuration jar file so that i can get obvious result. My mail id: dineshayya@gmail.com
Thanks & Regards,
Dinesh Ayyapillai
the jar file has been given in the link..try out and let me know if you could download the same.
Hi Shiva,
Nice Tutorial !! can you please send the jar file to lovesaiju@gmail.com
sent the jar file to ur mail id.
hi can you sent me jar file to ashvin_mbm2006@yahoo.co.in
Hi shiva, Nice work man.. Can u please send me the jar to my email: sugumarayyadhurai@gmail.com.
Hi Sir, i have a small doubt on this scenario ( in OSB PROJECT)let supose ,,
i am taking request from source its a collection of data like files. next i can transform to target streams like in data telugu file is the send to telugu stream if hindi file is the send to hindi stream . so now my question is how we can write code for this in Xquery
Do you have separate Xquery transformations for both the streams? If you have only 1 or 2 cases you can go for conditional branch directly. If you see more cases like this go for dynamic routing as explained in the post.
Hi Shiva,
Can you please send me the jar file to my mail Id:
vishnu.reddy004@gmail.com
Hi Siva, If there is an error in one business service, i want to try other business service automatically without being communicate to the requester. The requirement is that the requester need not know which business service has provided the response.
Hi, If that is the case you can actually call another business service from the exception handler when you get the error on first business service. You can create exception handlers on routing node or pipeline pair node.
Hi shiva,
Thanks… Can you please send me the jar file to my mail Id: neha5v31@gmail.com
good example but the code would help e lot…could you please or somebody send me the code?
alvarogrm@gmail.com
Hi shiva,
I am looking for dynamic routing and dynamic publish good tutorial for a long,These blog is really help me a lot to understand.
I appreciate your effort and time to blogging it
Could you please send me the jar file to souvik06@gmail.com
Thanks
Souvik
Shiva
That was a realy nice example! Can I get a copy of the jar?
my email is jili115@yahoo.com
Thanks!
Hi shiva,
Thanks for great blog,can you please email me the source the project or jar file to mail Id kiran.chalasani@yahoo.com. I appreciate it.
Thanks
Kiran
Sent you the jar to ur mail id as unable to upload to the blog..
Hi there.. great example, any chance i could have the source for this project ?
Thanks
Could also pls send me the jar file at : vikmaar@gmail.com
Hi shiva,
I tried with simple Helloworld business and NoHelloworld business services deployed in SOA and imported into Eclipse and I follow the the remaining as article.
When I testing I got error like
The invocation resulted in an error: .
soapenv:Server
BEA-382612: Error preparing message for dispatch
BEA-382612
Error preparing message for dispatch
RouteNode1
request-pipeline
My Query is in your sample your are using same WSDL for BS & PS,for different wsdl (BS) how to call in DyamicRouting.
Can you please any suggestions.
Thanks
Mani
Hi shiva,
Thanks for sending the jar.How to create the xQuery transformation with the sample code,when creating the xQuery,what should I select on the source and target,in your Xquery,there is no source and target.
Thanks
Mani
Hi shiva,
Thanks for nice blog,can you please post the jar file of the project or else can you send it to mail Id mani.pala744@gmail.com
sent you in the mail.
this blog is great can u please send the jar file to jayanth.512@gmail.com
can u please send me this project, i just started learning OSB. It will be helpful..Thank in Advance..
You should be able to download using url https://drive.google.com/open?id=0B-JxCNrHSh7yM25GU2NhNEsyX0U