Invoking Asynchronous Business Services using BPEL
Invoking Asynchronous Business Services Using BPEL
This tutorial covers invoking two asynchronous business services in a parallel flow and using conditional branching based on the results returned from the two processes by using BPEL.
Approximately 1 hour
This tutorial covers the following topics:
Place the cursor over this icon to load and view all
the screenshots for this tutorial. (Caution: Because this action loads all screenshots
simultaneously, response time may be slow depending on your Internet connection.)
Note: Alternatively, you can place the cursor
over each individual icon in the following steps to load and view only the screenshot
associated with that step.
This tutorial demonstrates how to invoke a business service asynchronously and to wait for its completion by using a callback mechanism. This tutorial shows how to create a parallel flow containing two asynchronous processes in the MyLoanFlow application, which is created in the "Invoking a Synchronous Business Service using BPEL" tutorial. The following two Web services, which are invoked asynchronously in a parallel flow, accept a loan application and return a loan offer:
 |
The UnitedLoan service |
 |
The StarLoan service |
The implementation for the UnitedLoan and StarLoan services are provided in the <drive:>\orabpel\samples\utils\AsyncLoanService directory of the Oracle BPEL Process Manager installation. The Web services are deployed by using the obant command-line script provided with Oracle BPEL Process Manager software.
Back to Topic List
The loan application document, supplied by a client, is first modified with a credit rating value after invoking a CreditRatingService process. The modified loan document is sent to the two loan-provider Web services for consideration. Each loan provider returns a loan offer document for acceptance.
After deploying the UnitedLoan and StarLoan services, you construct the BPEL process to asynchronously invoke the UnitedLoan and StarLoan services in parallel. The UnitedLoan service is automated and returns a loan offer document without manual intervention. However, the StarLoan service requires manual intervention. A Web interface is provided to manually accept a loan application that is sent to the StarLoan service, enabling the StarLoan service process to be completed. After the two loan offer documents are received from the loan services invoked, the BPEL process uses conditional branching to compare a value in the loan offer documents and select the loan offer with the lowest value.
In BPEL:
|
A parallel flow is implemented by creating a <flow> element. |
|
An asynchronous flow is implemented by creating an <invoke> activity element with a WS-Addressing header to use the Web service. The WS-Addressing header, which contains a correlation ID, enables the Web Service to callback the invoking process. The callback is used by the Web service to return a response to the invoking process, which waits for a response by using a <receive> activity. |
 |
The conditional branching is implemented by using a <switch> activity element. |
Back to Topic List
Before starting this tutorial, you should:
Back to Topic List
To create the BPEL actions that invokes the UnitedLoan service asynchronously, perform the following steps:
| 1. |
To build and deploy the UnitedLoan service, enter the following commands at the command prompt. (Use the drive letter corresponding with the location in which you installed Oracle BPEL Process Manager.)
cd D:\orabpel\samples\utils\AsyncLoanService obant

Note: Oracle BPEL PM Server should be running. The Ant build script builds and deploys both the UnitedLoan and StarLoan services, and some other Web services that are not used in this lesson.
|
| 2. |
In Oracle BPEL Designer, right-click MyLoanFlow.bpel, and select Open to display the BPEL file in Overview mode.
|
| 3. |
Add a <partnerLink> element for the UnitedLoan service by clicking Add Partner Link.

|
| 4. |
In the New partnerLink Wizard, to populate the wsdlLocation field, enter the URL http://localhost:9700/orabpel/default/UnitedLoan/UnitedLoan?wsdl, or click the icon to display the UDDI Browser, and click the UnitedLoan link.

Note: The UDDI Browser window is closed when you select a link to populate the field.
In the New partnerLink Wizard, enter the following values for the remaining fields:
Note: Field values, except for name, can be set by using the drop-down list in each field.

Click Done.
Note: The partnerRole and myRole fields are needed when invoking an asynchronous service, which performs a callback operation on your BPEL process.
|
| 5. |
Confirm that the unitedLoan partnerlink has been added by viewing the new partner link box in Overview mode in the BPEL Designer tab.

|
| 6. |
To invoke the UnitedLoan service, click Process Map in the BPEL Designer tab, and drag an invoke activity from the BPEL Palette to the flow before the onResult (client) activity.

|
| 7. |
To configure the invoke activity to initiate the unitedLoan service partnerLink, click the invoke activity and enter the following values in the BPEL Inspector fields.
In the New variable Wizard, set the field values:
 |
name: loanApplication |
 |
messageType: services:LoanServiceRequestMessage |

Click Done. The final properties of the invoke activity are:

Note: The outputVariable field is empty because the initiate operation is one way, that is, it does not have an output message.
|
| 8. |
To ensure that the unitedLoan service receives the loan application, add an assign activity before the initiate (unitedLoan) activity in BPEL Designer, and set the name property to setLoanApplication in the BPEL Inspector.

|
| 9. |
Right-click the setLoanApplication assign activity icon in the Process Map, and select Add Copy Rule.

In the Copy Rule window, click the Variable option button in the From section, and select the values for the following fields by using the drop-down lists.
 |
Variable: input |
 |
Part: payload |
In the To section, select the following field values:
 |
Variable: loanApplication |
 |
Part: payload |
Note: The XPATH Query fields in the Copy Rule window are optional. If the XPATH Query value is omitted, the entire message from the input variable is copied to the output variable.

Click Done.
|
| 10. |
To configure the BPEL process to receive the UnitedLoan service's result from a callback operation, drag a receive activity from the BPEL Palette to Process Map after the initiate (unitedLoan) activity.

|
11.
|
Select the receive activity in Process Map, and set the variable property by clicking its icon. Select Create Global Variable in the New variable Wizard. Enter the following field values:
 |
name: loanOffer1 |
 |
messageType: services:LoanServiceResultMessage |

Click Done.
In the BPEL Inspector, set the other <receive> activity property values.

|
12.
|
To obtain the first loan offer from the UnitedLoan service, drag an assign activity from the BPEL Palette to the region after the onResult (unitedLoan) activity, and set the name property to copyLoanOffer1.

|
13.
|
To copy the loanOffer1 variable to selectedLoanOffer variable, right-click the copyloanOffer1 assign activity and select Add Copy Rule. In the From section of the Copy Rule window, select the first option button and enter the following values.
 |
Variable: getLoanOffer1 |
 |
Part: payload |
In the To section, set the following field values:
 |
Variable: selectedLoanOffer |
 |
Part: payload |
Note: The XPATH Query field is empty in both cases. This copies the entire document from one variable to another. 
Click Done.
|
14.
|
To compile and deploy the updated MyLoanFlow BPEL process to Oracle BPEL PM Server, click BPEL > Build and Deploy BPEL Project. The results of the build and deployment processes are shown in the Console log.

Note: Correct any errors before proceeding with the next task of testing the asynchronous UnitedLoan service BPEL process flow. That is, ensure that you see "BUILD SUCCESSFUL" appear in the Console log window.
|
Back to Topic List
To test the asynchronous invocation of the UnitedLoan service, perform the following steps:
| 1. |
Start and log in to Oracle BPEL Console by clicking Start > Programs > Oracle BPEL Process Manager 2.0 > BPEL Console. Enter bpel in the Password field.

|
| 2. |
In Dashboard, the MyLoanFlow, UnitedLoan, and StarLoan with other services should appear under the Deployed BPEL Processes column. Click the MyLoanFlow link.

|
| 3. |
Initiate the MyLoanFlow process to test the asynchronous UnitedLoan service by entering 123456789 in the SSN field. Click Post XML Message.

Note: This initiates the MyLoanFlow process, which can be monitored using the Visual Flow or Audit Instance links displayed in the response page.

|
| 4. |
To verify that the asynchronous BPEL process is working click the Audit Instance link to display the process step in the Audit subtab of the Instances tab.

Note: The creditRatingService is examined in the OBE titled "Invoking a Synchronous Business Process using BPEL."
|
| 5. |
To examine the loan application document sent to the UnitedLoan service, scroll down the Audit subtab window until the unitedloan (intiate) activity is visible and then click the More link.

Note: The inner <loanApplication> element contains the loan application details returned from the CreditRatingService in the payload part of the loanApplication variable.

|
| 6. |
To examine the loan offer document returned by the UnitedLoan service, scroll down the Audit tab window until the unitedLoan (onResult) receive activity is visible. To view the contents of the loanOffer1, click the More link.

Note: The payload part of the loanOffer1 variable contains a <loanOffer> XML fragment containing the service <providerName> element value of United Loan, and <APR> element value of 5.7, which is calculated and returned by the UnitedLoan service.

Note: If you click the More link for the copyLoanOffer1 and client (onResult) activities, you can see that the loanOffer1 payload is copied to the selectedLoanOffer variable, which is returned to the client application that submitted the loan application.
|
Back to Topic
To create a parallel flow by using the <flow> BPEL activity, perform the following steps:
| 1. |
To create a scope container for the parallel flow activities in BPEL Designer, drag a scope activity from the More Activities list in the BPEL Palette to the region between the getCreditRating scope and the setLoanApplication assign activity in the Process Map.

|
| 2. |
To set the name for the new scope activity, click scope-1 in the Process Map and set the name property to collectOffers in the BPEL Inspector.

|
| 3. |
Expand the collectOffers scope by clicking to the top left of the scope.

Drag the setLoanApplication assign activity to the "Drop activity here" text inside the collectOffers scope box.
 |
| 4. |
To add the parallel <flow> activity into the collectOffers scope, drag flow from More Activities in the BPEL Palette to the region after setLoanApplication in the collectOffers scope.

|
| 5. |
Drag the initiate (unitedLoan) and onResult(unitedLoan) activities sequentially to the left branch of the flow activity.

Note: The next section adds the StarLoan service into the right branch of the parallel flow activity.
To save your changes to the MyLoanFlow BPEL process, select File > Save.
|
Back to Topic List
To invoke the StarLoan service asynchronously in parallel with the UnitedLoan service, perform the following steps:
| 1. |
To create a new partnerLink for the StarLoan service, in BPEL Designer click Overview to view the MyLoanFlow process in overview mode and click Add Partner Link.

In the New partnerLink Wizard, enter the following values in the fields:

Click Done. |
| 2. |
To invoke the starLoan service in BPEL Designer, click Process Map to view the process map, then drag an invoke activity from the BPEL Palette to the right branch of the flow activity.

Select the invoke activity in the BPEL Inspector. Enter the following property values:
Note: The outputVariable property is empty as the asynchronous service does not return its result with this activity. You can select these property values from drop-down list in each field.

|
| 3. |
To receive the loan offer from the StarLoan service, drag a receive activity from the BPEL Palette to the region after the initiate (starLoan) activity in the right branch of the flow:

Select the receive activity and in the BPEL Inspector, enter the following property values:
In the New variable Wizard for the variable property, enter the following field values:
 |
name: loanOffer2 |
 |
messageType: services:LoanServiceResultMessage |
Note: The messageType field is already populated with the correct value.

Click Done.
Note: In the BPEL Palette, the property values for the getLoanOffer2 receive activity should be:

|
Back to Topic List
Conditional branching, implemented with a <switch> activity in BPEL, allows the BPEL process to perform different tasks based on the outcome of a condition.
To create a conditional branch that selects the best loan offer based on a comparison of the APR values returned by the UnitedLoan and StarLoan services, perform the following steps:
| 1. |
In the Process Map of the BPEL Designer, drag a switch activity from the list under More Activities in the BPEL Palette to the region after the flow activity.

Note: By default, the switch activity initially provides two branches:
 |
An <<empty>> branch, which is processed if the branch condition is true.
Note: Each branch, except the <otherwise> branch, specifies a condition. |
 |
An <otherwise> branch, which is processed if all the other branch conditions evaluated are false. |
|
| 2. |
Drag the copyLoanOffer1 assign activity below the switch activity to the <<empty>> branch of the switch activity. In the BPEL Inspector, change the assign activity name property to selectUnitedLoan.

|
| 3. |
To enable selection of the StarLoan offer, drag a new assign activity from the BPEL Palette to the <otherwise> branch of the switch activity. Using the BPEL Inspector, set the name property to selectStarLoan.

|
| 4. |
Right-click the selectStarLoan assign activity, and select Add Copy Rule to copy the payload part from loanOffer2 to the payload part of the selectedLoanOffer variable.

Click Done. |
| 5. |
To add the conditional test for the first branch of the switch activity, select the shaded box labeled <<empty>>, which contains the selectUnitedLoan assign activity. In the condition property in the BPEL Inspector, enter the following text:
bpws:getVariableData('loanOffer1','payload','/autoloan:loanOffer/autoloan:APR') <
bpws:getVariableData('loanOffer2','payload','/autoloan:loanOffer/autoloan:APR')

Note: The condition compares the text value in the <APR> element of loanOffer1 with loanOffer2. If the <APR> value for loanOffer1 is less than loanOffer2, then the UnitedLoan offer is copied to selectedLoanOffer. Otherwise, the StarLoan offer is copied to selectedLoanOffer. If you enter the condition text in the BPEL Source tab, then use the character sequence < for the '<' character.
|
| 6. |
To deploy the completed BPEL process flow, click BPEL > Build and Deploy BPEL Project and observe the results in the BPEL Designer Console tab.

|
Back to Topic List
Testing the BPEL process is done using the Oracle BPEL Console. The StarLoan service must be manually processed. To assist with completing a loan offer for the StarLoan service, a Web-based user interface is already deployed with the StarLoan application in the Oracle BPEL PM Server. The sequence of steps reveal the URL used to access the Web interface for completing the loan offer for StarLoan. Two tests are performed, one to check if the conditional branching process selects the UnitedLoan offer when the StarLoan offer is greater than the UnitedLoan, and the other to check the results when the UnitedLoan offer is less than the StarLoan offer.
To test the parallel flow of operation and conditional branching, perform the following steps:
| 1. |
By using the BPEL Console to delete process instances in the BPEL PM Server, click the Instances tab (even if the Instance tab is displayed). Click Purge All Instances.

In the delete all instances confirmation page, click Delete all instances.

To return to the console, click Back to Console.

Note: This returns you to the Dashboard page of the BPEL Console.
|
| 2. |
To start the test of MyLoanFlow, in Dashboard, click the MyLoanFlow link in the Deployed BPEL Processes column.

|
| 3. |
In the
Initiating a test instance HTML Form page, enter 123456789 in the SSN field, and click Post XML Message.

|
| 4. |
In the BPEL Processes page, which shows that the test instance has been initiated, click the Visual Flow link.

|
| 5. |
Click the Instances tab to look at the flow. Scroll down until you see the parallel flow containing the initiate and receive activities for StarLoan and UnitedLoan services.

Note: The unitedLoan (onResult) activity has completed. However, the starLoan (onResult) has not completed, which is indicated by the color highlight surrounding the activity waiting for completion.
If you click the Audit subtab and scroll down until you can see the activities contained in the <flow> section, then you can notice that the starLoan (onResult) activity is in a pending state waiting for the asynchronous callback from the StarLoan service.

|
| 6. |
To manually complete the StarLoan process, start a new Web browser window, and enter the following URL to access the StarLoan UI to display the loan application for processing:
http://localhost:9700/StarLoanUI

Note: The Web page shows that StarLoan has a loan application waiting for review.
|
| 7. |
To begin the loan application approval process, click the Assign APR Task link.

Note: A Web form page is displayed containing the details, such as the SSN of the customer submitting the loan application, and a text field for the APR value with a default of 7.4.
|
| 8. |
To approve the loan application and complete the StarLoan service task, accept the default APR value and click Approve.

Note: Approving or rejecting the loan application manually completes the StarLoan processing, and initiates an asynchronous callback to the MyLoanFlow BPEL process.
|
| 9. |
To view the updated flow for the MyLoanFlow BPEL process, in the Audit subtab of the Instances tab in the Oracle BPEL Console, click the Refresh View link and scroll down to the starLoan (onResult) activity.

Note: The starLoan (onResult) activity has completed after receiving the "onResult" callback from the StarLoan partner link.
|
| 10. |
To view the loan offer document returned by the StarLoan service, click the More link at the end of the line stating Received "onResult" callback from partner "starLoan."

Note: The <APR> element in the loan offer contains the 7.4 value entered when approving the loan application by using the StarLoan UI Web application.
|
| 11. |
To view the <APR> value returned in the loan offer from the UnitedLoan service, in the Audit subtab of the Instances tab, scroll down to the unitedLoan (onResult) activity, and click the More link:

Note: The <APR> element in the UnitedLoan offer contains the value 5.7, which is less than the StarLoan offer.
|
| 12. |
To see the activities processed by the <switch> conditional branching activity, in the Audit subtab of the Instances tab, scroll down until you see the <switch> element:

Note: The selectUnitedLoan assign activity was processed, indicating the condition in the switch successfully chose the best loan offer, that is the loan offer with a smaller <APR> value. Click the More link to confirm that the selected loan offer is from United Loan.

Note: The loan offer selected can also be viewed by clicking the More link for the client (onResult) activity. You can also click the Instances > Flow tab to view the MyLoanFlow BPEL process steps, which shows that the selectUnitedLoan assign activity is processed by the switch after the activities in parallel flow have completed.

|
| 13. |
To check if the conditional branching selects the StarLoan offer when it has an <APR> element value less than the UnitedLoan value of 5.7, click the Dashboard tab and click the MyLoanFlow link to initiate a new test instance of the BPEL process.

Note: The In-Flight BPEL Processes column is split with the bottom section showing the Recently Completed BPEL Process Instances.
|
| 14. |
To initiate a new loan application, in the Initiate subtab of the BPEL Processes tab enter 987654321 in the SSN field, and click Post XML Message.

|
| 15. |
Open a new Web browser window, and manually approve the loan application with the StarLoanUI by entering the following URL:
http://localhost:9700/StarLoanUI

Note: The StarLoan UI lists another task waiting approval.
|
| 16. |
In the StarLoan UI, click the Assign APR Task link.

Note: The loan application being approved is for a customer with a SSN value of 987654321.
|
| 17. |
To approve the StarLoan offer, enter 1.1 in the APR field, and click Approve.

Note: The StarLoanUI Web page confirms the approval process has completed.
Close the browser containing the StarLoanUI confirmation page.
|
| 18. |
To confirm that the StarLoan is selected by the MyLoanFlow BPEL process, return to the browser displaying the Initiate subtab in the BPEL Processes tab. Click the Visual Flow link, and scroll until you see the switch activity.

Note: The selectStarLoan assign activity should appear below the switch activity. This confirms that the conditional branch successfully selected the StarLoan offer, which contains the lowest APR value.
|
| 19. |
To verify that the StarLoan offer selected contains the value 1.1 in the <APR> element, click Audit subtab in the Instances tab window, scroll down to the selectedStarLoan activity, and click the More link.

Note: The selected loan offer is from Star Loan and contains a value 1.1 in the <APR> element.
|
Back to Topic List
In this tutorial, you've learned how to:
Back to Topic List
 |
To ask a question about this OBE tutorial, post a query on the OBE
Discussion Forum. |
 |
To learn more about Oracle BPEL products, refer
to additional OBEs on the OTN
Web site. |
Back to Topic List
|