Tuesday, August 16, 2016

SOA: Fault Handling: Creating a fault policy

Fault handling is a very interesting concept in SOA. It is analogous to Exception Handling per OOPs concepts.

Fault Policy is defined to handle runtime fault exceptions. You can define actions to execute based on the type of exception. Here's a 1-0-1 on defining a simple fault policy:

1 -  Create the fault-policies.xml file

Right Click on the Project > Select From Gallery > Select SOA Tier/Faults > Fault Policy Document > Click Ok

This creates a fault-policies.xml within the project/SOA folder.

2 - Editing the fault policy

Open the fault-policies.xml to edit the fault policy.

Provide a unique ID to the fault policy:
<faultPolicy id="MyFaultPolicy">

Let's define the fault policy to retry 3 time at a interval for 120 sec for any runtime fault:

<faultName>
    <condition>
        <action ref="ora-retry"/>
    </condition>
</faultName>

This means for any fault (since no name is specified) the action "ora-retry" will be executed. The action "ora-retry" is a custom action here. We will need to define what ora-retry means.

3 - Define ora-retry

Add the following action to the fault policy file.

<Action id="ora-retry">
    <retry>
        <retryCount>2</retryCount>
        <retryInterval>60</retryInterval>
        <exponentialBackoff/>
        <retryFailureAction ref="default-terminate"/>
    </retry>
</Action>

4 - Review the Fault Policy

Here is how the fault-policies.xml document looks:

<?xml version="1.0" encoding="UTF-8"?>
<faultPolicies xmlns="http://schemas.oracle.com/bpel/faultpolicy" xmlns:bpelx="http://schemas.oracle.com/bpel/extension" xmlns:medns="http://schemas.oracle.com/mediator/faults" xmlns:rjm="http://schemas.oracle.com/sca/rejectedmessages">
    <faultPolicy id="MyFaultPolicy">
        <Conditions>
            <faultName>
                    <action ref="ora-retry"/>
            </faultName>
        </Conditions>
        <Actions>
            <Action id="default-termination">
                <abort/>
            </Action>
            <Action id="ora-retry">
                <retry>
                    <retryCount>2</retryCount>
                    <!--<retryInterval>43200</retryInterval>-->
                    <retryInterval>60</retryInterval>
                    <exponentialBackoff/>
                    <retryFailureAction ref="custom-java-send-email"/>
                    <retrySuccessAction ref="default-termination"/>
                </retry>
            </Action>
        </Actions>
    </faultPolicy>
</faultPolicies>


5 - Create the Fault Bindings

Now the fault policy is created. However, the job is not done yet. We need to associate the fault policy to the composite. Thus, whenever there is a fault in the composite the fault policy "MyFaultPolicy" will be invoked.

To do this we need to create the fault-bindings.xml file within Project/SOA folder as follows:

<?xml version="1.0" encoding="UTF-8"?>
<faultPolicyBindings version="2.0.1" xmlns="http://schemas.oracle.com/bpel/faultpolicy">
    <composite faultPolicy="MyFaultPolicy" />
</faultPolicyBindings>




Please share your feedback below. Hope this is helpful!


CaptiveCode


No comments:

Post a Comment