Posts Tagged 'dynamic routing'

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.


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

Join 380 other followers

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

%d bloggers like this: