Mediator Error Handling – Java Call from Fault Policy File

By rajesh | January 7, 2014 | 0 Comment

We use fault handling framework to handle errors in BPEL & Mediator components, In BPEL we can also caught faults using Catch & CatchAll block but there is no such provision in Mediator. In Mediator we have to use fault policy and fault binding files to handle all types of error.

In Mediator, fault name is same for all types of fault so in fault policy file we need to caught only one fault for mediator.

<faultName xmlns:medns=”” name=”medns:mediatorFault”>

Note: Fault policies are applicable to parallel routing rules only. For sequential routing rules, the fault goes back to the caller. It is the responsibility of the caller to handle the fault.

In this post, we show you how to call java code from fault policy file whenever there is any fault in mediator.

Let us first create one java code which we want to call from fault policy file. To do that create a project in Jdeveloper and add fabric-runtime.jar file to project libraries.

Farbric-runtime.jar file can be found at below location.



Our custom class should implement IFaultRecoveryJavaClass interface which has two functions defined inside it.

oracle.integration.platform.faultpolicy.IFaultRecoveryJavaClass {

public void handleRetrySuccess(IFaultRecoveryContext ctx);

public String handleFault(IFaultRecoveryContext ctx);


The handleRetrySuccess method is invoked upon a successful retry attempt and the handleFault method is invoked to execute a policy of type javaAction.


There are many functions defined for IFaultRecoveryContext interface as mentioned below. So you can use required function as per your requirement.

public interface IFaultRecoveryContext {


* Gets implementation type of the fault.

* @return


public String getType();


* @return Get property set of the fault policy action being executed.


public Map getProperties();


* @return Get fault policy id of the fault policy being executed.


public String getPolicyId();


* @return Name of the faulted reference.


public String getReferenceName();


* @return Port type of the faulted reference link.


public QName getPortType();



Our custom class should look like below.



package faultpolicyjavacode;


import java.util.Map;

import oracle.integration.platform.faultpolicy.IFaultRecoveryContext;

import oracle.integration.platform.faultpolicy.IFaultRecoveryJavaClass;


public class TestClass implements IFaultRecoveryJavaClass {

public void handleRetrySuccess(IFaultRecoveryContext iFaultRecoveryContext) {



public String handleFault(IFaultRecoveryContext iFaultRecoveryContext) {


System.out.println(“Fault policy id: ” +



return “OK”;



Now compile your custom class, prepare jar file and deploy jar file to lib folder of soa server.

You need to copy jar file to below path

Path: ($ORACLE_MIDDLEWARE_HOME/user_projects/domains/$domain_name/lib).


Now we create one sample mediator project. Create a new project in Jdeveloper and add synchronous mediator to it. Now add fault-policy file to it, your fault-policy file should look like below.

<?xml version=”1.0″ encoding=”UTF-8″?>


<faultPolicy version=”2.0.1″ id=”Mediator_ServiceFaults”>


<faultName xmlns:medns=””



<action ref=”ora-java”/>





<Action id=”ora-java”>

<javaAction className=”faultpolicyjavacode.TestClass”


<returnValue value=”OK” ref=”ora-human-intervention”/>







Now create fault-bindings.xml file and add below content to it.

<?xml version=”1.0″ encoding=”UTF-8″?>

<faultPolicyBindings version=”2.0.1″



<composite faultPolicy=”Mediator_ServiceFaults”/>



As explained earlier we can only handle mediator fault when we use “Parallel” routing rules. So add a parallel routing route and call your target service. When you do request mapping, do some deliberate mapping so that your mediator failed during runtime, In our case we used local dvm file in mapping which really don’t exist.


Now you need to refer fault-policies.xml and fault-bindings.xml files in composite.xml file.



Deploy your composite and see the testing result.

In soa server console, you should be able to see below message.


Fault policy id: Mediator_ServiceFaults



You can see attached sample code below.



Leave a Reply

Your email address will not be published. Required fields are marked *