|Oracle® Fusion Middleware Developer's Guide for Oracle SOA Suite
11g Release 1 (11.1.1)
Part Number E10224-03
This chapter describes how to use events and timeouts. Because web services can take a long time to return a response, a BPEL process service component must be able to time out and continue with the rest of the flow after a period of time.
This chapter includes the following sections:
This chapter provides an example of how to program a BPEL process service component to wait one minute for a response from a web service named Star Loan that provides loan offers. If Star Loan does not respond in one minute, then the BPEL process service component automatically selects an offer from another web service named United Loan. In the real world, the time limit is more like 48 hours. However, for this example, you do not want to wait that long to see if your BPEL process service component is working properly.
Because asynchronous web services can take a long time to return a response, a BPEL process service component must be able to time out, or give up waiting, and continue with the rest of the flow after a certain amount of time. You can use the pick activity to configure a BPEL flow to either wait a specified amount of time or to continue performing its duties. To set an expiration period for the time, you can use the wait activity.
The pick activity provides two branches, each one with a condition. The branch that has its condition satisfied first is executed. In the following example, one branch's condition is to receive a loan offer, and the other branch's condition is to wait a specified amount of time.
Figure 14-1 provides an overview. The following activities take place (in order of priority):
An invoke activity initiates a service, in this case, a request for a loan offer from Star Loan.
The pick activity begins next. It has the following conditions:
This condition has code for receiving a reply in the form of a loan offer from the Star Loan web service. The onMessage code matches the code for receiving a response from the Star Loan web service before a timeout was added.
This condition has code for a timeout of one minute. This time is defined as
PT1M, which means to wait one minute before timing out. In this timeout setting:
S stands for seconds
M for one minute
H for hour
D for day
Y for year
In the unlikely event that you want a time limit of
3 days, and
15 seconds, you enter it as
PT1Y3D15S. The remainder of the code sets the loan variables selected and approved to
false, sets the annual percentage rate (APR) at
0.0, and copies this information into the
The time duration format is specified by the BPEL standard. For more detailed information on the time duration format, see the duration section of the most current XML Schema Part 2: Datatypes document at:
The pick activity condition that completes first is the one that the BPEL process service component executes. The other branch then is not executed.
Figure 14-1 Overview of the Pick Activity
To create a pick activity:
In the SOA Composite Editor, double-click the BPEL process service component.
From the Component Palette, drag a Pick activity into the designer.
Expand the Pick activity.
The Pick activity includes the onMessage (envelope icon) and onAlarm (alarm clock icon) branches. Figure 14-2 provides an example.
Figure 14-2 Pick Activity
Double-click the OnAlarm branch of the pick activity and set its time limit to
1 minute instead of
1 hour. Figure 14-3 provides an example.
Figure 14-3 OnAlarm Branch
Double-click the onMessage branch. Figure 14-4 provides an example.
Figure 14-4 onMessage Branch
Edit its attributes to receive the response from the loan service.
The code segment in Example 14-1 defines the
pick activity for this operation after design completion:
Example 14-1 Pick Activity
<pick> <!-- receive the result of the remote process --> <onMessage partnerLink="LoanService" portType="services:LoanServiceCallback" operation="onResult" variable="loanOffer"> <assign> <copy> <from variable="loanOffer" part="payload"/> <to variable="output" part="payload"/> </copy> </assign> </onMessage> <!-- wait for one minute, then timesout --> <onAlarm for="PT1M"> <assign> <copy> <from> <loanOffer xmlns="http://www.autoloan.com/ns/autoloan"> <providerName>Expired</providerName> <selected type="boolean">false</selected> <approved type="boolean">false</approved> <APR type="double">0.0</APR> </loanOffer> </from> <to variable="loanOffer" part="payload"/> </copy> </assign> </onAlarm> </pick>
The wait activity allows a process to wait for a given time period or until a time limit has been reached. Exactly one of the expiration criteria must be specified. A typical use of this activity is to invoke an operation at a certain time. You typically enter an expression that is dependent on the state of a process.
When specifying a time period for waiting, note the following:
Wait times cannot be guaranteed if they are scheduled with other events that require processing. Due to this additional processing, the actual wait time can be greater than the wait time specified in the BPEL process.
Wait times of less than two seconds are ignored by the server. Wait times above two seconds, but less than one minute, may not get executed in the exact, specified time. However, wait times in minutes do execute in the specified time.
The default value of
2 seconds for wait times is specified with the MinBPELWait property in the System MBean Browser of Oracle Enterprise Manager Fusion Middleware Control Console. You can set this property to any value and the wait delay is bypassed for any waits less than MinBPELWait.
Note:Quartz version 1.6 is supported for scheduling expiration events on wait activities.
You can specify the minimum time duration for a BPEL process to perform a wait that involves a dehydration. If the wait duration is less than or equal to the value, BPEL continues executing activities in the same thread and transaction.
From the SOA Infrastructure menu, select SOA Administration > BPEL Properties.
At the bottom of the BPEL Service Engine Properties page, click More BPEL Configuration Properties.
In the Value field, specify a value in seconds.
To create a wait activity:
From the Component Palette, drag a Wait activity into the designer.
Double-click the Wait activity to display the Wait dialog.
In the For section, enter the amount of time for which to wait.
In the Until section, select the deadline for which to wait, as shown in Figure 14-5.
Figure 14-5 Wait Dialog
Exactly one of the expiration criteria must be specified, as shown in Example 14-2.
For synchronous processes that connect to a remote database, you must increase the SyncMaxWaitTime timeout property in the System MBean Browser of Oracle Enterprise Manager Fusion Middleware Control Console.
For information on setting this property, see Section 7.3, "Specifying Timeout Values."