Wednesday, January 23, 2008

BPEL Fault Framework

Lab nn – BPEL Fault Framework
This simple lab introduces you to the fault framework and the configuration required to leverage the framework.
Release provides a generic fault management framework for handling faults in BPEL processes. If a fault occurs during runtime in an invoke activity in a process, the framework catches the fault and performs a user-specified action defined in a fault policy file associated with the activity. If a fault results in a condition in which human intervention is the prescribed action, you perform recovery actions from Oracle BPEL Control. The fault management framework provides an alternative to designing a BPEL process with catch branches in scope activities.
In this lab we will catch faults (business and runtime) for invoke activities.
Create a simple Web Service
· Create a Java class in JDeveloper called SayHi with a simple method such as –
package sayhi;
public class SayHi { public SayHi() { } public String sayHi(String name){ return "Hi There "+ name; }}
· Right-mouse click on the Java class and expose as a J2EE Web Service· Deploy to Oracle Application Server

Create a new Asynchronous BPEL process
· Create a new asynchronous BPEL process in JDeveloper

· Set input/output to –

<schema xmlns="" targetNamespace="http://www.niall.rentACar/" elementFormDefault="qualified" xmlns:tns="http://www.niall.rentACar/" xmlns:wsdl="" xmlns:xsi="" xmlns:soap11-enc="; <element name="rentCarElement"> <complexType> <sequence> <element name="name" type="string" nillable="true"/> <element name="pickup" type="string" nillable="true"/> <element name="return" type="string" nillable="true"/> <element name="dateOut" type="string" nillable="true"/> <element name="dateRtn" type="string" nillable="true"/> <element name="bookingCode" type="string" nillable="true"/> <element name="comments" type="string" nillable="true"/> </sequence> </complexType> </element></schema>
· Add a partner link for the SayHiService

· Add invoke

· Add Assign before the invoke to pass the name variable

· Add Assign after the invoke to copy input to output

· Open the RentACarProcess.wsdl file in JDeveloper

· Add the following line before the <types> element
<import namespace="" location="http://localhost:8888/orabpel/xmllib/RuntimeFault.wsdl;
This imports the RemoteException runtime fault that we will use later in the BPEL process.

· Create a new global variable – runtimeException

· Add a catch branch to the main

· Deploy to BPM and test
Set up the Fault Handler
· Make a copy of DefaultPolicy.xml

Here we will specify the default handling policies for the „default“ domain.
<Conditions> <!-- Fault if wsdlRuntimeLocation is not reachable --> <faultName xmlns:bpelx="" name="bpelx:remoteFault"> <condition> <action ref="ora-retry"/> </condition> <condition> <action ref="ora-human-intervention"/> </condition> </faultName> <!-- Fault if location port is not reachable--> <faultName xmlns:bpelx="" name="bpelx:bindingFault"> <condition> <action ref="ora-rethrow-fault"/> </condition> </faultName>
<!-- Business faults --><!-- Fault comes with a payload of error, make sure the name space--><!-- is provided here or at root level -->
· Add the ora-human-intervention action as detailed above.
· Also set the retryCount to 2 instead of 8 as detailed below.
<Action id="ora-retry"> <retry> <retryCount>2</retryCount> <retryInterval>2</retryInterval> <exponentialBackoff/> </retry> </Action>
· Amend fault-bindings.xml to point to your new policy file

· Undeploy the SayHi Web Service App so as to generate a remote fault

· Bounce the application server home instance· Go to the BPEL Console and clear the wsdl cache· Rerun the rentACarProcess

· Click on the Activities tab

· Perform manual recovery
Create rentACar Web Service
Create a new project in JDeveloper

· Create a Java class with the following methods

package rentacarservice;
public class RentACar { public RentACar() { } public String bookRentalCar(String pickup, String rtn, String dateOut, String dateRtn) throws NoRentalCarAvailableException{ String bookingRef = "AB2626"; if (dateOut.equals("251207")){ bookingRef = "Sorry no vehicles available"; throw new NoRentalCarAvailableException(bookingRef); } else { System.out.println("Car booked. Pickup at "+ pickup + " on " + dateOut + ". Return at " + rtn + " on " + dateRtn); return bookingRef; } } public String cancelRentalCar(String bookingRef){ System.out.println("Rental Booking "+ bookingRef + " has been cancelled"); return " Rental Booking " + bookingRef + " cancelled"; } }
· Create a new Java class - NoRentalCarAvailableException
package rentacarservice;
public class NoRentalCarAvailableException extends Exception { public NoRentalCarAvailableException() { super(); } public NoRentalCarAvailableException(String message) { super(message); }}
· Expose RentACar as a web service

· Deploy to Oracle Application Server· Test· Re-deploy the SayHi Service
Create new fault policy for Business error
<!-- Business faults --><!-- Fault comes with a payload of error, make sure the name space--><!-- is provided here or at root level -->
<faultName xmlns:tns="http://rentacarservice/"name="tns:NoRentalCarAvailableException"><condition><action ref="ora-human-intervention"/></condition></faultName>
· Bounce the home instance

Amend the BPEL Process to call the Car Rental Service
· Add Partner Link· Add Assign/Invoke· Add Catch Branch for the business error

· Deploy and Test

· Click on Activities tab

No comments: