Conditional Branch in OSB
Conditional Branch:- It is used to route the incoming requests to different business services based on different conditions like equal to (=), not equal to (!=), less than (<), less than equal to(<=), greater than(>), greater than or equal to(>=).
If no any conditions satisfied then by default branch is executed.
Scenario:- Create a OSB service which will accept employee details, whose salary is greater than 30,000 he is eligible for Loan, whose salary is less than or equal to 30,000 he is not eligible for loan.
Solution:-
Create a project name it as ConditionalBR (as per your choice you can give it)
create a schema as per the requirement and name it as per your choice
Right click on project name--->New--->Xsd Schema (give the schema name as per your choice)
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org"
targetNamespace="http://www.example.org" elementFormDefault="qualified">
<xsd:element name="employeedetails">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="FristName" type="xsd:string"/>
<xsd:element name="MiddleName" type="xsd:string"/>
<xsd:element name="LastName" type="xsd:string"/>
<xsd:element name="Age" type="xsd:integer"/>
<xsd:element name="Salary" type="xsd:integer"/>
<xsd:element name="ZIP" type="xsd:integer"/>
<xsd:element name="Address" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Result">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="LoanResponse" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Click on save button to save the schema changes.
Double click on conditionalBR which shows the structure of the project
Right-click on the Proxy service layer---->Insert Protocal---->HTTP
then provide proxy service name Click on Next, choose service type as Wsdl then from xsd I need to make wsdl, click on create wsdl
select interface type as Synchronous Interface, select input payload as xsd incoming request (employee details), if yours project xsd is not shown in that folder the import the xsd by import option.
select output as result and click on ok
after selecting input and output payload window will appear like
then click on ok --->Next --->Finish
Double click on pipeline
Here we need set out logic
Drag-drop conditional branch, add one more branch
Drag-drop pipeline pair for each branches
Now you need to choose the condition element, click on red sign and set the overall condition element
Click on ok then save it
Drag-drop replace activity in each response pipeline
Double click on branch 1 and set the condition
Click on save button
Click on branch 2 and set the condition
Now go to 1st replace activity, double click on it and set the parameter as
Location:- Body
Expression :- .
Value:- concat($body/exam:employeedetails/exam:FristName,' ',$body/exam:employeedetails/exam:MiddleName,' ',$body/exam:employeedetails/exam:LastName,' ','is','Approved for Loan')
Replace option:- Replace node contents
Click on save button
Click on 2nd branch replace activity, set the parameter as
Location:- Body
Expression:- .
Value:- concat($body/exam:employeedetails/exam:FristName,' ',$body/exam:employeedetails/exam:MiddleName,' ',$body/exam:employeedetails/exam:LastName,' ','is','Not Eligible for Loan')
Replace option:- Replace node contents
Click on save button
Now please deploy the composite and test.
Comments
Post a Comment