Chapter 8. Exception Management

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.

We will cover the following topics to gain expertise in exception management:

  • Handling business exceptions in a task
  • Handling business exceptions in a subprocess
  • Handling a system exception-Fault Management Framework
  • Handling the timeout exception-Timer event
  • Faulting the process

Introduction

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.

How to do it...

In this section, you will learn to handle business exceptions, as follows:

  1. Go to JDeveloper | Application Navigator | SalesToContractDemo Project and click on the SalesToContract process.
  2. Go to Component palette | BPM | Activities and click the activity SubProcess.
  3. Click anywhere in the salesrepresentative swimlane to create a subprocess in it.
  4. This will open the Subprocess | Properties dialog. Enter the name Stockvalidation_ExceptionHandler for the subprocess and click OK.
    How to do it...
  5. 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.
  6. Go to Component Palette | BPM | Activities and click on the Script activity.
  7. Click on the subprocess between the Start and End activities. This will create a Script Task in the subprocess.
  8. In the Script task properties, enter AssignStockStatus as the name, and in the Implementation tab, check Data Associations and drop quote as variable.
    How to do it...
  9. Assign StockvalidationFailed as a value to quote | quoteRequestStatus, as shown in the preceding screenshot.
  10. Click OK twice to return to SubProcess.
  11. Click on Component Palette | BPM | Interactive user task.
  12. Click between AssignStockStatus script and EndStockValidationException.
  13. This will open User task properties. In the Basic tab, enter Name of the User task as StockValidation.
  14. In the Implementation tab, create a Human Task StockValidationNotification and assign the object quote as input, as shown in the following screenshot:
    How to do it...
  15. Click OK twice and you are back to the subprocess.
    How to do it...
  16. 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.
    How to do it...
  17. In the Create Project dialog, enter StockvalidatorUI as the Project Name and click OK.
  18. Once the UI is created, you can validate it from Application Navigator | SalesToContractDemo project.
  19. Create a Process Data object named StockAvailability, of type String, and click OK.
    How to do it...
  20. Go to Component Palette | BPM | Activities and click Service Task.
  21. Click on the designer, between Enter Quote and Check Customer. This will open the service task Properties.
    How to do it...
  22. Enter ValidateStock for the service task Name, and click on the Implementation tab.
  23. In Service Task, on the Implementation tab, choose Service Call
  24. 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.
    How to do it...
  25. Check Data Associations and click the pencil button to edit.
  26. 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.
    How to do it...
  27. Click OK twice, and you are back to the designer.
  28. When you use the service Stockvalidator_EBS, you will find that SOPFault errors get infused in Business Catalog, as shown in the following screenshot:
    How to do it...
  29. Go to Component Palette | BPM | Gateways and click Exclusive Gateway.
  30. Click between the ValidateStock service task and Customer Check rule. This will open the Properties dialog. Enter StockAvailable as the gateway name.
  31. Create a sequence unconditional flow from ValidateStock to StockAvailable.
    How to do it...
  32. Go to Component Palette | BPM | Events, click Terminate End Event, and name it EndProcess.
  33. Click to the right of the StockAvailable gateway and create an unconditional flow from StockAvailable to the EndProcess End event.
  34. Create an unconditional flow from the StockAvailable gateway to CustomerCheck rule task and name it Yes.
  35. 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:
    StockAvailability == "UnAvailable"
    
  36. 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.
    How to do it...
  37. 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.
  38. Add Default sequence from ValidateStock to the Stockvalidation_ExceptionHandler option.
    How to do it...
  39. When you have finished the preceding steps, click Save.

How it works...

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.255.36