Using Dynamic Routing in OSB

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.

image

Create the message flow as shown below.

image

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.

image

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.

Advertisement

42 Responses to “Using Dynamic Routing in OSB”


  1. 1 Anonymous November 23, 2019 at 2:32 AM

    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.

  2. 3 jaspreet January 22, 2017 at 4:22 PM

    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.

  3. 5 sid May 27, 2016 at 9:43 PM

    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

  4. 7 Anto March 15, 2016 at 5:31 PM

    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.

    • 8 svgonugu March 17, 2016 at 11:21 AM

      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.

  5. 9 Dan August 6, 2014 at 7:27 PM

    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.

  6. 11 Sarath May 19, 2014 at 6:05 PM

    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

  7. 12 Anonymous January 10, 2014 at 8:05 PM

    Hi Shiva,

    WIth your code only i understood the Dynamic Routing functionality.
    Thank you very much :)

    regards,
    KiranKumarReddy.B
    09037094569.

  8. 13 Saurabh March 9, 2013 at 7:56 PM

    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?

  9. 15 Naveen M December 19, 2012 at 12:49 PM

    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.

  10. 17 Dinesh Ayyapillai September 18, 2012 at 11:41 AM

    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

  11. 19 SJ August 23, 2012 at 6:45 PM

    Hi Shiva,
    Nice Tutorial !! can you please send the jar file to lovesaiju@gmail.com

  12. 21 Anonymous August 22, 2012 at 3:12 PM

    hi can you sent me jar file to ashvin_mbm2006@yahoo.co.in

  13. 22 Anonymous August 6, 2012 at 6:48 PM

    Hi shiva, Nice work man.. Can u please send me the jar to my email: sugumarayyadhurai@gmail.com.

  14. 23 kumar August 6, 2012 at 1:09 PM

    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

    • 24 svgonugu August 8, 2012 at 11:20 AM

      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.

  15. 25 vishnu August 2, 2012 at 9:18 PM

    Hi Shiva,
    Can you please send me the jar file to my mail Id:
    vishnu.reddy004@gmail.com

  16. 26 Rajesh July 17, 2012 at 1:18 AM

    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.

    • 27 svgonugu July 17, 2012 at 10:31 AM

      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.

  17. 28 Neha Varghese June 26, 2012 at 2:01 PM

    Hi shiva,
    Thanks… Can you please send me the jar file to my mail Id: neha5v31@gmail.com

  18. 29 Alvaro Ruiibo May 21, 2012 at 7:55 PM

    good example but the code would help e lot…could you please or somebody send me the code?
    alvarogrm@gmail.com

  19. 30 souvik May 20, 2012 at 9:59 AM

    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

  20. 31 JI April 25, 2012 at 5:22 AM

    Shiva

    That was a realy nice example! Can I get a copy of the jar?
    my email is jili115@yahoo.com
    Thanks!

  21. 32 kiran chalasani March 28, 2012 at 10:43 AM

    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

  22. 34 Ebe January 19, 2012 at 6:35 PM

    Hi there.. great example, any chance i could have the source for this project ?
    Thanks

  23. 35 Vikash January 4, 2012 at 12:19 PM

    Could also pls send me the jar file at : vikmaar@gmail.com

  24. 36 mani December 15, 2011 at 6:34 PM

    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

  25. 37 mani December 15, 2011 at 3:35 PM

    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

  26. 38 mani December 14, 2011 at 5:37 PM

    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


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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.




Pages

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 379 other subscribers

Enter your email address to follow this blog and receive notifications of new posts by email.


%d bloggers like this: