This chapter will help you learn how to handle system exceptions and business exceptions in Oracle BPM 11g. Exceptions can occur in tasks or in the subprocess. You will explore how exceptions are thrown and how exceptions are caught, for a task and for a subprocess. In addition, you will infuse exception handling for task and subprocesses using either the boundary catch
event or an event subprocess.
Errors can happen in a process. They might be caused either due to system failure or maybe a business issue. When an error occurs due to system failure, software failure, hardware failure, and so on—broadly speaking due to infrastructure failure, they are termed as system errors. Infrastructure issues such as 'database not available', 'server not up and running', and so on, cause system errors.
Any errors due to problems in process behavior (say that a process was designed in such a way that if inventory doesn't have the stock availability, then the quotation cannot be processed normally and this would lead to a process exception) are called business exceptions, as they are caused due to interference of problems in your regular process flow.
System exceptions are used to handle system errors and business exceptions are used to handle process errors.
In this chapter, you will explore the following scenarios:
- Stock unavailability leads to a business exception that is handled by a subprocess. You will use the
catch error boundary
event to handle this business exception. - You will invoke a service in which unavailability will lead to a system exception. You will use the following mechanism to handle the following system exceptions:
- You will use fault-policy framework to handle system exceptions
- You will use the subprocess
Error handled by Event Sub process Boundary
event - The
Catch Timer
event will handle timeout exceptions
- Handling business exceptions in a task
You have a service, StockValidator_EBS
, a BPEL web service that checks for the availability of stock (items) based on PRODUCTID. And as a response, if the item is not available in the inventory, it shows a Business Error SOPFault.
You can create a StockValidator_EBS BPEL web service, based on a PLSQL procedure, which checks for item availability in the MTL_SYSTEM_ITEMS table and returns SOPFault
if the item is not available.
You will implement a service task in your BPM process to invoke this StockValidator_EBS service.
If Stock is available: Then the process token follows the normal path
Else, if Stock is not available: Then the service task throws an error
You will use the Boundary Catch Event to handle the exception, in this case. Boundary error catch events enable you to resume the main process flow after handling the exception.
In this section, you will learn to handle business exceptions, as follows:
- Go to JDeveloper | Application Navigator | SalesToContractDemo Project and click on the SalesToContract process.
- Go to Component palette | BPM | Activities and click the activity
SubProcess
. - Click anywhere in the salesrepresentative swimlane to create a subprocess in it.
- This will open the Subprocess | Properties dialog. Enter the name
Stockvalidation_ExceptionHandler
for the subprocess and click OK. - For the Start and End activities in the subprocess, click on them and enter
StartStockvalidationException
and EndStockvalidationException
as Name for the Start and End activities, respectively. Keep their Implementation type as None. - Go to Component Palette | BPM | Activities and click on the Script activity.
- Click on the subprocess between the Start and End activities. This will create a Script Task in the subprocess.
- In the Script task properties, enter
AssignStockStatus
as the name, and in the Implementation tab, check Data Associations and drop quote as variable. - Assign StockvalidationFailed as a value to quote | quoteRequestStatus, as shown in the preceding screenshot.
- Click OK twice to return to SubProcess.
- Click on Component Palette | BPM | Interactive user task.
- Click between AssignStockStatus script and EndStockValidationException.
- This will open User task properties. In the Basic tab, enter Name of the User task as StockValidation.
- In the Implementation tab, create a Human Task
StockValidationNotification
and assign the object quote as input, as shown in the following screenshot: - Click OK twice and you are back to the subprocess.
- Go to BPM Project navigator and in Business catalog | Human Tasks, you can find the StockValidationNotification task. Double-click it and let Outcome be set to OK; click Auto-Generate task form to generate a UI for this task.
- In the Create Project dialog, enter
StockvalidatorUI
as the Project Name and click OK. - Once the UI is created, you can validate it from Application Navigator | SalesToContractDemo project.
- Create a Process Data object named StockAvailability, of type String, and click OK.
- Go to Component Palette | BPM | Activities and click Service Task.
- Click on the designer, between Enter Quote and Check Customer. This will open the service task Properties.
- Enter
ValidateStock
for the service task Name, and click on the Implementation tab. - In Service Task, on the Implementation tab, choose Service Call
- Click on the "browse" button to the right of Name to select the service Stockvalidator_EBS and click OK on the Type dialog. The operation process will pop-up automatically.
- Check Data Associations and click the pencil button to edit.
- Drag-and-drop quote from the Data objects as an input to service task, and the StockAvailability Data object into the output, which gets populated by processResponse | result.
- Click OK twice, and you are back to the designer.
- When you use the service Stockvalidator_EBS, you will find that SOPFault errors get infused in Business Catalog, as shown in the following screenshot:
- Go to Component Palette | BPM | Gateways and click Exclusive Gateway.
- Click between the ValidateStock service task and Customer Check rule. This will open the Properties dialog. Enter
StockAvailable
as the gateway name. - Create a sequence unconditional flow from ValidateStock to StockAvailable.
- Go to Component Palette | BPM | Events, click Terminate End Event, and name it
EndProcess
. - Click to the right of the StockAvailable gateway and create an unconditional flow from StockAvailable to the EndProcess End event.
- Create an unconditional flow from the StockAvailable gateway to CustomerCheck rule task and name it
Yes
. - Create a conditional flow from the StockAvailable gateway to the EndProcess activity. Choose Simple Expression and enter the expression, as follows, and then click OK:
- Go to Component Palette | BPM | Events, click on the Error Catch event, and drag it on to the ValidateStock service task. This will open the Properties dialog.
- Let the implementation type be Error and click the "browse" button to the right of Exception, to browse for the errors. Select SOPFault from the list, as shown in the preceding screenshot, and then click OK.
- Add Default sequence from ValidateStock to the Stockvalidation_ExceptionHandler option.
- When you have finished the preceding steps, click Save.
BPMN service engine runs the task ValidateStock, which calls StockValidator_EBS. StockValidator_EBS will raise an error if the stock is not available. The task fails with a SOAP error, which will be converted by BPMN service engine into an exception.
When an error occurs while running the task ValidateStock, which has a boundary error catch event attached, BPMN Service Engine will follow the flow defined by the boundary error catch event. The exception handling flow, defined by the boundary error catch event, can rejoin the main process flow if stock is available, or end the process.