In this previous post about Error handling in SOA Suite 11G, I explained how you can create your own fault handling policy for your BPEL process.
This post describes how to call a Java action for error handling.
First we are going to create a new project in JDeveloper witch contains the Java class that will be called when an error occurs.
Add the following libraries to your project: SOA Runtime and BPEL Runtime.
Create a new Java class and let it implement the following interface: oracle.integration.platform.faultpolicy.IFaultRecoveryJavaClass.
The IFaultRecoveryJavaClass interface defines two operations: handleRetrySuccess and handleFault.
The handleRetrySuccess method is invoked upon a successful retry attempt and the handleFault method is invoked to execute a policy of type javaAction.
public interface IFaultRecoveryJavaClass {
void handleRetrySuccess(IFaultRecoveryContext iFaultRecoveryContext) { }
java.lang.String handleFault(IFaultRecoveryContext iFaultRecoveryContext) { }
}
The IFaultRecoveryContext contains methods for retrieving specified details about the error, the instance and properties you can define in the <Properties> section of the fault-policies.xml file (explained later).
Here follows a Java class example.
package nl.whitehorses.soa.demo;
import java.util.ArrayList;
import java.util.Map;
import oracle.integration.platform.faultpolicy.IFaultRecoveryContext;
import oracle.integration.platform.faultpolicy.IFaultRecoveryJavaClass;
public class FaultHandler implements IFaultRecoveryJavaClass {
public void handleRetrySuccess(IFaultRecoveryContext iFaultRecoveryContext) {
System.out.println("This is for retry success");
handleFault(iFaultRecoveryContext);
}
public String handleFault(IFaultRecoveryContext iFaultRecoveryContext) {
//print all fault details
System.out.println("==========");
System.out.println("Fault policy id: " + iFaultRecoveryContext.getPolicyId());
System.out.println("Fault type: " + iFaultRecoveryContext.getType());
System.out.println("Partnerlink: " + iFaultRecoveryContext.getReferenceName());
System.out.println("Port type: " + iFaultRecoveryContext.getPortType());
System.out.println("Properties found in propertySet:");
//print all properties defined in the fault-policy file
Map props = iFaultRecoveryContext.getProperties();
for (Map.Entry entry : props.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue().get(0));
}
System.out.println("==========");
return "OK";
}
}
The Java file must be deployed as a jar file in the lib folder of the SOA-suite domain ($ORACLE_MIDDLEWARE_HOME/user_projects/domains/soa_domain/lib).
Next we have to create a BPEL process with a fault-bindings and fault-properties file, see this post.
In the fault-policies.xml file we must declare an Action of type javaAction. In the properties section we can add some properties we can use in our Java code (in this example I created a property called myProperty with the value My Porperty value).
<?xml version="1.0" encoding="UTF-8"?>
<faultPolicies xmlns="http://schemas.oracle.com/bpel/faultpolicy"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<faultPolicy version="2.1.3" id="ConnectionFaults">
<Conditions>
<faultName xmlns:bpelx="http://schemas.oracle.com/bpel/extension"
name="bpelx:remoteFault">
<condition>
<action ref="java-fault-handler"/>
</condition>
</faultName>
</Conditions>
<Actions>
<Action id="java-fault-handler">
<javaAction className="nl.whitehorses.soa.demo.FaultHandler"
defaultAction="ora-human-intervention"
propertySet="properties">
<returnValue value="OK" ref="ora-human-intervention"/>
</javaAction>
</Action>
</Actions>
<Properties>
<propertySet name="properties">
<property name="myProperty">My Property value</property>
</propertySet>
</Properties>
</faultPolicy>
</faultPolicies>
The next figure shows a part the output from the Managed server when the Java class is invoked.



Whitehorses is specialized in succesfully implementing Oracle SOA solutions: BPEL, OSB, WebLogic & BPM
{ 8 comments… read them below or add one }
I have a Java program that uses the class BPELFaultRecoveryContext below
import com.collaxa.cube.engine.fp.BPELFaultRecoveryContext;
which resides in the orabpel.jar file. I jar up the java program and put it in the $ORACLE_MIDDLEWARE_HOME/user_projects/domains/soa_domain/lib folder on the SOA server. When I run the bpel process, it will call this java class and now, when the java class runs, it said that it can’t find this class BPELFaultRecoveryContext. I searched the server and the orabpel.jar file is there. It’s in another directory though.
The intereresting thing is in this java program, it uses the below classes and they are in the fabric-runtime.jar file. I do not include the fabric-runtime.jar file in the jar file with the java class but the java program is able to locate these 2 classes but not the one above.
import oracle.integration.platform.faultpolicy.IFaultRecoveryContext;
import oracle.integration.platform.faultpolicy.IFaultRecoveryJavaClass;
Do I need to include the orabpel.jar file in the jar file with the java class? Do you have any ideas? Thanks
Were you able to get this to work?
Thanks,
Sai
Hi,
We have java action created for Mediator, but the problem we are seeing is how do we get the composite instanceID from that.
Thanks
RaviSekhar
To get composite InstanceID, you have the API IFaultRecoveryContext.getInstanceId()
“The Java file must be deployed as a jar file in the lib folder of the SOA-suite domain ($ORACLE_MIDDLEWARE_HOME/user_projects/domains/soa_domain/lib).”
How do I do this in jDeveloper? Or, do I need to javac the file to a jar from the cmd line?
Also, what log should this be showing up in?
Hi,
Nice article.
But is there a way to send the reply back to the caller of Bpel/mediator from the java handler ?
I can set up the Bpel variables using BPELFaultRecoveryContextImpl.setvariabledata.
But i am not able to find a way to send the reply back to Caller.
Any help/suggestion in this regard is highly appreciated.
Thanks !!
Hi,Excellent Article..
Can we call a webService/BPEL Process from the Java Action ?
What’s the Trade-off in terms of performance?
I want to invoke a BPEL Service,when mediator results in a Fault.
Thanks
Vivek