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.

<CustomerType value =’Privileged’>

<CustomerType value =’Ordinary’>

Following is the XML schema that we use.

<xsd:schema targetNamespace=””
    xmlns:xsd=”” xmlns:ns1=””>

    <xsd:complexType name=”Customer”>
<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:complexType name=”StatusMsg”>
<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:element name=”Customer” type=”ns1:Customer” />
<xsd:element name=”StatusMsg” type=”ns1:StatusMsg” />

Following is the WSDL that we will use for the proxy service:

<wsdl:definitions name=”CustomerService”
targetNamespace=””         xmlns:wsdl=””
    xmlns:ns1=”” xmlns:xsd=””
    xmlns:tns=”” xmlns:soap=””>
<xsd:import namespace=””
                schemaLocation=”Customer.xsd” />

    <wsdl:message name=”CustomerCreate”>
<wsdl:part name=”parameters” element=”ns1:Customer” />
<wsdl:message name=”CustomerCreateResponse”>
<wsdl:part name=”parameters” element=”ns1:StatusMsg” />

    <wsdl:portType name=”CustomerServicePort”>
<wsdl:operation name=”CustomerCreate”>
<wsdl:input message=”tns:CustomerCreate” />
<wsdl:output message=”tns:CustomerCreateResponse” />

    <wsdl:binding name=”CustomerServiceBinding” type=”tns:CustomerServicePort”>
<soap:binding style=”document”
transport=”” />

        <wsdl:operation name=”CustomerCreate”>
<soap:operation soapAction=”CustomerCreate” />
<soap:body use=”literal” />
<soap:body use=”literal” />

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:service isProxy=’false’>absolute path of business service</ctx:service>
<ctx:operation>operation name</ctx:operation>

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.


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 I appreciate it.


    Jesus O.

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


    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’>


    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:




    Do I have to change the port in the CustomerService.wsdl?


  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

    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 :)


  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

    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:
    then route to BSS1
    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:

    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

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

    hi can you sent me jar file to

  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:

  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:

  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:

  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?

  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


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


    That was a realy nice example! Can I get a copy of the jar?
    my email is

  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 I appreciate it.



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

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

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

    Could also pls send me the jar file at :

  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: .


    BEA-382612: Error preparing message for dispatch

    Error preparing message for dispatch


    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.


  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.


  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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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.


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: