Oracle OSB 12c: Conditional Branch example

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 (>=)

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

0_OSB-12c_Conditional_Branch_example_Problem_statement_in_figure

 

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

 

Step 1: Open New Project

File Menu –> New –> Project

1_OSB-12c_Conditional_Branch_example_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

2_OSB-12c_Conditional_Branch_example_New_Project_wizard

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

3_OSB-12c_Conditional_Branch_example_New_Project_wizard_name

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

4_OSB-12c_Conditional_Branch_example_New_Project_create_folder

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

5_OSB-12c_Conditional_Branch_example_New_Project_create_folder_b

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)

6_OSB-12c_Conditional_Branch_example_New_Project_create_folder_c

 

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

  1. http://localhost:8080/EmployeeLoanService/services/DefaultLoanApprovalService?wsdl
  2. 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

7_OSB-12c_Conditional_Branch_example_New_Project_schema_wsdl

Note: Make sure those two web services are running

 

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)

8_OSB-12c_Conditional_Branch_example_New_Project_HTTP_component

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

9_OSB-12c_Conditional_Branch_example_New_Project_Business_wizard_6a

 

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

10_OSB-12c_Conditional_Branch_example_New_Project_Business_wizard_6b

 

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

11_OSB-12c_Conditional_Branch_example_New_Project_Business_wizard_6c

 

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

12_OSB-12c_Conditional_Branch_example_New_Project_Business_wizard_6d

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

13_OSB-12c_Conditional_Branch_example_New_Project_Business_wizard_7a

 

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

14_OSB-12c_Conditional_Branch_example_New_Project_Business_wizard_7b

 

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

15_OSB-12c_Conditional_Branch_example_New_Project_Business_wizard_7c

 

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

16_OSB-12c_Conditional_Branch_example_New_Project_Business_wizard_7d

Finally both the Business Services are created

 

Business Service is created on the External Services lane and this resides under “BusinessService” folder

17_OSB-12c_Conditional_Branch_example_New_Project_Business_services_created

 

Proxy Service

Step 8: Create Proxy Service and add pipeline

Drag and drop HTTP component from Technology palate to Proxy Services

18_OSB-12c_Conditional_Branch_example_New_Project_Proxy_service_wizard

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

19_OSB-12c_Conditional_Branch_example_New_Project_Proxy_service_wizard_9a

 

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

20_OSB-12c_Conditional_Branch_example_New_Project_Proxy_service_wizard_9b

 

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

21_OSB-12c_Conditional_Branch_example_New_Project_Proxy_service_wizard_9c

 

Step 9.d: In step 3 of Create Proxy Service wizard –> populates endpoint URI

Click Finish

22_OSB-12c_Conditional_Branch_example_New_Project_Proxy_service_wizard_9d

Finally Proxy Service is created

 

Proxy Service is created on the Proxy Services lane and this resides under “ProxyService” folder

23_OSB-12c_Conditional_Branch_example_New_Project_Proxy_service_created

 

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

24_OSB-12c_Conditional_Branch_example_New_Project_pipeline_editor

 

Step 11: Conditional Branch node

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

25_OSB-12c_Conditional_Branch_example_New_Project_drag_cond_branch

 

Add one more branch to the already existing two branches
26_OSB-12c_Conditional_Branch_example_New_Project_drag_cond_branch_ADD

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>

27_OSB-12c_Conditional_Branch_example_New_Project_drag_cond_branch_ADD_condition

 

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

28_OSB-12c_Conditional_Branch_example_New_Project_drag_cond_branch_ADD_condition_insert

 

Step 14: Add conditions to all branches under “Conditional Branch” node

Conditional Branch 1: loan amount in dollars <= 4000

29_OSB-12c_Conditional_Branch_example_New_Project_add_cond_to_branch_node_1

 

Enter the value “4000” for the comparison to go in this branch

Click OK

30_OSB-12c_Conditional_Branch_example_New_Project_add_cond_to_branch_node_1_enter_values

 

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)

31_OSB-12c_Conditional_Branch_example_New_Project_add_cond_to_branch_node_2_enter_values

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

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

32_OSB-12c_Conditional_Branch_example_New_Project_add_routing_to_each_branch_nodes

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

33_OSB-12c_Conditional_Branch_example_New_Project_add_BS_to_routing_node

 

Similarly, do it for second operation as well (as said earlier red-ribbon type error vanished)

34_OSB-12c_Conditional_Branch_example_New_Project_cond_branch_after_adding_BS_services

 

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

35_OSB-12c_Conditional_Branch_example_New_Project_cond_branch_example_testing_run

 

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

36_OSB-12c_Conditional_Branch_example_New_Project_cond_branch_example_testing_run_execute

Note: Make sure enterprise web service is up and running, otherwise error will be thrown

 

Request document and Response document

37_OSB-12c_Conditional_Branch_example_New_Project_cond_branch_example_testing_result_output

 

Similarly, we can test for other case i.e.; entering loan amount of greater than $. 4K where OSB routes to HR Manager Approval service

38_OSB-12c_Conditional_Branch_example_New_Project_cond_branch_example_testing_result_output_2

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)

 

Download project

EmployeeLoanService (10kB)

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

 

Read Also:

Happy Coding !!
Happy Learning !!

Oracle OSB 12c: Service Callout and Routing Table example
Oracle OSB 12c: Operational Branch example