Invoking a Synchronous Business Service using BPEL
Invoking a Synchronous Business Service by using
BPEL
This tutorial covers invoking a synchronous BPEL business service that interacts with a credit rating Web service.
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 covers how to use Oracle BPEL Designer to create
the BPEL actions required to invoke a synchronous credit rating service that
determines a credit rating for the applicant based on their social security
number (SSN). The credit rating service check is the first part of a "loan
flow application," and includes some exception handling. The process steps
are tested by using Oracle BPEL Process Manager.
The "loan flow application" accepts a loan application XML document from a client containing their SSN and other details. The credit rating service uses the SSN to determine the credit rating value, which is returned in a modified loan application document. The updated loan application is forwarded to loan providers for evaluation. Each loan provider returns a loan offer document. The best loan offer is selected and returned to the client for acceptance.
Note: A BPEL process provides a Web Service Description Language (WSDL) exposing its interface as a Web Service.
Back to Topic List
The following diagram illustrates the initial process structure of the MyLoanFlow BPEL process, which accepts a loan application document as an input message, invokes a credit rating service, and returns an updated loan application document.

The diagram shows the activities required for the MyLoanFlow BPEL process to invoke the CreditRatingService Web service:
| d1. |
The MyLoanFlow BPEL process receives an input message containing a loan application document. |
| d2. |
The social security number (SSN) in the loan application document is assigned to a variable (crInput), which is supplied to the CreditRatingService invoked by using the partner link identifying the service. |
| d3. |
The CreditRatingService synchronously processes the request and returns a result in the output variable (crOutput) to the BPEL process. |
| d4. |
By using an assign activity, the result in the output
variable is copied into the loan application document.
Note: A loan offer document, and not the loan application, is returned in an output message from the BPEL process. The loan offer is not processed in the BPEL lesson. |
Back to Topic List
Before starting this tutorial, you should have:
|
1. |
Installed Eclipse 3.0 |
|
2. |
Installed JDK 1.4.1_x or later |
|
3. |
Installed the Oracle BPEL Process Manager and Oracle BPEL Designer |
These prerequisites are discussed in the OBE titled Installing Oracle BPEL Designer and Oracle BPEL Process Manager.
Back to Topic List
Before you create the BPEL project, start the Oracle BPEL
Process Manager by clicking Start > Programs > Oracle BPEL Process
Manager 2.0 > Start BPEL PM Server. Start the Oracle BPEL Designer
by clicking Start > Programs > Oracle BPEL Process Manager 2.0
> BPEL PM Designer.
To create the MyLoanFlow BPEL project and WSDL interface, perform the following steps:
|
1. |
To create an Oracle BPEL Project in the BPEL PM Designer,
click File > New > Project, or enter [Shift]-[Alt]-[N].

In the New Project window, select the Oracle BPEL Project wizard and click Next.
|
|
2. |
In the Create a BPEL Project window, enter the following field values:
Note: The MyLoanFlow BPEL process is an asynchronous process. However, the CreditRatingService that is invoked later is a synchronous process.

Click Finish, to create the MyLoanFlow project folder with the following files shown in the Eclipse Navigator:

The MyLoanFlow.bpel
file is opened in the editor window in the Overview mode.

Note: The MyLoanFlow process is created with two Global XML Variables:
 |
The input variable for accepting an input XML document from the client |
 |
The output variable for returning an output XML document to the client |
|
|
3. |
The MyLoanFlow project must provide a suitable description of its interface to its client. In this case, the MyLoanFlow application receives a loan application XML document as input, and returns a loan offer XML document to the client.
To create the interface, edit the contents of the MyLoanFlow.wsdl
file. Double-click MyLoanFlow.wsdl
to open the file in the editor.

Add the following namespace declaration in the start tag of the <definitions> root element in MyLoanFlow.wsdl:
xmlns:s1="http://www.autoloan.com/ns/autoloan"
For example:
<definitions name="MyLoanFlow"
targetNamespace="http://training.oracle.com"
xmlns:tns="http://training.oracle.com"
xmlns:s1="http://www.autoloan.com/ns/autoloan"
xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
>
To define the loan application and loan offer XML document
types, select the entire initial <schema>
element inside the <types>
element, delete the <schema>
element, and replace it with the following <schema>
definition (by using copy and paste):
<schema attributeFormDefault="qualified"
elementFormDefault="qualified"
targetNamespace="http://www.autoloan.com/ns/autoloan"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="loanApplication" type="s1:LoanApplicationType"/>
<element name="loanOffer" type="s1:LoanOfferType"/>
<complexType name="LoanApplicationType">
<sequence>
<element name="SSN" type="string"/>
<element name="email" type="string"/>
<element name="customerName" type="string"/>
<element name="loanAmount" type="double"/>
<element name="carModel" type="string"/>
<element name="carYear" type="string"/>
<element name="creditRating" type="int"/>
</sequence>
</complexType>
<complexType name="LoanOfferType">
<sequence>
<element name="providerName" type="string"/>
<element name="selected" type="boolean"/>
<element name="approved" type="boolean"/>
<element name="APR" type="double"/>
</sequence>
</complexType>
</schema> |
In the WSDL file, locate a <message> element with a name attribute value MyLoanFlowRequestMessage. In the <part> child element, set the element attribute value to s1:loanApplication, as follows:
<message name="MyLoanFlowRequestMessage"> <part name="payload" element="s1:loanApplication"/> </message>
Locate the next <message> element with a name attribute value MyLoanFlowResponseMessage. In the <part> child element, set the element attribute value to s1:loanOffer, as follows:
<message name="MyLoanFlowResponseMessage"> <part name="payload" element="s1:loanOffer"/> </message>
Click File > Save (or enter [Ctrl]+[S]) to save the changes to the WSDL document.
|
|
4. |
Because the WSDL document for MyLoanFlow has been modified,
the BPEL design must be refreshed to pick up the changes. To refresh the
BPEL design, click the MyLoanFlow.bpel
tab and click the refresh link in the lower right corner
of the client box.

Note: Although there is no observable visual change, the WSDL is reloaded.
|
|
5. |
In MyLoanFlow.bpel
in Overview mode, click the variable name output
in the Global XML Variables section to display the Customize
'output' Variable dialog box:

In the Customize 'output' Variable
dialog box, select output
in the name field and replace it with selectedLoanOffer.

Click Done.
Note: In the BPEL Overview
page, the variable is now called selectedLoanOffer.
|
|
6. |
To compile and deploy MyLoanFlow.bpel, click BPEL > Build and Deploy BPEL Project.

The following result should appear in the Console log window: 
|
|
7. |
Test the interface in the BPEL Console, which is started by clicking Start > Programs > Oracle BPEL Process Manager 2.0 > BPEL Console.

To log in to the BPEL Console, select
the Domain value default,
and enter a Password value bpel,
and click Login.

The Oracle BPEL Console home page shows the Dashboard listing all deployed processes.
Note: MyLoanFlow appears in the Name column of the Deployed BPEL Processes section.
|
|
8. |
On the Oracle BPEL Console Dashboard
page, click MyLoanFlow
to display a test HTML form autogenerated with the input message type
specified by the MyLoanFlow.wsdl
document.
This completes a simple test to verify the appearance of the MyLoanFlow interface.
|
Back to Topic List
The CreditRatingService example is supplied with the installed Oracle BPEL Process Manager software, and located in the D:\orabpel\samples\utils\CreditRatingService directory.
To perform a credit validation from MyLoanFlow, you call an external service called CreditRatingService. To enable the CreditRatingService:
To deploy the CreditRatingService and add a BPEL action to invoke the service, perform the following
steps:
|
1. |
To build and deploy the CreditRatingService, start a command window and enter the following commands:
D:
cd \orabpel\samples\utils\CreditRatingService
obant

|
|
2. |
To confirm that the CreditRatingService
has been deployed, refresh the Dashboard page in the
Oracle BPEL Console.

Note: The CreditRatingService BPEL Process entry is listed in the Deployed BPEL Processes Name column.
|
|
3. |
To create a partner link, return to the Oracle BPEL
Designer, view the MyLoadFlow.bpel
process in the Overview page, and click the Add
Partner Link link.

|
|
4. |
In the New PartnerLink Wizard, enter
the following field values:
Click Done.
Note: Leave myRole
empty, and use the associated dialog boxes or pop lists associated to populate the values
for the other fields. If you click the
icon at the end of the wsdlLocation field, then you can
select the CreditRatingService
link to populate the wsdlLocation field by using the
UDDI Browser.

|
|
5. |
To create a new global variable to store the input
data for the CreditRatingService,
click the Add XML Variable link on the Overview
page.

In the New variable Wizard, enter the following field values:
 |
name: crInput |
 |
messageType: services:CreditRatingServiceRequestMessage |

Click Done.
Note: By using the pop list icon in
the messageType field,
you can set its value to services:CreditRatingServiceRequestMessage.
|
|
6. |
To create a global variable for the return value from
the CreditRatingService,
click the Add XML Variable link and set the following
field values in the New variable Wizard:
 |
name: crOutput |
 |
messageType: services:CreditRatingServiceResponseMessage |

Click Done.
|
|
7. |
In Oracle BPEL Designer, click Process Map
to display the MyLoanFlow <process>
in its graphical representation. The initial process flow contains a receive
activity to obtain the client data and an invoke activity
to return a response to the client.

Note: The BPEL Palette
and BPEL Inspector panes are displayed on the right next
to the process map. The BPEL Palette provides entries
for BPEL activities that you can drag from the palette to an appropriate
position in the process map. The BPEL Inspector is used
to set properties of a selected process step.
|
|
8. |
To create a new assign activity, drag the assign
activity from the BPEL Palette to the region between
the initiate (client) and onResult (client)
activities in the Process Map.

Note: When you drag an activity over
the line connecting activities in the process map, a round ball appears
to indicate the target drop position. The resulting process map contains
the assign activity.

|
|
9. |
To name the assign activity, select the new assign
activity, and enter copySSN
in the name property in the BPEL Inspector.

To pass the SSN
value in the input variable
as a parameter to the CreditRatingService,
click the icon
next to the <assign> property heading in the BPEL
Inspector and select Add Copy Rule.

In the Copy Customizer dialog box,
assign the SSN from the
input variable to the ssn
field of the crInput variable.
First, click the From option button and enter the following
fields by using the field pop list icon :
 |
Variable: input |
 |
Part: payload |
 |
XPATH Query: Select
SSN from the loanApplication
document to yield the value:
/autoloan:loanApplication/autoloan:SSN |
Click the To option button and set
the following field values:
 |
Variable: crInput |
 |
Part: payload |
 |
XPATH Query: /services:ssn
Note: This field can be populated by selecting
ssn from the items
in field pop list. |

Click Done.
|
|
10. |
To add an <invoke> activity from
the BPEL Palette, drag invoke to the
region after the copySSN
<assign> rule in the Process Map.

In the BPEL Inspector,
set the following properties:

|
|
11. |
Add another assign activity after the
invoke activity for the CreditRatingService
and set the name property to getCreditRating.

Select the new assign activity, select
Add Copy Rule from the BPEL Inspector section,
and select the Variable option button from the From
section of the Copy Rule dialog box, and enter the field
values:
 |
Variable: crOutput |
 |
Part: payload |
 |
XPATH Query: /services:rating |
In the To section, enter the field values:
 |
Variable: input |
 |
Part: payload |
 |
XPATH Query: /autoloan:loanApplication/autoloan:creditRating |

Click Done.
Note: This is the last activity needed to complete invoking the CreditRatingService as a synchronous BPEL process.
|
Back to Topic List
The CreditRatingService
may be inactive, unavailable, or may return incorrect results. To provide for
these exceptions, you can include fault handling in your BPEL process to make
it more robust. In BPEL, a <scope>
element is used as a wrapper for a <faultHandler>
element. The <faultHandler>
element can contain one or more <catch>
elements for each exception to be handled. A catch-all mechanism can be supplied
for managing unexpected errors.
Note: A <scope> element, in Process Map mode of Oracle BPEL Designer, appears as labeled box enclosing one or more BPEL activities:

The icon at the bottom left of the scope box can be used to add <catch> element fault handlers. For example:
The CreditRatingService
raises a NegativeCredit exception
if it receives an invalid social security number (SSN), for example, the SSN
starts with zero.
To add the fault handler that sets the credit rating value to any negative number, such as -1000, when an invalid SSN is supplied to the CreditRatingService, perform the following steps:
|
1. |
To create a scope, in the BPEL Palette
click More Activities to drag the scope
activity to the region between the receive (initiate)
and assign (copySSN) activities in the Process
Map.

Select the scope activity and enter getCreditRating for the name property in the BPEL Inspector.
|
|
2. |
Click the icon next to the getCreditRating scope activity, and observe the text "Drop Activity Here" in the center of the box:

Drag the assign (copySSN),
invoke (creditRatingService),
and assign (getCreditRating)
activity sequence into the getCreditRating
scope box.

Note: Make sure you maintain the order of the activities in the scope box.
|
|
3. |
Right-click the getCreditRating
scope box handle and select Add XML Variable.

In the New variable Wizard, enter the following fields:
 |
name: crError |
 |
messageType: services:CreditRatingServiceFaultMessage |
Note: The messageType value can be selected from the field pop icon on the right.

Click Done.
|
|
4. |
To add a fault handler to the getCreditRating
scope, click the
(exclamation point) icon at the bottom left of the getCreditRating
scope box and select Add catch.

In the New catch Wizard, select the following field values from their pop lists:
 |
faultName: services:NegativeCredit |
 |
faultVariable: crError |
Note: The faultName value is obtained from the WSDL document for the CreditRatingService Web service.

Click Done.

Note: The Process Map displays the new catch fault handler.
|
|
5. |
In the fault handler, manage the exception by setting
the value -1000 in the input document creditRating
element. To set the credit rating in the input document, drag an assign
activity from the BPEL Palette to the "Drop
activity here" text in the Process Map,
and set the name property to setErrorRating.

Right-click the assign activity and
select Add Copy Rule.
Select the Expression option button
from the From area and enter the value -1000.
Select the To option button and set the following field
values:
 |
Variable: input |
 |
Part: payload |
 |
XPATH Query: /autoloan:loanApplication/autoloan:creditRating |

Click Done.
|
|
6. |
To return to the main BPEL process flow map, click Upper
Element above the process map for the catch fault handler.

Select File > Save to save the changes to MyLoanFlow.bpel.
Note: You are now ready to deploy the MyLoanFlow BPEL process to Oracle BPEL Process Manager to invoke and test the process flow. |
Back to Topic List
To deploy the completed MyLoanFlow BPEL process to Oracle BPEL Process Manager by using Oracle BPEL Designer, and view the deployed process in Oracle BPEL Console, perform the following steps:
|
1. |
In the Oracle BPEL Designer, click
Overview in the BPEL Designer tab page of
the MyLoanFlow.bpel file
and click BPEL > Build and Deploy BPEL Project in
the main menu. Alternatively, click the
icon.

Note: The result of the build-and-deploy
operation is visible in the Eclipse Console tab window
below the BPEL Designer area. Ensure that you see the
words "BUILD SUCCESSFUL"
in the Console window before you continue with subsequent
steps.
|
|
2. |
In the Oracle BPEL Console,
click the Dashboard tab page containing the deployed BPEL
processes. You should see the CreditRatingService
and MyLoanFlow processes
listed in the name column of Deployed BPEL Processes,
in addition to the TaskManager
process. The In-Flight BPEL Process Instances column
should be empty.

Note: The four tab pages available on the
Oracle BPEL Console page are:
|
Back to Topic List
The MyLoanFlow
BPEL application deployed to Oracle BPEL Process Manager can
be used to test the invocation of the CreditRatingService
by using Oracle BPEL Console. The first test, which yields
a successful credit rating check, uses a valid 9-digit social security number
(SSN), for example, 123456789. The second test yields a negative credit rating
when an invalid SSN beginning with a leading zero is entered, for example, 0123455678.
To test the MyLoanFlow BPEL process, perform the following steps:
|
1. |
In the Dashboard tab page of Oracle
BPEL Console, click the MyLoanFlow
link in the name column in the Deployed BPEL
Processes section.

|
|
2. |
The BPEL Processes tab page is displayed
with the Initiate subtab page containing an HTML form generated
to accept input values for each element in a loan application XML document.
The HTML form is used to initiate the test of the BPEL process by using
the input values supplied. Enter 123456789
in the SSN field, and click Post XML Message
to initiate the first test.

Note: The values in the HTML form fields become the text values in the loan application XML document that is sent to the MyLoanFlow BPEL process.
|
|
3. |
The Initiate subtab page in the BPEL
Processes tab page shows that the test has been initiated. The
BPEL process instance number is displayed along with three icons and their
textual links (Visual Flow, Audit Instance, Debug Instance). Any of these
links can be used to monitor the entire BPEL process flow.

Note: The text "Instance
'#:#:#:-#' is being processed asynchronously" indicates
that the MyLoanFlow BPEL
process is an asynchronous process, as specified when creating the project
with the Asynch
BPEL Process template. However, the activity used to invoke the
CreditRatingService, within
MyLoanFlow, is executed
synchronously.
|
|
4. |
To check the outcome of this first test,
click the Audit Instance link and in the Instances
tab page to see the activities of the BPEL process in the Audit
subtab page.

Note: Process steps (activities) in the MyLoanFlow BPEL process are shown in the sequence in which they occur.
|
|
5. |
To examine the loan application XML document
input for this test, click the More link at the end of
the client (initiate) activity in the Audit
subtab page.

Note: The input payload has a <loanApplication> element containing an <SSN> child element with a text value of 123456789, which was supplied in the HTML form initiating the process.
|
|
6. |
Scroll the Audit page
to view the activities in the getCreditRating
scope, click the More link to expand the information
for the copySSN activity to examine the contents of the
crInput variable.

The crInput variable, which is passed to the CreditRatingService invoked in the next step, contains the SSN value 123456789 that was copied from the <SSN> element in <loanApplication> input payload by the copySSN assign activity.
|
|
7. |
Scroll the Audit page
to the creditRatingService (process) activity, click
the More link to examine the crInput
value supplied to and the crOutput
value returned by the CreditRatingService
service invoked.

Note: The crInput has the value 123456789 in its <ssn> child element, and crOutput value has a value of 560 in the <rating> child element. The value 560 is the credit rating value returned from the CreditRatingService.
|
|
8. |
Finally, scroll down to the getCreditRating
assign activity and click the More link to examine the
modified loan application XML document. The getCreditRating
assign ac | |