Skip to main content

Dynamic Routing in OSB 12C

Dynamic Routing in OSB cab be used when the BusinessService endpoint required to be determine at runtime in message flow.

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.

Following is the XML schema that we use:>> Customer.xsd
<?xml version="1.0" encoding="windows-1252" ?>

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



x

Following is the WSDL that we will use for the proxy service >> CustomerService.wsdl


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


OSB project configuration:

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

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



Second implementation:
you can write some thing like with help of XQEURY file:
xquery version "1.0" encoding "utf-8";

(:: OracleAnnotationVersion "1.0" ::)


(:: pragma  type="ctx:route" ::)

declare namespace xf = "http://www.rubix.nl/test/routingexample/";
declare namespace ctx = "http://www.bea.com/wli/sb/context";

declare function xf:mapping ()
    as element(*) {
    <mappings>
        <mapping>
            <Customer>A</Customer>
            <Service>CustomerService/business/CustomerServiceA</Service>
        </mapping>
        <mapping>
            <Customer>B</Customer>
            <Service>CustomerService/business/CustomerServiceB</Service>
        </mapping>
    </mappings>
};

declare function xf:checkDefault($value as xs:string*)
    as xs:string {
    if (exists($value))
    then $value
    else xf:mapping()/mapping[Customer="A"]/Service/text()
};

declare function xf:selectBusinessService($customer as xs:string)
    as xs:string {
    xf:checkDefault(xf:mapping()/mapping[Customer=$customer]/Service/text())
};

declare function xf:DetermineCustomerEndpoint($customer as xs:string)
    as element(*) {
    <ctx:route>
        <ctx:service isProxy="false">{ xf:selectBusinessService($customer) }</ctx:service>
        <ctx:operation>Order</ctx:operation>
    </ctx:route>
};

declare variable $customer as xs:string external;

xf:DetermineCustomerEndpoint($customer)


With this custom XQUERY file, A Xquery function "DetermineCustomerEndpoint" will be called where it will do following tasks:

  1. Dynamic Routing will call "DetermineCustomerEndpoint".
  2. "DetermineCustomerEndpoint" will check whether proxy services will be called or business service be called, This condition with be decided based on "True"/"False" of isProxy.
  3. "DetermineCustomerEndpoint" will call function "selectBusinessService" where it will send CustomerType as in variable "$customer".
  4. "selectBusinessService" will execute and call another xquery function "checkDefault".
  5. "checkDefault" function will validate value of "$customer", whether it is "A" or "B".
  6. In "checkDefault" function, Based on input values Mapping XML will execute and business service absolute path will be return.
  7. Same business service path will be executed.
You can deploy and test it over OSB console.

Comments

  1. Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles.Oracle OSB Online Training

    ReplyDelete
  2. Thanks for Sharing this OSB online training ORACLE is most useful
    Oracle OSB Training

    ReplyDelete
  3. Iam so thrilled because of finding your alluring website here.Actually i was searching for Oracle Fusion HCM Techno Functional.Your blog is so astounding and informative too..Iam very happy to find such a creative blog. Iam also find another one by mistake while am searching the same topic Oracle PPM Cloud.Thank you soo much.

    ReplyDelete
  4. Iam so thrilled because of finding your alluring website here.Actually i was searching for Oracle Fusion HCM Techno Functional.Your blog is so astounding and informative too..Iam very happy to find such a creative blog. Iam also find another one by mistake while am searching the same topic Oracle PPM Cloud.Thank you soo much.

    ReplyDelete
  5. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp a great deal more around this condition. and I could assume you are an expert on this subject. Same as your blog i found another one Oracle Taleo .Actually I was looking for the same information on internet for Oracle Taleo and came across your blog. I am impressed by the information that you have on this blog. Thanks a million and please keep up the gratifying work.

    ReplyDelete
  6. I wish to show thanks to you just for bailing me out of this particular trouble. As a result of checking through the net and meeting techniques that were not productive, Same as your blog I found another one Oracle OSB 12c.Actually I was looking for the same information on internet for Oracle OSB 12c and came across your blog. I am impressed by the information that you have on this blog. Thanks once more for all the details.

    ReplyDelete
  7. Thank you so much for providing information and throwing light on the most useful and important topics.

    Informatica Read Rest Api

    ReplyDelete
  8. Thank you for taking the time to write this blog. Your interest and attention are greatly appreciated! managed hosting service providers

    ReplyDelete

Post a Comment

Popular posts from this blog

Oracle SOA 12C rest adapter with Custom HTTP headers

Most existing web applications are connected through web services, which are commonly known as SOAP services. More and more users are relying on mobile devices for communication, and they’re looking for lighter ways to access enterprise information on the go. REST services are the answer for the mobile device platform, because they get rapid responses and fast access to data. Oracle SOA Suite 12 c  provides a complete set of service infrastructure components for designing, deploying, and managing composite applications. Oracle SOA Suite 12 c  enables services to be created, managed, and orchestrated into composite applications and business processes. Some time we have need to send HTTP headers in REST service, In OSB we use header component and add what ever is needed but in oracle SOA 12C it's little bit different. Let see how we can do it. Create one SOA Application. Create one SOA Sample project inside SOA Application. Go to composite and drag drop REST adapt

Swagger API document from Any WADL & Schema in Oracle SOA

Hi everyone, Hope everyone is doing well these days, Recently i started a project work over how to generate swagger API document for your any REST API, In case if you don't know what is swagger please go and check " https://swagger.io/tools/swagger-editor/ ". It's a great and easy to use tool which will help to create user friendly, human readable form API documentation with extension for generating API client in different languages with capability of testing your API from same. What is swagger editor, Design, describe, and document your API on the first open source editor fully dedicated to OpenAPI-based APIs. The Swagger Editor is great for quickly getting started with the OpenAPI (formerly known as the Swagger Specification) specification, with support for Swagger 2.0 and OpenAPI 3.0.  What benefits you will get by using swagger, Runs Anywhere, The Editor works in any development environment, be it locally or in the web. Smart Feedback, Validate you