How to Use a Java Action Fault Policy
Note the following details when using the Java action fault policy:
-
The Java class provided follows a specific interface. This interface returns a string. Multiple values can be provided for output and the fault policy to take after execution.
-
Additional fault policy can be executed by providing a mapping from the output value (return value) of implemented methods to a fault policy.
-
If no
ReturnValueis specified, the default fault policy is executed, as shown in the following example.
<Action id="ora-java">
<javaAction className="mypackage.myclass"
defaultAction="ora-human-intervention" propertySet="prop-for-billing">
<!--defaultAction is a required attribute, but propertySet is optional-->
<!-- attribute-->
<ReturnValue value="RETRY" ref="ora-retry"/>
<!--value is not nilable attribute & cannot be empty-->
<ReturnValue value="RETRHOW" ref="ora-rethrow-fault"/>
</javaAction>
</Action>
Table 12-7 provides an example of ReturnValue use.
Table 12-7 System Interpretation of Java Action Fault Policy
| Code | Description |
|---|---|
<ReturnValue value="RETRY" ref="ora-retry"/> |
Execute the |
<ReturnValue value="" ref="ora-rethrow"/> |
Fails in validation. |
<javaAction className="mypackage.myclass" defaultAction="ora-human-intervention"> |
Execute |
<ReturnValue value="RETRY" ref="ora-retry"/> <ReturnValue value="" ref=""/> |
Fails in validation. |
<javaAction className="mypackage.myclass" defaultAction=" ora-human-intervention"> <ReturnValue></ReturnValue> |
Fails in validation. |
To invoke a Java class, you can provide a class that implements the IFaultRecoveryJavaClass interface. IFaultRecoveryJavaClass is included in the fabric-runtime.jar file. The package name is oracle.integration.platform.faultpolicy.
The IFaultRecoveryJavaClass interface has two methods, as shown in the following example:
public interface IFaultRecoveryJavaClass
{
public void handleRetrySuccess( IFaultRecoveryContext ctx );
public String handleFault( IFaultRecoveryContext ctx );
}
Note the following details:
-
handleRetrySuccessis invoked upon a successful retry attempt. The retry policy chains to a Java action onretrySuccessAction. -
handleFaultis invoked to execute a policy of typejavaAction. -
The fault policy class is packaged and deployed in either of two ways:
-
Package the Java class with the SOA composite application.
-
If the Java class must be shared by multiple SOA composite applications, place it in the shared location (for example,
$MW_HOME/soa/soa/ modules/oracle.soa.ext_11.1.1). The shared location includes areadmefile that describes how to place the Java class to make it available in the class path.
-
The following example shows the data available with IFaultRecoveryContext:
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 partner link.
*/
public String getReferenceName();
/**
* @return Port type of the faulted reference .
*/
public QName getPortType();
}
The service engine implementation of this interface provides more information (for example, Oracle BPEL Process Manager). The following example provides details:
public class BPELFaultRecoveryContextImpl extends BPELXExecLetUtil implements
IBPELFaultRecoveryContext, IFaultRecoveryContext{
...
}
Oracle BPEL Process Manager-specific data is available with IBPELFaultRecoveryContext, as shown in the following example:
public interface IBPELFaultRecoveryContext {
public void addAuditTrailEntry(String message);
public void addAuditTrailEntry(String message, Object detail);
public void addAuditTrailEntry(Throwable t);
/**
* @return Get action id of the fault policy action being executed.
*/
public String getActionId();
/**
* @return Type of the faulted activity.
*/
public String getActivityId();
/**
* @return Name of the faulted activity.
*/
public String getActivityName();
/**
* @return Type of the faulted activity.
*/
public String getActivityType();
/**
* @return Correleation id of the faulted activity.
*/
public String getCorrelationId();
/**
* @return BPEL fault that caused the invoke to fault.
*/
public BPELFault getFault();
/**
* @return Get index value of the instance
*/
public String getIndex(int i);
/**
* @return get Instance Id of the current process instance of the faulted
* activity.
*/
public long getInstanceId();
/**
* @return Get priority of the current process instance of the faulted
* activity.
*/
public int getPriority();
/**
* @return Process DN.
*/
public ComponentDN getProcessDN();
/**
* @return Get status of the current process instance of the faulted
* activity.
*/
public String getStatus();
/**
* @return Get title of the current process instance of the faulted
* activity.
*/
public String getTitle();
public Object getVariableData(String name) throws BPELFault;
public Object getVariableData(String name, String partOrQuery)
throws BPELFault;
public Object getVariableData(String name, String part, String query)
throws BPELFault;
/**
* @param priority
* Set priority of the current process instance of the faulted
* activity.
* @return
*/
public void setPriority(int priority);
/**
* @param status
* Set status of the current process instance of the faulted
* activity.
*/
public void setStatus(String status);
/**
* @param title
* Set title of the current process instance of the faulted
* activity.
* @return
*/
public String setTitle(String title);
public void setVariableData(String name, Object value) throws BPELFault;
public void setVariableData(String name, String partOrQuery, Object value)
throws BPELFault;
public void setVariableData(String name, String part, String query,
Object value) throws BPELFault;
}
The following example provides an example of javaAction implementation.
public class TestJavaAction implements IFaultRecoveryJavaClass {
public void handleRetrySuccess(IFaultRecoveryContext ctx) {
System.out.println("This is for retry success");
handleFault(ctx);
}
public String handleFault(IFaultRecoveryContext ctx) {
System.out.println("-----Inside handleFault-----\n" + ctx.toString());
dumpProperties(ctx.getProperties());
/* Get BPEL specific context here */
BPELFaultRecoveryContextImpl bpelCtx = (BPELFaultRecoveryContextImpl) ctx;
bpelCtx.addAuditTrailEntry("hi there");
System.out.println("Policy Id" + ctx.getPolicyId());
...
}