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
<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:
- Dynamic Routing will call "DetermineCustomerEndpoint".
- "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.
- "DetermineCustomerEndpoint" will call function "selectBusinessService" where it will send CustomerType as in variable "$customer".
- "selectBusinessService" will execute and call another xquery function "checkDefault".
- "checkDefault" function will validate value of "$customer", whether it is "A" or "B".
- In "checkDefault" function, Based on input values Mapping XML will execute and business service absolute path will be return.
- Same business service path will be executed.
You can deploy and test it over OSB console.
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
ReplyDeleteGood article, thanks for sharing this information.
ReplyDeleteOracle Fusion HCM Techno Functional Online Training
Thanks for Sharing this OSB online training ORACLE is most useful
ReplyDeleteOracle OSB Training
Thank you for sharing this Valuable information of this OSB.
ReplyDeleteOracle OSB Training OSB Online Training Hyderabad OSB Online Training India
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.
ReplyDeleteIam 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.
ReplyDeleteThose 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.
ReplyDeleteI 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.
ReplyDeleteAppreciate you sharing, great article.Much thanks again. Really Cool.
ReplyDeletejava training
salesforce training
hadoop training
mulesoft training
linux training
mulesoft training
Thank you so much for providing information and throwing light on the most useful and important topics.
ReplyDeleteInformatica Read Rest Api
Thank you for sharing wonderful information with us to get some idea about it.
ReplyDeleteOracle OSB Training
OSB Online Training Hyderabad
osb certification training
soa training
Thank you for taking the time to write this blog. Your interest and attention are greatly appreciated! managed hosting service providers
ReplyDeleteVery well written Blog remote infrastructure management services
ReplyDeleteNice Blog email hosting providers
ReplyDeleteHi , i am using same detail sto print log but getting below error please let me know where i am missing .
ReplyDeletelog4j:ERROR Could not parse file [null].
java.lang.NullPointerException
Thank You and I have a tremendous present: Full House Reno whole home remodel cost
ReplyDelete