Skip Headers
Oracle® Fusion Middleware Developer's Guide for Oracle SOA Suite
11g Release 1 (11.1.1)

Part Number E10224-03
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Index
Go to Feedback page
Contact Us

Go to previous page
Go to next page
View PDF

14 Using Events and Timeouts in BPEL Processes

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:

14.1 Introduction to Event and Timeout Concepts

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.

14.2 Creating a Pick Activity to Select Between Continuing a Process or Waiting

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):

  1. An invoke activity initiates a service, in this case, a request for a loan offer from Star Loan.

  2. The pick activity begins next. It has the following conditions:

    • onMessage

      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.

    • onAlarm

      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 1 year, 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 loanOffer variable.

      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:
  3. 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

Description of Figure 14-1 follows
Description of "Figure 14-1 Overview of the Pick Activity"

14.2.1 How To Create a Pick Activity

To create a pick activity:

  1. In the SOA Composite Editor, double-click the BPEL process service component.

  2. From the Component Palette, drag a Pick activity into the designer.

  3. 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

    Description of Figure 14-2 follows
    Description of "Figure 14-2 Pick Activity"

  4. 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

    Description of Figure 14-3 follows
    Description of "Figure 14-3 OnAlarm Branch"

  5. Click OK.

  6. Double-click the onMessage branch. Figure 14-4 provides an example.

    Figure 14-4 onMessage Branch

    Description of Figure 14-4 follows
    Description of "Figure 14-4 onMessage Branch"

  7. Edit its attributes to receive the response from the loan service.

14.2.2 What Happens When You Create a Pick Activity

The code segment in Example 14-1 defines the pick activity for this operation after design completion:

Example 14-1 Pick Activity

        <!--  receive the result of the remote process -->
        <onMessage partnerLink="LoanService"
            operation="onResult" variable="loanOffer">
            <from variable="loanOffer" part="payload"/>
            <to variable="output" part="payload"/>
       <!--  wait for one minute, then timesout -->
       <onAlarm for="PT1M">
                        <loanOffer xmlns="">
                            <selected type="boolean">false</selected> 
                            <approved type="boolean">false</approved> 
                            <APR type="double">0.0</APR> 
                    <to variable="loanOffer" part="payload"/>

14.3 Creating a Wait Activity to Set an Expiration Time

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:


Quartz version 1.6 is supported for scheduling expiration events on wait activities.

14.3.1 How To Specify the Minimum Wait Time

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.

  1. From the SOA Infrastructure menu, select SOA Administration > BPEL Properties.

  2. At the bottom of the BPEL Service Engine Properties page, click More BPEL Configuration Properties.

  3. Click MinBPELWait.

  4. In the Value field, specify a value in seconds.

  5. Click Apply.

  6. Click Return.

14.3.2 How to Create a Wait Activity

To create a wait activity:

  1. From the Component Palette, drag a Wait activity into the designer.

  2. Double-click the Wait activity to display the Wait dialog.

  3. In the For section, enter the amount of time for which to wait.

  4. In the Until section, select the deadline for which to wait, as shown in Figure 14-5.

14.3.3 What Happens When You Create a Wait Activity

Exactly one of the expiration criteria must be specified, as shown in Example 14-2.

Example 14-2 Wait Activity

<wait (for="duration-expr" | until="deadline-expr") standard-attributes>

14.4 Setting Timeouts for Synchronous Processes

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."