1. SOA Fault Framework: Creating and using a Java action fault policy
Quick guide on how to create and deploy a Java action to be used from a fault policies
configuration file. There are several posts about how to create the custom Java action, but
none mentions how to enable it at the server, so here it is.
1) Create a JDeveloperproject
We're going to use a standard Java project to create the Java action. Create it using
JDeveloper, leaving the default values, and then add the Libraries BPEL Runtime
and SOA Runtime, in order to satisfy the dependencies (right-click over the project
name, then select the last menu entry, "Project properties..."):
Project Libraries
2) Code the class
The code below is basically a copy from the official documentation. You have to
implement the IFaultRecoveryJavaClass interface, and if you want to access the
BPEL context (to write an audit entry, for instance), you must cast the input parameter
"ctx" to BPELFaultRecoveryContextImpl:
2. 01 package info.mazanatti;
02
03 import com.collaxa.cube.engine.fp.BPELFaultRecoveryContextImpl;
04
import
oracle.integration.platform.faultpolicy.IFaultRecoveryContext;
05
import
oracle.integration.platform.faultpolicy.IFaultRecoveryJavaClass;
06
07
public class CustomFaultJavaAction implements
IFaultRecoveryJavaClass {
08 public void handleRetrySuccess(IFaultRecoveryContext ctx) {
09 System.out.println("This is for retry success");
10 handleFault(ctx);
11 }
12
13
public String handleFault(IFaultRecoveryContext ctx)
{
14 System.out.println("Action context:n" + ctx.toString());
15
16 // Get BPEL specific context here
17
BPELFaultRecoveryContextImpl bpelCtx =
(BPELFaultRecoveryContextImpl) ctx;
18
19 // Writing an audit entry
20 bpelCtx.addAuditTrailEntry("hi there");
21
22 // Getting details
23 System.out.println("Policy Id: " + ctx.getPolicyId());
24
System.out.println("Composite Name: " +
bpelCtx.getCompositeName());
25
26 // Getting an instance variable
27
Element payload =(Element)
bpelCtx.getVariableData("inputVariable", "payload", "/"));
28 Node node = payload.getFirstChild();
29
30
31 // Implement some logic to decide the outcome
32 return "ABORT";
33 }
34 }
Compile the project, and if everything's OK, create a new deployment profile and
generate a JAR file (mine will be "CustomJavaAction.jar"). After creating the
3. deployment profile, you must open up the same context menu and select the newly
created profile.
3) Deploy the new package
You have to copy the JAR file to the server and put it inside the
"oracle.soa.ext_11.1.1" directory - you will find it inside SOA Suite product's
directory, not inside the domain.
If you're under Linux, just run this:
locate oracle.soa.ext_11.1.1 | grep build.xml
Probably, just one result will show up:
/oracle/middleware/soa_11.1.1.5/soa/modules/oracle.soa.ext_11.1.1/bui
ld.xml
After finding the folder, copy CustomJavaAction.jar to it and update the environment
by calling the appropriate setDomainEnv.sh script and then running ANT from the
"soa.ext" folder - this will update the oracle.soa.ext.jar MANIFEST.MF file, adding
a reference to your new file:
$ . /oracle/middleware/domains/soa11g/bin/setDomainEnv.sh
*****************************************************
** Setting up SOA specific environment...
*****************************************************
...
.
USER_MEM_ARGS=-Xms512m -Xmx1024m
.
*****************************************************
** End SOA specific environment setup
*****************************************************
$ cd
/oracle/middleware/soa_11.1.1.5/soa/modules/oracle.soa.ext_11.1.1
$ ant
Buildfile: build.xml
create-manifest-jar:
[echo] Creating oracle.soa.ext at
/oracle/middleware/soa_11.1.1.5/soa/modules/oracle.soa.ext_11.1.1/ora
4. cle.soa.ext.jar:
/oracle/middleware/soa_11.1.1.5/soa/modules/oracle.soa.ex
t_11.1.1/CustomJavaAction.jar:
/oracle/middleware/soa_11.1.1.5/soa/modules/oracle.soa.ex
t_11.1.1/classes
BUILD SUCCESSFUL
Total time: 1 second
Warning: this procedure is not cluster-friendly. If you're running a cluster, you
must copy the file and run ANT on each physical server that forms the domain.
If the server is running, restart it.
4) Attach the action to your fault policies
Now, you just have to use the brand new action when defining your fault policies.
Here's my fault-policies.xml:
<?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 id="customPolicy" version="0.0.1"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.oracle.com/bpel/faultpolicy"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Conditions>
<!-- Any error -->
<faultName>
<condition>
<action ref="custom-java"/>
</condition>
</faultName>
</Conditions>
<Actions>
<Action id="custom-java">
<javaAction className="info.mazanatti.CustomFaultJavaAction"
defaultAction="default-human-intervention">
<returnValue value="ABORT" ref="default-abort"/>
</javaAction>
</Action>
</Actions>
</faultPolicy>
5. </faultPolicies>
Here are the log entries generated by my custom action:
<Mar 30, 2012 4:31:30 PM BRT> <Notice> <Stdout> <BEA-000000> <Action
context:
[Fault uri=http://schemas.oracle.com/bpel/extension
Fault prefix=
Fault Localpart=remoteFault
[Faulted Activity Details:
Activity Name=Invoke1
Activity Id=BpInv0
Activity lineNumber=75
Partner Link=Service1
Partner Port
type={http://xmlns.oracle.com/Abril_VD/POC_Flow/BPELProcess1}BPELProc
ess1
ActivityType=invoke
]
Instance Id=480010
Fault Policy Id=customPolicy
Fault Policy Action Id=custom-java
Fault Payload=
Key=summary
Value=<summary>oracle.fabric.common.FabricInvocationException: Unable
to access the following endpoint(s):
http://some.faulty.address</summary>
Key=detail Value=<detail>Unable to access the following
endpoint(s): http://some.faulty.address</detail>
Key=code Value=<code>null</code>
]>
<Mar 30, 2012 4:31:30 PM BRT> <Notice> <Stdout> <BEA-000000> <Policy
Id: customPolicy>
<Mar 30, 2012 4:31:30 PM BRT> <Notice> <Stdout> <BEA-000000>
<Composite Name: UseFaultJavaAction>
References:
Adding Custom Classes and JAR Files to SOA
Using Fault Handling in a BPEL Process