In this article, we will explore the use of Service Callout & Routing Table nodes in OSB 12c
We will re-use the last article and modify business case requirements and then accordingly implement the solution using “Service Callout” & “Routing Table” nodes
1. Service Callout :
- This node helps to enrich the content before invoking the business service on the request thread (similarly on the response thread)
2. Key points of Service Callout node :
- OSB makes a call to a service through a service callout action, the content of the message is constructed using the values of variables in the message context
- Message content for outbound messages is handled differently depending upon the type of the target service
- Used in real time request-response scenarios
- Call a service in synchronous way [Blocking]
- Being a synchronous call, the thread gets blocked until a response is returned from target service
- Using Service Callout node in Proxy Service’s Message Flow –> can invoke business service or another proxy service
3. Routing Table:
- A routing table is a set of routes wrapped in a switch-style condition table. It is a short-hand construct that allows different routes to be selected based upon the results of a single XQuery expression
4. Business case requirement :
- This is the same use case for Employee Loan process in an organization used in the last article with little modification
- 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
- Employee details are validated using Employee Validation service
- Outcome of the validation service is either Yes or No
- And this employee validation outcome needs to be set in the request before routing to the business service (from there to invoke an actual enterprise web service)
- This time, we are going to route the service based on the loan amount (in dollars) at the Routing Table level (unlike conditional branch node in the last article)
- 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
5. Assumptions :
- There are three web services for Employee Loan Process up & running on the application server
- This web services can be invoked only through OSB
- Three web services are
1. Default Loan approval service
2. HR Manager Loan approval service
3. Employee Detail Validation Service (for employee detail validation) - 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)
6. Service Callout & Routing Table example :
Let’s get started with designing OSB modules for Service Callout & Routing Table example in Oracle JDeveloper 12c IDE
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 this 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: ServiceCalloutAndRoutingTableSB
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 three web services up & running at below URLs in the application servers
- http://localhost:8080/EmployeeLoanService/services/DefaultLoanApprovalService?wsdl
- http://localhost:8080/EmployeeLoanService/services/HRManagerLoanApprovalService?wsdl
- http://localhost:8080/EmployeeLoanService/services/ValidateEmployeeDetailService?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 three web services are running
6.1 Business Service :
Step 6: Create Business Service to invoke the exposed Web Service
There are three Business Services
- Default Loan Approval Service
- HR Manager Loan Approval Service
- Employee Validation 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
Similarly, we will create business service for third service i.e.; Employee Validation Service
Step 8.a: Fill up the mandatory details for Business Service (i.e .bix file)
- Service Name: EmployeeValidationServiceBS (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 8.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 8.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 8.d: In step 3 of Create Business Service wizard –> populates the endpoint URI for the exposed web service to be invoked
Click Finish
Finally all three Business Services are created
Business Service is created on the External Services lane and this resides under “BusinessService” folder
6.2 Proxy Service
Step 9: 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 10.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 10.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
Note: WSDL file of EmployeeLoanApprovalService(PS) & other two loan approval service namely viz., DefaultLoanApprovalService(BS) and HRManagerLoanApprovalService(BS) are roughly similar and their request/response pattern are almost similar with one extra element for Business Service for Employee Validation (employeeDetailValidated)
Step 10.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 10.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 11: 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 12: Service Callout node
As per our business case requirement stated in the first section of this article, we need to invoke employee validation service using “Service Callout” node to get to know whether employee details are validated or not
Outcome of Employee Validation Service is: Yes or No
And this value needs to be set in the request document/body before invoking the Business Service (using “Routing Table” node in this example)
Step 13: Drag and drop “Pipeline Pair” from “Message Flow” under the category “Nodes”
Note: We can’t directly drag & drop “Service Callout” node to Proxy Service’s Message Flow. So, first drag & drop “Pipeline Pair” node and then drag & drop “Service Callout” node inside stage1 of Request Pipeline of the PipelinePairNode1
Drag and drop “Service Callout” from “Message Flow” under the category “Communication”
Note: Drag & drop “Service Callout” inside Stage1 of Request Pipeline of the PipelinePairNode1
Error: Red-ribbon type error mark on top-right corner is because, we haven’t set correct mandatory values for Service Callout node (after setting conditions & saving would vanishes all errors)
Step 14: Next step is to set mandatory values for Service Callout –> which will vanishes all errors after saving
First select the service to be invoked i.e.; in this example, EmployeeValidationServiceBS
Finally click OK
Select the correct operation to be invoked; in this case we have got just one operation to validate the employee details
- Operation: validateEmployeeDetail
- Configuration: Configure Payload Document (Make sure to select this option out of 2)
Set the mandatory Payload values for both Request & Response i.e.; setting the message context variable as below
- Request –> Payload* –> requestValidateEmployeeDetail
- Response –> Payload* –> responseValidateEmployeeDetail
Points regarding the Service Callout request & response variables
- Request variable “requestValidateEmployeeDetail” to be set using “Assign” node prior to Service Callout node in message flow
- Extract validation details (i.e.; Yes or No) from the response variable “responseValidateEmployeeDetail” and set it in the context variable using “Assign” node
Step 15: Setting/assigning request document à in the request variable of the “Service Callout” for Employee Validation Service using “Assign” node
Drag and drop “Assign” from “Message Flow” under the category “Message Processing”
Assign Properties :
- Value*: Click “fx” which opens Expression Builder –> set the request document for Employee Validation Service (move to next step for setting this expression)
- Variable*: requestValidateEmployeeDetail (this is same message context variable we have set in the request Payload of the Service Callout)
Click “fx” to set request document for Employee Validation Service
To get the request document sample, we need to test the Employee Validation Service separately at the Business Service level
Error: This is due to, we haven’t set the namespace for this request document –> we will take care of this error in the folowing step
Add namespace for request document of the Employee Validation Service
User Namespace:
- Prefix: val
- URL: http://benchresources.in/entities/ValidateEmployeeDetail
Finally click OK
Step 16: Extract response document from response variable of the “Service Callout” and set in the message context variable
Drag and drop “Assign” from “Message Flow” under the category “Message Processing”
Assign Properties:
- Value*: Click “fx” and move to the next step
- Variable*: employeeValidated
Note: we will use this message context variable “employeeValidated” in the next step (to set in the request body before invoking Business Service)
Below expression used to extract the content value from the response variable of the Service Callout
- Expression: $responseValidateEmployeeDetail/val:validated/text()
Finally click OK
Note: This message context variable “employeeValidated” will be set in the request body using “Insert” node in the next step
Step 17: Insert message context variable “employeeValidated” in the original request body (before invoking either of the Business Service)
Drag and drop “Insert” from “Message Flow” under the category “Message Processing”
Insert Properties:
- Value*: click “fx” and move to next step for setting the Expression
- Position*: after
- Location*: body
- XPath: $body/loan:ProcessLoanRequestType/loan:amountInDollars
Click “fx” and set below Expression
- Expression: <loan:employeeDetailValidated>{$employeeValidated}</loan:employeeDetailValidated>
Finally click OK
Step 18: Routing Table node
Routing Table: It is a set of routes wrapped in a switch-style condition table
Drag and drop “Routing Table” from “Message Flow” under the category “Route”
- Value*: $body/loan:ProcessLoanRequestType/loan:amountInDollars/text()
6.3 Advantage of OSB 12c over OSB 11g :
- When we drag and drop the Routing or Routing Table node, it automatically have a Route node in place
- Whereas in 11g, we need to drag and drop Route node first before Routing or Routing Table node
Error: Red-ribbon type error mark on each top-right corner is because, we haven’t choose/set any specific business service
Click fx which opens XQuery Expression Builder and set the below expression
- Expression: $body/loan:ProcessLoanRequestType/loan:amountInDollars/text()
Finally click OK
Note: manually need to add “/text()”
Step 19:
Case 1: amount <= 4000
- Click first case under Routing Table
- Select “<=” operator from drop-down and set the value to “4000” using Expression Builder
Add business service to Routing node in the Routing Table
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, repeat the same steps for the second case (>4000)
Case 2: amount > 4000
- Click second case under Routing Table
- Select “>” operator from drop-down and set the value to “4000” using Expression Builder
Add business service to Routing node in the Routing Table
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, repeat the same steps for the default case
In this example, actually we don’t need that but this needs to be set. So, repeat the same steps and select Default Loan Approval Service
Step 20: Time to test !!
Testing Service Bus project –> deploying into IntegratedWeblogicServer
Step 21: 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 $. 3750
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)
7. Download project :
EmployeeLoanService (13kB) ServiceCalloutAndRoutingTableSB (26.7kB)
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-design.htm#OSBDV2378
- http://docs.oracle.com/cd/E28280_01/admin.1111/e15867/modelingmessageflow.htm#i1103454
- https://docs.oracle.com/middleware/1213/osb/develop/osb-pipeline-actions.htm#OSBDV2493
- https://docs.oracle.com/middleware/1213/osb/develop/osb-pipeline-design.htm#OSBDV2409
Happy Coding !!
Happy Learning !!