In this article, we will explore the use of Conditional Branch node in OSB 12c
With the use of Conditional Branch node, we can route the incoming requests to different business services based on different conditions like,
- equal to (=)
- not equal to (!=)
- less than (<)
- less than or equal to (<=)
- greater than (>)
- greater than or equal to (>=)
1. Business case requirement :
- This is a simple use case for Employee Loan process in an organization
- When an employee of the organization submit the request for a loan, it goes through various process to get it approved
- Employee enters basic details like employee id, name, grade and loan amount requested in dollars and comments if any
- If entered loan amount in dollars is less than or equal to 4 thousands ($4K), then it goes through the default loan approval process
- Otherwise, if entered loan amount in dollars is greater than 4 thousands ($4K), then it goes to HR Manager for approval
2. Assumptions :
- There are two web services for Employee Loan Process up & running on the application server
- This web services can be invoked only through OSB
- Two web services are
1. Default Loan approval service
2. HR Manager Loan approval service - For demo purpose, we will copy the WSDL and Schema files and paste in our Service Bus project under “Resources” folder
This web service roughly based on this article, go through this article to understand the underlying web services part - Download this web service project used in this demo example from download section (scroll to last)
Let’s get started with designing OSB modules for Conditional Branch example in Oracle JDeveloper 12c IDE
3. Conditional Branch example :
Step 1: Open New Project
File Menu –> New –> Project
Step 2: Select Service Bus Tier from available categories
Service Bus Tier –> Service Bus Project –> OK
This opens up wizard for New Service Bus Project
Note: Comparing this wizard with the one we have created in the last article, the major difference is “Service Bus Project” option is enabled since we have one Service Bus Application in the user/developer workspace (already created)
Step 3: Enter Project Name and its directory location for the new Service Bus Project
Leave the default values for demo; otherwise we can give more specific names in accordance with naming convention followed in the project
Project Name: ConditionalBranchSB
Click Finish
New Service Bus project will be created with required artifacts
Step 4: Create required folders in accordance with project standards (naming conventions)
Generally, there should be
- ProxyService folder to place/store/save the proxy services which ends with .proxy
- BusinessService folder to place/store/save the business services which ends with .bix
- Resources folder to store all other required artifacts like WSDL, Schema and transformations files
Now, we will create above listed folders
Right click on the Service Bus project –> New –> Folder…
Opens up a new wizard
Note: If you don’t find “folder” option directly, then click on “From Gallery” and from there choose folder option and continue with below next steps
Create Folder wizard –> enter folder name like, for example “BusinessService” for Business Service
Finally click OK –> to create folder
Similarly, we can create “ProxyService” and “Resources” folders
After creating all three folders namely ProxyService, BusinessService and Resources, our project will look like below screenshot
Note: Also create “entities” & “wsdl” folders under “Resources” to store/keep Schema and WSDL files (separately)
Step 5: Enterprise Information System (EIS) or Exposed Web Services
As we discussed in the assumption section, there are two web services up & running at URLs
- http://localhost:8080/EmployeeLoanService/services/DefaultLoanApprovalService?wsdl
- http://localhost:8080/EmployeeLoanService/services/HRManagerLoanApprovalService?wsdl
So we will copy Schema and WSDL files && paste it to the Resources folder as directed below
- XML Schema –> under “entities” folder
- WSDL –> under “wsdl” folder
Note: Make sure those two web services are running
3.1 Business Service :
Step 6: Create Business Service to invoke the exposed Web Service
There are two Business Services
- Default Loan Approval Service
- HR Manager Loan Approval Service
Drag and drop HTTP component from Technology palate to External Services lane (Business Service in 11g)
Upon dropping, a new wizard pops up to enter the required details for Business Service or External Service
Step 6.a: Fill up the mandatory details for Business Service (i.e .bix file)
- Service Name: DefaultLoanApprovalServiceBS (append BS to the business service as a naming standard)
- Location: browse through “BusinessService” folder we created in earlier step
- Transport: http (keep it as it is)
Click Next
Step 6.b: Select “WSDL” from four available options
And browse to wsdl location by clicking first icon with green arrow mark pointing towards right hand side (i.e.; wsdl is placed under “Resources/wsdl” folder)
Choose “Application” and select correct WSDL we have stored for this project
Finally click OK and then click Next
Step 6.c: In step 2 of Create Business Service wizard –> populates wsdl file with port after reading the WSDL file we have chosen in the previous step
Click Next
Step 6.d: In step 3 of Create Business Service wizard –> populates the endpoint URI for the exposed web service to be invoked
Click Finish
Similarly, we will create business service for second service i.e.; HR Manager Loan Approval Service
Step 7.a: Fill up the mandatory details for Business Service (i.e .bix file)
- Service Name: HRManagerLoanApprovalServiceBS (append BS to the business service as a naming standard)
- Location: browse through “BusinessService” folder we created in earlier step
- Transport: http (keep it as it is)
Click Next
Step 7.b: Select “WSDL” from four available options
And browse to wsdl location by clicking first icon with green arrow mark pointing towards right hand side (i.e.; wsdl is placed under “Resources/wsdl” folder)
Choose “Application” and select correct WSDL we have stored for this project
Finally click OK and then click Next
Step 7.c: In step 2 of Create Business Service wizard –> populates wsdl file with port after reading the WSDL file we have chosen in the previous step
Click Next
Step 7.d: In step 3 of Create Business Service wizard –> populates the endpoint URI for the exposed web service to be invoked
Click Finish
Finally both the Business Services are created
Business Service is created on the External Services lane and this resides under “BusinessService” folder
3.2 Proxy Service :
Step 8: Create Proxy Service and add pipeline
Drag and drop HTTP component from Technology palate to Proxy Services
Upon dropping, a new wizard pops up to enter the required details for Proxy Service
Step 9.a: Fill up the mandatory details for Proxy Service (i.e .proxy file)
- Service Name: EmployeeLoanProcessPS (append PS to the proxy service as a naming standard)
- Location: browse through “ProxyService” folder we created in earlier step
- Transport: http (keep it as it is)
Keep “Generate Pipeline” checked for creating pipeline along with Proxy Service
Click Next
Step 9.b: We will use “Default Loan Approval Service” WSDL for this demo example
Note: In a complex business scenarios, WSDL file of BS & PS are different
Step 9.c: In step 2 of Create Proxy Service wizard –> populates wsdl file with port after reading the WSDL file we have chosen in the previous step
Click Next
Step 9.d: In step 3 of Create Proxy Service wizard –> populates endpoint URI
Click Finish
Finally Proxy Service is created
Proxy Service is created on the Proxy Services lane and this resides under “ProxyService” folder
Step 10: Double-click on the EmployeeLoanProcessPSPipeline which opens up in new editor with .pipeline extension (green-color round-cornered rectangle type figure in the Pipelines/Split Joins)
Opens up EmployeeLoanProcessPSPipeline.pipeline file in an editor
Step 11: Conditional Branch node
3.3 Conditional Branch :
- We can have different routes based on the conditions exposed at the Proxy Service level
In this example, we got two conditions exposed at the Proxy Service level namely
- amountInDollars <= 4000
- amountInDollars > 4000
So using conditional branch node, we can expose different routes based on the conditions depending on the business requirements with always mandatory default branch
Reason for default branch is to route the incoming request, if nothing matches the exposed condition at the Proxy Service level
Step 12: Drag and drop “Conditional Branch” from “Message Flow” under the category “Nodes”
Add one more branch to the already existing two branches
Error: Red-ribbon type error mark on top-right corner is because, we haven’t set conditions in Conditional Branch (after setting conditions & saving would vanishes all errors)
Step 13: Add condition expression to ”Conditional Branch” node (from Conditional Flow – Properties)
- click BranchNode1 which opens up Conditional Flow – Properties in the dialog box
- select “body” in the Expression field
- click “fx” icon next to <XPath>
Select the attribute from input request body element to be evaluated
In this example, amountInDollars from the request and click “Insert Into Expression”
And this is entered into Expression box at the top
Expression: ./loan:ProcessLoanRequestType/loan:amountInDollars
Step 14: Add conditions to all branches under “Conditional Branch” node
Conditional Branch 1: loan amount in dollars <= 4000
Enter the value “4000” for the comparison to go in this branch
Click OK
Conditional Branch 2: loan amount > 4000
Similarly, do it for second branch as well but this time instead of “<=”, select “>” operator from the drop-down from the values (under Properties)
Note: If any condition doesn’t fall under these two conditions (<=4000 or >4000), then default branch will come into picture (but safely all conditions are covered and there is no need to set any routing to business service for default branch)
Step 15: Add Routing node to each conditional branches (skip adding Routing node to Default branch)
Error: Red-ribbon type error mark on each top-right corner is because, we haven’t chose any specific business service
3.4 Advantage of OSB 12c over OSB 11g :
- When we drag and drop the Routing, it automatically have a Route node in place
- Whereas in 11g, we need to drag and drop Route node first before Routing node
Note: once we select and set the business service in the Routing, then red-ribbon type error mark will vanish after saving all
Step 16: Add business service to all Routing node
- Click on Routing –> opens corresponding properties in the dialog box below
- Click browse icon next to Service* –> opens “Resource Chooser” –> select service to be routed
- Finally Click OK
Similarly, do it for second operation as well (as said earlier red-ribbon type error vanished)
Step 17: Add transformation logic for the Proxy Service (i.e.; EmployeeLoanProcessPSPipeline.pipeline) using assign/replace node
Generally,
- Request document to the input of OSB and request document to the input of Enterprise Service isn’t same at all time
- So, we need to add transformation logic to convert the request document received at the input of OSB –> to the input of External/Business Service
- Judiciously use assign, replace, rename nodes
- Invoking other services using “Service Callout” or “Java Callout” node to enrich the input request document before invoking External/Business Service
Note: Above points implies for response thread in the response pipeline of the pipeline-pair
But in our case, we don’t need any transformation logic as both Proxy Service and Business Service are roughly based on the same WSDL
Time to test !!
Testing Service Bus project –> deploying into IntegratedWeblogicServer
Step 18: Testing
This will open our traditional OSB console, where we can input and execute this sample mock service.
Enter necessary employee details requesting a loan amount of $. 3685
Note: Amount entered by the user is less than $. 4K, therefore OSB will route to default loan approval service
Note: Make sure enterprise web service is up and running, otherwise error will be thrown
Request document and Response document
Similarly, we can test for other case i.e.; entering loan amount of greater than $. 4K where OSB routes to HR Manager Approval service
The same can be tested through Service console (OSB console) at http://localhost:7101/sbconsole (change the port number, if you have configured something else)
4. Download project :
EmployeeLoanService (10kB)
Related Articles :
- Oracle SOA 12c – Installation steps using Single Installer
- Oracle SOA 12c – Domain creation steps
- Oracle OSB 12c – Hello World mock service with Proxy Service
- Oracle OSB 12c – Hello World service with both Business and Proxy Service
- Oracle OSB 12c – Operational Branch example
- Oracle OSB 12c – Conditional Branch example
- Oracle OSB 12c – Service Callout and Routing Table example
- Oracle OSB 12c – Java Callout and Routing Table example
- Oracle OSB 12c – File Polling/Reading and Writing using File Transport
- Oracle OSB 12c – File Polling/Reading and Writing using FTP Transport and authentication via Service Account
- Oracle WebLogic – Steps to create Connection Factory and Queue
- JMS Client – To produce and consume messages in JMS Queue
- Oracle WebLogic – Steps to create Connection Factory and Topic
References :
- https://docs.oracle.com/middleware/1213/osb/develop/osb-pipeline-flow.htm#OSBDV2468
- https://docs.oracle.com/middleware/1213/osb/develop/osb-pipeline-design.htm#OSBDV2359
Happy Coding !!
Happy Learning !!