Handle faults by two ways
1. Using Catch & CatchAll blocks
2. Using Fault Handling Framework
FHF:
Fault
handling allows a BPEL process service component to handle error messages or
other exceptions returned by outside web services, and to generate error
messages in response to business or runtime faults. There are two categories of
BPEL faults:
1. Business faults – Business faults are
application-specific faults that are generated when there is a problem with the
information being processed (for example, when a member is not found in the
database).
2. Runtime faults – Runtime faults are
the result of problems within the running of the BPEL process service component
or web service (for example, data cannot be copied properly because the
variable name is incorrect). These faults are not user-defined, and are thrown
by the system. They are generated for a variety of reasons, including the
following:
• The process tries to use a value
incorrectly.
• A logic error occurs (such as an
endless loop).
• A Simple Object Access Protocol
(SOAP) fault occurs in a SOAP call.
• An exception is thrown by the
server.
Handling
Faults with the Fault Management Framework:
Oracle SOA
Suite provides a generic fault management framework for handling faults in BPEL
processes.
If a fault
occurs during runtime in an invoke activity in a process, the framework catches
the fault and performs a user-specified action defined in a fault policy file
associated with the composite or component.
• The fault management framework
catches all faults (business and runtime) for an invoke activity.
• A fault policy file defines fault
conditions and their corresponding fault recovery actions. Each fault condition
specifies a particular fault or group of faults, which it attempts to handle,
and the corresponding action for it. A set of actions is identified by an ID in
the fault policy file.
• A set of conditions invokes an
action (known as a fault policy).
• Email or JMS notify users of errors
associated with a condition.
• A fault policy bindings file
associates the policies defined in the fault policy file with the following:
1. SOA composite applications
2. BPEL process and Oracle Mediator
service components
3. Reference binding components for BPEL
processes and Oracle Mediator service components
-> We use this framework only to handle
invocation faults; we can’t use this framework to handle all types of fault.
-> This
can be used for BPEL as well as Mediator component.
-> We should use this only for two BPEL templates (Async and OneWay).
fault-policies.xml
<faultPolicies xmlns="http://schemas.oracle.com/bpel/faultpolicy">
<faultPolicy version="2.0.1" id="CompositeFaultPolicy" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.oracle.com/bpel/faultpolicy">
<Conditions>
<!-- Conditions can be fine grained to include Actions based on Error Codes. If a remotefault occurs check whether it is a WSDLReadingError. If yes then rethrow it else retry it."-->
<faultName xmlns:bpelx="http://schemas.oracle.com/bpel/extension" name="bpelx:remoteFault">
<condition>
<test>$fault.code/code="WSDLReadingError"</test>
<action ref="ora-rethrow-fault"/>
</condition>
<condition>
<action ref="ora-retry"/>
</condition>
</faultName>
<faultName xmlns:bpelx="http://schemas.oracle.com/bpel/extension" name="bpelx:bindingFault">
<condition>
<action ref="java-fault-handler"/>
</condition>
</faultName>
<faultName xmlns:bpelx="http://schemas.oracle.com/bpel/extension" name="bpelx:runtimeFault">
<condition>
<action ref="java-fault-handler"/>
</condition>
</faultName>
</Conditions>
<Actions>
<!-- This Action will invoke a Custom Java Class to process Faults. Also depending upon the returnValueanother action will be invoked whic is specified by the ref attribute. This demosntrates chaining of Actions"-->
<Action id="java-fault-handler">
<javaAction className="com.beatech.faultapp.CustomFaultHandler" defaultAction="ora-human-intervention" propertySet="properties">
<returnValue value="Manual" ref="ora-human-intervention"/>
</javaAction>
</Action>
<!-- This Action will mark the instance as "Pending for Recovery" in the EM console -->
<Action id="ora-human-intervention">
<humanIntervention/>
</Action>
<!--This is an action will bubble up the fault to the Catch Blocks-->
<Action id="ora-rethrow-fault">
<rethrowFault/>
</Action>
<!--This action will attempt 3 retries with intervals of 120 seconds -->
<Action id="ora-retry">
<retry>
<retryCount>3</retryCount>
<retryInterval>120</retryInterval>
<retryFailureAction ref="java-fault-handler"/>
</retry>
</Action>
<!--This action will cause the instance to terminate-->
<Action id="ora-terminate">
<abort/>
</Action>
</Actions>
<!--Properties can be used to pass values to the Java class as a Map that can be used by the Class -->
<Properties>
<propertySet name="properties">
<property name="myProperty1">propertyValue1</property>
<property name="myProperty2">propertyValue2</property>
<property name="myPropertyN">propertyValueN</property>
</propertySet>
</Properties>
</faultPolicy>
</faultPolicies>
<javaaction classname="com.beatech.faultapp.CustomFaultHandler" defaultaction="ora-rethrow">
<returnValue ref="ora-rethrow" value="Rethrow"/>
<returnvalue ref="ora-terminate" value="Abort"/>
<returnvalue ref="ora-retry" value="Retry"/>
<returnvalue ref="ora-human-intervention" value="Manual"/>
</javaaction>
fault-bindings.xml
SOA Tier -> Faults -> Fault Policy Document
Go to composite.xml
file and click on edit composite Fault policies option
Once you click on OK a fault-bindings.xml is automatically generated according the selection you have made in the previous window. It would be created in you project as fault-bindings.xml.
A set of conditions
invokes an action (known as fault policy).
| Q) Which static routing rule support fault policy? |
| Parallel rules only. |
Oracle SOA Suite Fault Handling Best Practices
1. Create fault (catch block) for each partner link. For each partner link, have a catch block for all possible errors. Idea is not to let errors go to catchAll block.
2. CatchAll should be kept for all errors that cannot be thought of during design time.
3. Classify errors into various types – runtime, remote, binding, validation, Business errors etc.
5. Use Catch Block for non-partner link error.
6. Every retry defined in fault policy causes a commit of the transaction. Dehydration will be reached and threads released.
8. Handle Rollback fault by providing ‘No Action’ in fault policy.
9. Remember – Receive, OnMessage, On Alarm, Wait, CheckPoint (Activity for forcing Java thread to store its current state to Dehydration store) will cause storing of current state to dehydration store and threads will be released.
10. Always use MDS to store fault policies and bindings to increase their reuse for multiple composites and projects.
Important points while handling error
• If the error occurred in synchronous need to return minimum error information like error code, description and message id
• If the services are more alike Asynchronous then we need to have common error logging/audit framework which will receive errors through DB or JMS ,Based on error types we can notify or persist the error
• Fault context variable is available only in error handler.
• While designing fault schema object consider the below important points
• Error Code
• Error Description
• Error Reference (i.e. Service Name and Which operation)
• Instance Id (This information you can get inbuilt function fn:uuid)
• Error Type (System Error or Business Error)
• Error Notification