The example below shows a Java snippet defined in a BPEL Java activity
/* Start of Code snippet */
/*Write your java code below e.g.
System.out.println("Hello, World");
*/
try{
String status = "Bronze";
/* accessing a process variable of type string */
String country = (String)getVariableData("v_country");
/* accessing a variable within the complex type - customer */
Element country1 = (Element)getVariableData("inputVariable", "payload","/ns1:customer/ns1:Country");
String c1 = country1.getTextContent();
/* writes to the audit trail - will then be visible in BPEL console at runtime*/
addAuditTrailEntry("country is: " + country);
addAuditTrailEntry("country1 is: " + c1);
if (country.equalsIgnoreCase("Ireland")){
status = "Gold";
}
/* setting the output variable within the complex type - customer */
setVariableData("outputVariable", "payload",
"/ns1:customer/ns1:Status", status);
addAuditTrailEntry("status is: " + status);
}
/* End of Code snippet */
catch (Exception e) {
addAuditTrailEntry(e);
}
Add the following line before the bpelx:exec tag to import the Element class
Calling an external Java class in a Java activity
Jar up the Java class you want to use and copy the jarfile to the BPEL
system\services\lib directory.
In this example, my class is called CustomerStatus
/* Start of Code snippet */
try{
String status = "Bronze";
String country = (String)getVariableData("v_country");
Element country1 = (Element)getVariableData("inputVariable", "payload","/ns1:customer/ns1:Country");
String c1 = country1.getTextContent();
addAuditTrailEntry("country is: " + country);
addAuditTrailEntry("country1 is: " + c1);
CustomerStatus cs = new CustomerStatus();
status = cs.getStatus(country);
setVariableData("outputVariable", "payload",
"/ns1:customer/ns1:Status", status);
addAuditTrailEntry("status is: " + status);
}
catch (Exception e) {
addAuditTrailEntry(e);
}
/* End of Code snippet */
add the following entries before the bpelx:exec tag
Wednesday, January 30, 2008
Using boolean in a BPEL Switch activity
v_approvalRequired is defined as a boolean
condition= "bpws:getVariableData('v_approvalRequired')=string(true())"
condition= "bpws:getVariableData('v_approvalRequired')=string(true())"
Wednesday, January 23, 2008
BPEL 10.1.3.3 Fault Framework
Lab nn – BPEL 10.1.3.3 Fault Framework
This simple lab introduces you to the 10.1.3.3 fault framework and the configuration required to leverage the framework.
Release 10.1.3.3 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 –
rentACar.xsd
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.niall.rentACar/" elementFormDefault="qualified" xmlns:tns="http://www.niall.rentACar/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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="http://schemas.oracle.com/bpel/extension" 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="http://schemas.oracle.com/bpel/extension" 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="http://schemas.oracle.com/bpel/extension" 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 -->
</Conditions>
· 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
This simple lab introduces you to the 10.1.3.3 fault framework and the configuration required to leverage the framework.
Release 10.1.3.3 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 –
rentACar.xsd
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.niall.rentACar/" elementFormDefault="qualified" xmlns:tns="http://www.niall.rentACar/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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="http://schemas.oracle.com/bpel/extension" 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="http://schemas.oracle.com/bpel/extension" 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="http://schemas.oracle.com/bpel/extension" 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 -->
</Conditions>
· 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
Subscribe to:
Posts (Atom)