Extending the Oracle BPEL Error Hospital with custom Java Actions

3

With patch set 10.1.3.3 of its SOA Suite Oracle introduced standard fault handling functionality for BPEL. This Error Hospital framework allows the definition of policies for handling runtime exceptions, like Remote Faults and Binding Faults, that may occur on invoke activities in BPEL processes. Remote Faults occur when the service that the BPEL process tries to invoke cannot be reached, e.g. in case of a network or server failure. Remote Faults can be retried. Binding Faults indicate a mismatch between service provider and service consumer. It makes no sense to retry these unless the mismatch is repaired.

Instead of modeling the error handling behavior for runtime exceptions on invoke activities in BPEL it is now possible to define policies for dealing with these. A policy defines actions for responding to specific faults. Actions may be conditional: if the test that is specified for a condition passes the action will be executed. Specifying a test is not mandatory; in that case the condition is treated as the catch all condition by the Error Hospital framework. Note that multiple conditions may be specified without test element. In that case however, the framework will execute only the last condition specified and simply disregards the other conditions. This does not mean that chaining of actions is impossible. We will demonstrate several capabilities for this in this blog post. ....
 

Fault policies

Consider the following Fault Policy that is used at one of our customers.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />&lt;faultPolicy version=&quot;2.0.1&quot; id=&quot;SabicDefaultPolicy&quot;<br />             xmlns:env=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;<br />             xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;<br />             xmlns=&quot;http://schemas.oracle.com/bpel/faultpolicy&quot;<br />             xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;<br />  &lt;!-- This section describes fault conditions.<br />       Build more conditions with faultName, test and action --&gt;<br />  &lt;Conditions&gt;<br />    &lt;!-- Fault if wsdlRuntimeLocation is not reachable;<br />         remoteFault is retryable --&gt;<br />    &lt;faultName xmlns:bpelx=&quot;http://schemas.oracle.com/bpel/extension&quot; name=&quot;bpelx:remoteFault&quot;&gt;<br />      &lt;condition&gt;<br />        &lt;action ref=&quot;ora-retry&quot;/&gt;<br />      &lt;/condition&gt;<br />    &lt;/faultName&gt;<br />    &lt;!-- Bindingfaults are not retryable --&gt;<br />    &lt;faultName xmlns:bpelx=&quot;http://schemas.oracle.com/bpel/extension&quot; name=&quot;bpelx:bindingFault&quot;&gt;<br />       &lt;condition&gt;<br />         &lt;action ref=&quot;send-notification&quot;/&gt;<br />       &lt;/condition&gt;<br />    &lt;/faultName&gt;<br />  &lt;/Conditions&gt;<br />  &lt;Actions&gt;<br />     &lt;!-- This action will attempt 8 retries at increasing intervals of 2, 4, 8, 16, 32, 64, 128, and 256 seconds. --&gt;<br />     &lt;Action id=&quot;ora-retry&quot;&gt;<br />       &lt;retry&gt;<br />         &lt;retryCount&gt;8&lt;/retryCount&gt;<br />         &lt;retryInterval&gt;2&lt;/retryInterval&gt;<br />         &lt;exponentialBackoff/&gt;<br />         &lt;retryFailureAction ref=&quot;send-notification&quot;/&gt;<br />       &lt;/retry&gt;<br />     &lt;/Action&gt;<br />     &lt;!-- This action will cause a replay scope fault --&gt;<br />     &lt;Action id=&quot;ora-replay-scope&quot;&gt;<br />        &lt;replayScope/&gt;<br />     &lt;/Action&gt;<br />     &lt;!-- This action will bubble up the fault --&gt;<br />     &lt;Action id=&quot;ora-rethrow-fault&quot;&gt;<br />       &lt;rethrowFault/&gt;<br />     &lt;/Action&gt;<br />     &lt;!-- This action will mark the work item to be &quot;pending recovery from console&quot; --&gt;<br />     &lt;Action id=&quot;ora-human-intervention&quot;&gt;<br />       &lt;humanIntervention/&gt;<br />     &lt;/Action&gt;<br />     &lt;!-- This action will cause the instance to terminate --&gt;<br />     &lt;Action id=&quot;ora-terminate&quot;&gt;<br />       &lt;abort/&gt;<br />     &lt;/Action&gt;<br />     &lt;!-- Custom Java action that sends a notification to the technical support team;<br />          Then it will invoke the ora-human-intervention action. --&gt;<br />    &lt;Action id=&quot;send-notification&quot;&gt;<br />      &lt;javaAction className=&quot;nl.amis.soa.bpel.ext.util.SendMail&quot;<br />                  defaultAction=&quot;ora-human-intervention&quot;<br />                  propertySet=&quot;send-notification-properties&quot;/&gt;<br />    &lt;/Action&gt;<br />  &lt;/Actions&gt;<br />  &lt;Properties&gt;<br />    &lt;propertySet name=&quot;send-notification-properties&quot;&gt;<br />      &lt;property name=&quot;from&quot;&gt;emailaddress@somedomain.com&lt;/property&gt;<br />      &lt;property name=&quot;to&quot;&gt;emailaddress@somedomain.com; otheremailaddress@somedomain.com&lt;/property&gt;<br />      &lt;property name=&quot;subject&quot;&gt;BPM UAT:&lt;/property&gt;<br />      &lt;property name=&quot;text&quot;&gt;Environment: UAT&lt;/property&gt;<br />      &lt;property name=&quot;host&quot;&gt;smtp_host&lt;/property&gt;<br />      &lt;property name=&quot;port&quot;&gt;smtp_port&lt;/property&gt;<br />    &lt;/propertySet&gt;<br />  &lt;/Properties&gt;<br />&lt;/faultPolicy&gt;<br />

 

This fault policy specification is for both Runtime and Binding Faults. It lists all operations that are provided by Oracle out-of-the-box and adds a custom build Java action for sending e-mail notifications which we will discuss later. Using the following fault-bindings specification for a BPEL domain the policy is declared to be active for any partnerlink invocation in the domain.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />&lt;faultPolicyBindings version=&quot;2.0.1&quot; <br />                     xmlns=&quot;http://schemas.oracle.com/bpel/faultpolicy&quot; <br />                     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;<br />        &lt;!-- Enabling this will cause all processes in this domain to use this fault policy --&gt;<br />	&lt;process faultPolicy=&quot;SabicDefaultPolicy&quot;/&gt;<br />	&lt;partnerLink faultPolicy=&quot;SabicDefaultPolicy&quot;&gt;<br />          &lt;!--<br />	    &lt;name&gt;creditRatingService&lt;/name&gt;<br />	    &lt;portType xmlns:db=&quot;http://xmlns.oracle.com/pcbpel/adapter/db/insert/&quot;&gt;db:insert_plt&lt;/portType&gt;<br />	  --&gt;<br />	&lt;/partnerLink&gt;<br />&lt;/faultPolicyBindings&gt;<br />

 

Note: binding fault policies can be more fine-grained, e.g. on a per partnerlink basis or even for a specific porttype that is specified for a partnerlink service. Given the fault-bindings configuration presented here, the BPEL Error Hospital framework will now handle any Runtime and Binding faults for any BPEL process in the domain, taking precedence over any specification in the BPEL processes for handling runtimeFaults and bindingFaults.

Chaining actions in case of a runtime exception

According to our policy specification, in case of a Runtime Fault the system will first retry the faulted operation. It will retry up to a maximum of 8 times, gradually increasing the time between attempts. When the retry action does not resolve the problem the system executes the send-notification action. This sends an e-mail notification to the technical support team informing them about the issue. After sending the notification, the fault handling framework executes the “ora-human-intervention” action. The state of the BPEL process instance changes to “pending recovery” and a technical support representative can now access the BPEL Console and initiate further action from there. The chain of actions configured in the policy is shown in the following flowchart schema:

Custom Java Actions

As shown in the policy specification, the BPEL Error Hospital allows for Java extensions that can be used to define additional actions. In this case, the customer requested the technical support team to be notified in case of a runtime exception. Since the fault-handling framework does not provide this functionality we created a Java action to achieve this. Implementing the IFaultRecoveryJavaClass interface ensures that the Java custom action is usable by the BPEL Error Hospital. The following code listing shows part of the custom Java action class (accessor-methods and some other methods not shown):

package nl.amis.bpel.ext.util;<br /><br />import com.oracle.bpel.client.config.faultpolicy.IFaultRecoveryContext;<br />import com.oracle.bpel.client.config.faultpolicy.IFaultRecoveryJavaClass;<br /><br />import java.util.ArrayList;<br />import java.util.Map;<br />import java.util.Properties;<br /><br />import javax.mail.Message;<br />import javax.mail.Message.RecipientType;<br />import javax.mail.MessagingException;<br />import javax.mail.Session;<br />import javax.mail.Transport;<br />import javax.mail.internet.AddressException;<br />import javax.mail.internet.InternetAddress;<br />import javax.mail.internet.MimeMessage;<br /><br /><br />public class SendMail implements IFaultRecoveryJavaClass {<br />    private String from;<br />    private String to;<br />    private String subject;<br />    private String text;<br />    private String host;<br />    private String port;<br />    private Properties props;<br /><br />    public SendMail() {<br />    }<br /><br />    private void send() {<br />        Session mailSession = Session.getDefaultInstance(props);<br />        Message simpleMessage = new MimeMessage(mailSession);<br /><br />        try {<br />            InternetAddress fromAddress = new InternetAddress(from);<br />            simpleMessage.setFrom(fromAddress);<br />            String[] toAddresses = to.split(&quot;;&quot;);<br />            if (toAddresses != null &amp;&amp; toAddresses.length &gt; 0) {<br />                InternetAddress[] toInternetAddresses = <br />                    new InternetAddress[toAddresses.length];<br />                for (int i = 0; i &lt; toAddresses.length; i++) {<br />                    toInternetAddresses[i]= <br />                            new InternetAddress(toAddresses[i]);<br />                }<br />                simpleMessage.setRecipients(RecipientType.TO, <br />                                            toInternetAddresses);<br />            }<br />            simpleMessage.setSubject(subject);<br />            simpleMessage.setText(text);<br />            Transport.send(simpleMessage);<br />        } catch (AddressException e) {<br />            System.out.println(&quot;Error formatting Internet Email Address: &quot; + <br />                               e.getMessage());<br />            e.printStackTrace();<br />        } catch (MessagingException e) {<br />            System.out.println(&quot;Error sending email: &quot; + e.getMessage());<br />            e.printStackTrace();<br />        }<br /><br />    }<br /><br />    private String getParameterValue(ArrayList parameterList) {<br />        String value = null;<br />        if (parameterList != null &amp;&amp; parameterList.size() &gt; 0) {<br />            value = (String)parameterList.get(0);<br />        }<br />        return value;<br />    }<br /><br />    /**<br />     * This method is called by the BPEL Error Hospital framework when this<br />     * action is selected as retrySuccessAction (with the retry option) or<br />     * when this action is selected as successor in the human intervention<br />     * screen in the BPEL Console.<br />     * <br />     * @param iFaultRecoveryContext<br />     */<br />    public void handleRetrySuccess(IFaultRecoveryContext iFaultRecoveryContext) {<br />        Map properties = iFaultRecoveryContext.getProperties();<br />        if (properties != null &amp;&amp; properties.size() == 6) {<br />            setFrom(getParameterValue((ArrayList)properties.get(&quot;from&quot;)));<br />            setTo(getParameterValue((ArrayList)properties.get(&quot;to&quot;)));<br />            setSubject(getParameterValue((ArrayList)properties.get(&quot;subject&quot;)) + <br />                       &quot; &quot; + &quot;Retry Success&quot;);<br />            setText(&quot;The exception that occurred when processing &quot; + <br />                    iFaultRecoveryContext.getTitle() + <br />                    &quot; was successfully retried.\n&quot; + <br />                    &quot;This message was automatically generated, please do not reply to it.&quot;);<br />            setHost(getParameterValue((ArrayList)properties.get(&quot;host&quot;)));<br />            setPort(getParameterValue((ArrayList)properties.get(&quot;port&quot;)));<br />            send();<br />        }<br />    }<br /><br />    /**<br />     * This method is called by the BPEL Error Hospital framework when this<br />     * class is configured as action in the fault handling policy<br />     * <br />     * @param iFaultRecoveryContext<br />     * @return String that can be used to influence choice for next action (not used in this case)<br />     */<br />    public String handleBPELFault(IFaultRecoveryContext iFaultRecoveryContext) {<br />        Map properties = iFaultRecoveryContext.getProperties();<br />        if (properties != null &amp;&amp; properties.size() == 6) {<br />            setFrom(getParameterValue((ArrayList)properties.get(&quot;from&quot;)));<br />            setTo(getParameterValue((ArrayList)properties.get(&quot;to&quot;)));<br />            setSubject(getParameterValue((ArrayList)properties.get(&quot;subject&quot;)) + <br />                       iFaultRecoveryContext.getTitle());<br />            setText(getParameterValue((ArrayList)properties.get(&quot;text&quot;)) + <br />                    &quot;\n&quot; + &quot;BPEL Process Instance: &quot; + <br />                    iFaultRecoveryContext.getInstanceId() + <br />                    &quot; needs intervention to recover from a technical exception: &quot; + <br />                    iFaultRecoveryContext.getFault().getMessage() + &quot;.\n&quot; + <br />                    &quot;Check the Activities tab in the BPEL Management Console in order to resolve the error as soon as possible.\n&quot; + <br />                    &quot;This message was automatically generated, please do not reply to it.&quot;);<br />            setHost(getParameterValue((ArrayList)properties.get(&quot;host&quot;)));<br />            setPort(getParameterValue((ArrayList)properties.get(&quot;port&quot;)));<br />            send();<br />        }<br />        return null;<br />    }<br />}<br />

 

The framework executes method “handleBPELFault” to perform the action that is defined in the policy. Method “handleRetrySuccess” is executed when the technical team member resolving the problem selects to perform the send-notification action when the retry action was successful. This option is shown in the following screenshot:

The IFaultRecoveryContext parameter that is passed by the framework in both methods provides a wealth of information with respect to the faulted BPEL instance and regarding the cause of the error. For example:

  • getFault(): returns the BPELFault object for obtaining fault details, like getFault().getFaultName() or  getFault().getMessage()
  • getInstanceId(): gets the process id of the faulted instance. Alternatively, use getProcessId() for more detailed data for process identification
  • getLocator(): returns the Locator object via which the BPEL Client API can be accessed in order to do further processing on the domain
  • getPolicyId(): to identify the fault policy
  • getProperties(): returns a Java Map
    ob
    ject with properties that are passed on to the Java class as defined in the policy
  • getTitle(): alternative identification of the faulted process in the format “Instance #<instandeId> of <ProcessName>”
  • getVariableData(): the equivalent of bpws:getVariableData() that is used when programming BPEL processes; gives access to any data in the BPEL process

As may have been clear from the fault policy specification that was shown earlier, it is possible to pass parameters to the custom Java class using the <Properties> element which is bound to the Java action using the propertySet attribute on the <javaAction> element. The properties are passed on as a Java Map with values encapsulated as ArrayList objects.

Note that it is also possible to pass back a return value from the handleBPELFault method. The <javaAction> element in the policy specification may be used for specifying further action-chaining based on value returned by the handleBPELFault method. For example:

    &lt;Action id=&quot;send-notification&quot;&gt;<br />      &lt;javaAction className=&quot;nl.amis.soa.bpel.ext.util.SendMail&quot;<br />                  defaultAction=&quot;ora-human-intervention&quot;<br />                  propertySet=&quot;send-notification-properties&quot;&gt;<br />        &lt;returnValue value=&quot;X&quot; ref=&quot;ora-terminate&quot;/&gt;<br />        &lt;returnValue value=&quot;Y&quot; ref=&quot;some_other_java_action&quot;/&gt;<br />      &lt;/javaAction&gt;<br />    &lt;/Action&gt;<br />

 

Programmatically accessing activities with “pending recovery” status

Finally, Oracle extended the BPEL client API in order to retrieve activities that are in “pending recovery” state. The following snippet of code will provide you with a list of activities that are in pending recovery state:

  Locator locator = getLocator();<br />  WhereCondition where = <br />    WhereConditionHelper.whereActivitiesPendingRecovery();<br />  where.prependOrderBy(&quot;wi_modify_date desc&quot;);<br />  IActivityHandle[] activityHandles = locator.listActivities(where);&nbsp;

 

The resulting list matches the activities that are shown in the BPEL Console Activities tag for which the Fault Name column lists either remoteFault or bindingFault.

Future wishes

The BPEL Error Hospital that Oracle introduced with SOA Suite 10.1.3.3 works fine. When applied in the way described here it will prevent you from having to model the handling of Binding Faults or Runtime Faults in BPEL processes. It still leaves a lot to be desired for future releases though. To start with, the following would be great:

  • A default notification option in the BPEL Error Hospital that no longer requires Java coding
  • That is capable of using the Identity service for obtaining e-mail addresses
  • Updated documentation for using the Error Hospital and matching JavaDoc for extending it

Perhaps in the future we will also be able to specify policies for handling custom faults that may occur anywhere in the BPEL process, i.e. not only on invoke activities.

Share.

About Author

3 Comments

  1. Hi,

    I’m trying to implement this solution in 10.1.3.4 but have been unable to call the java class.  Can you give me an idea of where I should place the class on the server? (I have it in a .jar also if that’s appropriate)

    Thanks,
    Dan

  2. Hi,

    Is it possible to execute the instances, pending for manual recovery, using BPEL API. We have a requirement to do bulk resubmission using scripts if all the processes failed due to the same reason.

    Thanks
    Thyagu

  3. Hi,
    A nice article. Just would like to add to the list of desired features:
    Integration of exception framework with the JAZN repository to control access for Human Intervention policy. Eg. only few select (with certain role or few certain users) should be able to take action on faults raised in a particular process, or in a particular activity or port-type.

    Thanks-
    Ashish.