Archive

Archive for the ‘BPEL’ Category

Oracle SOA 11G – lookupXRef1M function

January 11, 2013 Leave a comment

lookupXRef() and lookupXRef1M() functions can be used to look up single and multiple values correspondingly from SOA 11G Cross Reference table (DEV_SOAINFRA.XREF_DATA).

lookupXRef1M() function will be used to look up multiple values of target system associated with the one value of source system.

Example Table Structure :

lookupXRef1M

lookupXRef1M

 
Cross Reference Table ( DEV_SOAINFRA.XREF_DATA ) Structure :

XREF_DATA_TABLE

XREF_DATA_TABLE

Issue:
lookupXRef1M() function looking up values differently for BPEL Assign activity and for BPEL Transformation (XSL).

While using with Assign activity it is giving the response like the below.

BPEL Assign activity :

 <assign name="assignLookupXRef1M">
            <copy>
              <from expression="xref:lookupXRef1M('Sample.xref','SIEBEL','SBL_001','FUSION',true())"/>
              <to variable="outputVariable" part="payload"
                  query="/client:processResponse/client:result"/>
            </copy>
          </assign>

BPEL Assign activity response :

<outputVariable>
<part  name="payload">
<processResponse>https://rathinasaba.wordpress.com/wp-admin/edit-comments.php
<client:result>
<value>FUS_001</value>
<value>FUS_002</value>
<value>FUS_003</value>
</client:result>
</processResponse>
</part>
</outputVariable>

While using it with XSL Transformation in BPEL it is just returning the concatenated values of target system.
BPEL Transformation:

<xsl:template match="/">
    <client:processResponse>
      <client:result>
        <xsl:value-of select='xref:lookupXRef1M("Sample.xref",/client:process/client:xrefReferenceColumnName,/client:process/client:xrefReferenceColumnValue,/client:process/client:xrefColumnName,true())'/>
      </client:result>
    </client:processResponse>
  </xsl:template>

BPEL Transformation response :

<outputVariable>
	<part  name="payload">
		<processResponse>
			<client:result>FUS_001FUS_002FUS_003</client:result>
		</processResponse>
	</part>
</outputVariable>

Solution to get the values properly in BPEL XSL Transformation :
Assign the lookupXRef1M() response in variable and iterate it using node() function like shown below with in the xsl to get the proper result as we get it in Assign activity.

<?xml version="1.0" encoding="UTF-8" ?>
<?oracle-xsl-mapper
  <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
  <mapSources>
    <source type="WSDL">
      <schema location="../LookupXRef1M.wsdl"/>
      <rootElement name="process" namespace="http://xmlns.oracle.com/CompositesSamples/LookupXRef1M"/>
    </source>
  </mapSources>
  <mapTargets>
    <target type="WSDL">
      <schema location="../LookupXRef1M.wsdl"/>
      <rootElement name="processResponse" namespace="http://xmlns.oracle.com/CompositesSamples/LookupXRef1M"/>
    </target>
  </mapTargets>
  <!-- GENERATED BY ORACLE XSL MAPPER 11.1.1.5.0(build 110418.1550.0174) AT [THU JAN 10 12:18:08 EST 2013]. -->
?>
<xsl:stylesheet version="1.0"
                xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
                xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
                xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
                xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                xmlns:ora="http://schemas.oracle.com/xpath/extension"
                xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
                xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
                xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
                xmlns:client="http://xmlns.oracle.com/CompositesSamples/LookupXRef1M"
                xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
                xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
                xmlns:med="http://schemas.oracle.com/mediator/xpath"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
                xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk"
                xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:vhadvm="http://www.oracle.com/XSL/Transform/java/com.vha.util.dvm.CustomDVMLookup"
                xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
                xmlns:exsl="http://exslt.org/common"
                exclude-result-prefixes="xsi xsl plnk wsdl client xsd bpws xp20 bpel bpm ora socket mhdr oraext dvm hwf med ids vha xdk xref ldap"
                extension-element-prefixes="exsl">
                <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <xsl:variable name="response" select='xref:lookupXRef1M("Sample.xref",/client:process/client:xrefReferenceColumnName,/client:process/client:xrefReferenceColumnValue,/client:process/client:xrefColumnName,true())'/>
    <client:processResponse>
      <client:result>
        <xsl:for-each select="exsl:node-set($response)/node()">
            <xsl:element name="value">
                <xsl:value-of select="."/>
            </xsl:element>
        </xsl:for-each>
      </client:result>
    </client:processResponse>
  </xsl:template>
</xsl:stylesheet>
Advertisements

SOA11G – Fault Handling using Custom Java Class

November 14, 2012 Leave a comment

Oracla SOA 11G contains the Fault handling framework to handle Business faults and Runtime faults.
It uses fault-policies.xml and fault-bindings.xml files to implement fault handling framework.

Fault policies configured with the Fault handling framework overrides the fault handling defined using Catch activities in the BPEL process.
So Faults raised by the BPEL component will be first handled by Fault policy configured. Then it can be sent to Catch activity by Rethrowing the fault from Fault policies configured.

This fault-policies.xml and fault-bindings.xml file can be placed in the same directory as the composite.xml file of Composite application or this files can be referred from MetaDataStore (MDS).  
Referring Fault policy files placed in the same directory from composite.xml

 <property name="oracle.composite.faultPolicyFile">fault-policies.xml</property>
 <property name="oracle.composite.faultBindingFile">fault-bindings.xml</property>

 
Referring Fault policy files placed in MDS from composite.xml file
 

 <property name="oracle.composite.faultPolicyFile">oramds:/apps/mdsstore/fault-policies/fault-policies.xml</property>
 <property name="oracle.composite.faultBindingFile">oramds:/apps/mdsstore/fault-policies/fault-bindings.xml</property>

  
Here is the sample to handle BPEL fault using Custom Java class.

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 version="3.0" id="FaultPolicy_CustomJava" 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>
			<faultName xmlns:bpelx="http://schemas.oracle.com/bpel/extension" name="bpelx:remoteFault">
				<condition>
					<action ref="ora-human-intervention" />
				</condition>
			</faultName>
			<faultName>
				<condition>
					<action ref="java-fault-handler" />
				</condition>
			</faultName>
		</Conditions>
		<Actions>
			<Action id="java-fault-handler">
				<javaAction className="com.bpel.faulthandler.BPELFaultHandler" defaultAction="ora-terminate">
					<returnValue value="OK" ref="ora-human-intervention" />
				</javaAction>
			</Action>
			<Action id="ora-retry">
				<retry>
					<retryCount>3</retryCount>
					<retryInterval>2</retryInterval>
					<exponentialBackoff />
					<retryFailureAction ref="ora-human-intervention" />
				</retry>
			</Action>
			<Action id="ora-rethrow-fault">
				<rethrowFault />
			</Action>
			<Action id="ora-human-intervention">
				<humanIntervention />
			</Action>
			<Action id="ora-terminate">
				<abort />
			</Action>
		</Actions>
	</faultPolicy>
</faultPolicies>

  

fault-bindings.xml

<?xml version="1.0" encoding="UTF-8"?>
<faultPolicyBindings version="3.0"
                     xmlns="http://schemas.oracle.com/bpel/faultpolicy"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <composite faultPolicy="FaultPolicy_CustomJava"/>
</faultPolicyBindings>

  
BPELFaultHandler.java class used to handle BPEL faults

package com.rathinasaba.bpel.faulthandler;

import oracle.integration.platform.faultpolicy.IFaultRecoveryContext;
import oracle.integration.platform.faultpolicy.IFaultRecoveryJavaClass;
import oracle.xml.parser.v2.XMLElement;

import org.apache.log4j.Logger;

import com.collaxa.cube.engine.fp.BPELFaultRecoveryContextImpl;
import com.oracle.bpel.client.BPELFault;
import com.rathinasaba.bpel.faulthandler.util.IElementNames;
import com.rathinasaba.bpel.faulthandler.ws.ExternalServiceManager;

public class BPELFaultHandler implements IFaultRecoveryJavaClass {
	private static final Logger LOG=Logger.getLogger(BPELFaultHandler.class);
	public String handleFault(IFaultRecoveryContext faultCtx) {
		LOG.debug("-------- Executing Custom java Fault Handler ----------");
		if(faultCtx instanceof BPELFaultRecoveryContextImpl){
			BPELFaultRecoveryContextImpl faultImpl = (BPELFaultRecoveryContextImpl) faultCtx;
			//For logging 
			LOG.debug("CompositeInstanceID :"+faultImpl.getCompositeInstanceId());
			LOG.debug("CompositeName :"+faultImpl.getCompositeName());
			LOG.debug("CompositeRevision :"+faultImpl.getProcessDN().getRevision());
			LOG.debug("Title :"+faultImpl.getTitle());
			BPELFault bpelFault = faultImpl.getFault();
			LOG.debug("---- Fault Message ---->"+bpelFault.getMessage());
			XMLElement inputXMLElement=(XMLElement)faultImpl.getVariableData("inputVariable","payload");
			LOG.debug("----- Received Input Document -----");
			XMLElement faultXMLElement=(XMLElement)bpelFault.getPart("payload");
			// To update the external system about the fault occured in BPEL process.
                        //Here the external system is updated with the data extracted from "inputVariable" and the  BPELFault details.
			ExternalServiceManager.getInstance().updateServiceOrderStatus(inputXMLElement, faultXMLElement);
		}
		return "OK";
	}
	
	public void handleRetrySuccess(IFaultRecoveryContext successCtx) {
		LOG.debug("-- Retry Success --");
	}
}

 

This Custom BPELFaultHandler.java class requires BPEL and SOA jars in classpath to execute.   
Steps followed : 
1. Compilee this java class and packed it as jar. [example: BPELFaultHandler.jar]

2. Placed this BPELFaultHandler.jar under this mentioned location.
C:\Saba\soa11g\soa11.1.1.5\Customs\lib

3. Unpacked the oracle.soa.bpel.jar under the SOA Suite installation Location metioned : C:\Saba\soa11g\soa11.1.1.5\Middleware\Oracle_SOA1\soa\modules\oracle.soa.bpel_11.1.1 directory of Oracle SOA Suite installation.

4. Edit the MANIFEST.MF file of oracle.soa.bpel.jar with my BPELFaultHandler.jar location

 

Manifest-Version: 1.0
Implementation-Vendor: Oracle
Ant-Version: Apache Ant 1.7.1
Implementation-Title: Oracle SOA BPEL
Implementation-Version: 11.1.1
Product-Name: Oracle SOA BPEL
Class-Path: bpel1-1-xbeans.jar orabpel-common.jar orabpel.jar bpel_coh
 erence_config.jar orabpel-exts.jar thirdparty.jar bpm-analytics.jar  
 orabpel-thirdparty.jar wsif-binding.jar orabpel-validator.jar monitor
 -rt-xbean.jar oracle.soa.bpmn.jar  ..\..\..\..\..\Customs\lib\CustomF
 aultHandler.jar ..\..\..\..\oracle_common\modules\oracle.xdk_11.1.0\x
 mlparserv2.jar
Created-By: 20.4-b02 (Sun Microsystems Inc.)
Product-Version: 11.1.1.4.0
Specification-Version: 11.1.1
Extension-Name: oracle.soa.bpel

 
5. Pack the jar and restart Managed Server.

Categories: BPEL

Composite Instance States in Oracle SOA 11G Processes

August 3, 2012 Leave a comment

When we are troubleshooting purging soa composites instances or during performance testing of soa composite processes , to understand how many instances are getting Completed , how may instances got faulted ,how how many instances went to NonRecoverable states and etc…. , we can run the below query to get the instance states on SOAINFRA schema.

 

State Description
0 STATE_INITIATED
1 STATE_OPEN_RUNNING
2 STATE_OPEN_SUSPENDED
3 STATE_OPEN_FAULTED
4 STATE_CLOSED_PENDING_CANCEL
5 STATE_CLOSED_COMPLETED
6 STATE_CLOSED_FAULTED
7 STATE_CLOSED_CANCELLED
8 STATE_CLOSED_ABORTED
9 STATE_CLOSED_STALE
10 STATE_CLOSED_ROLLED_BACK

 

-- CUBE_INSTANCE TABLE
SELECT (CASE WHEN STATE=0 THEN 'OPEN AND RUNNING'
             WHEN STATE=1 THEN 'CLOSED AND COMPLETED'
             WHEN STATE=2 THEN 'CLOSED AND FAUTED'
             WHEN STATE=3 THEN 'OPEN AND FAULTED'
             WHEN STATE=4 THEN 'RECOVERY REQUIRED'
             WHEN STATE=34 THEN 'OPEN AND FAULTED'
             WHEN STATE=64 THEN 'CLOSED AND STALE'
             WHEN STATE=32 THEN 'UNKNOWN'
             WHEN STATE=16 THEN 'TERMINATED'
             WHEN STATE=48 THEN 'TERMINATED'
             WHEN STATE=50 THEN 'TERMINATED'
             ELSE STATE || ''
             END) AS STATE, 
             COUNT(*) AS NUM_OF_COMPOSITE_INST FROM DEV_SOAINFRA.CUBE_INSTANCE
                                               WHERE COMPOSITE_NAME='SalesOrder' AND
                                                     CREATION_DATE >= TO_TIMESTAMP('2012-08-02 19:45:00','YYYY-MM-DD HH24:MI:SS') AND 
                                                     CREATION_DATE <= TO_TIMESTAMP('2012-08-02 21:00:00' ,'YYYY-MM-DD HH24:MI:SS') 
                                               GROUP BY STATE;

Callback issue in Oracle SOA 11G clustered environment

May 28, 2012 1 comment

Problem:

In Oracle SOA 11G clustered server environment, “A” asynchronous BPEL process calling “B” asynchronous BPEL process. While “B” process trying to give a callback response to “A” process , “B” process faulted with this exception Client received SOAP Fault from server : oracle.fabric.common.FabricException: java.lang.NullPointerException

<fault>
            <bpelFault>
                        <faultType>0</faultType>
                        <remoteFault>
                                    <part name="summary">
                                                <summary>oracle.j2ee.ws.client.jaxws.JRFSOAPFaultException: Client received SOAP Fault from server : oracle.fabric.common.FabricException: java.lang.NullPointerException</summary>
                                    </part>
                                    <part name="detail">
                                                <detail>Client received SOAP Fault from server : oracle.fabric.common.FabricException: java.lang.NullPointerException</detail>
                                    </part>
                        </remoteFault>
            </bpelFault>
</fault>

 
 
Solution:

1. Set serverURL and callbackServerURL settings of soa-infra.
2. Frontend Host and Frontend HTTP Port for SOA_Cluster.
Please refer the below link for Frontend HTTP Host and Port, as well as determining the callback URL.

Purge instances in Oracle SOA 11G from Java Client

December 4, 2011 1 comment

There are many strategies to managing how to purge oracle soa 11G instances.
Now In this post we will see how to purge Oracle SOA 11G instances from Simple Java Class.

Jars Required :
1. fabric-common.jar ($ORACLE_HOME\oracle_common\modules\oracle.fabriccommon_11.1.1)
2. fabric-runtime.jar ($ORACLE_HOME\Oracle_SOA\soa\modules\oracle.soa.fabric_11.1.1)
3. soa-infra-mgmt.jar ($ORACLE_HOME\oracle_common\soa\modules\oracle.soa.mgmt_11.1.1)
4. wlfullclient.jar ($ORACLE_HOME\wlserver_10.3\server\lib)

Java class to purge oracle soa 11G instances

package com.sample.purgeinstance;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import javax.naming.Context;

import oracle.soa.management.facade.Composite;
import oracle.soa.management.facade.CompositeInstance;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.CompositeFilter;
import oracle.soa.management.util.CompositeInstanceFilter;

public class InstanceManager {

	public Hashtable<String,String> getJNDIProps() {
        Hashtable<String,String> jndiProps = new Hashtable<String,String>();
        jndiProps.put(Context.PROVIDER_URL, "t3://localhost:8011/soa-infra");
        jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
        jndiProps.put(Context.SECURITY_CREDENTIALS, "password1");
        jndiProps.put("dedicated.connection", "true");
        return jndiProps;
    }
	
    public Locator getLocator() {
        try {
            return LocatorFactory.createLocator(getJNDIProps());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
    public void purgeStaleInstances(CompositeFilter compositeFilter, int state) {
        Locator locator = null;
        int purgedInstanceCount = 0;
 
        try {
            locator = this.getLocator();
            CompositeInstanceFilter instanceFilter=new CompositeInstanceFilter();
            System.out.println("------- Setting the process State --------");
            instanceFilter.setState(state);
            /**
             * Retrieve all the instances based on the filter criteria given
             */
            List<Composite> composites=locator.getComposites(compositeFilter);
            System.out.println("## Composite Instance Size: " + composites.size() +" matching composites.");
 
            Iterator compositeIter = composites.iterator();
            while (compositeIter.hasNext()) {
                Composite composite=(Composite)compositeIter.next();
                int compositeInstanceSize=composite.getInstances(instanceFilter).size();
                if (compositeInstanceSize > 0) {
                    purgedInstanceCount += compositeInstanceSize;
                    composite.purgeInstances(instanceFilter);
                    System.out.println("## Purged " + compositeInstanceSize +" instances for composite " + composite.getCompositeDN().getCompositeName());
                } else {
                    System.out.println("## No instances found for composite " + composite.getCompositeDN().getCompositeName());
                }
            }
            System.out.println("## Cleaned a total of " + purgedInstanceCount +" instances.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public static void main(String[] args) {
        InstanceManager instanceManager = new InstanceManager();
        /**
         *Clean instances based on instance state 
         */
        int instanceState = CompositeInstance.STATE_STALE;
        CompositeFilter compositeFilter = new CompositeFilter();        
        System.out.println("------ Starting to purge Instance -----");
        instanceManager.purgeStaleInstances(compositeFilter, instanceState);
    }

}

Purge instance Result

------ Starting to purge Instance -----
SEVERE: Failed to create a DirectConnectionFactory instance (oracle.soa.api.JNDIDirectConnectionFactory): oracle.soa.api.JNDIDirectConnectionFactory
------- Setting the process State --------
## Composite Instance Size: 13 matching composites.
## No instances found for composite SampleHumanTask
## No instances found for composite SimpleApproval
## Purged 5 instances for composite TrainBooking
## Purged 2 instances for composite MediatorDVMTest
## No instances found for composite MediatorXrefTest
## No instances found for composite BPELBAMSensor
## Purged 2 instances for composite AsynExternalBPEL
## Purged 3 instances for composite DVMTest
## Purged 4 instances for composite FaultHandlerBPEL
## Purged 4 instances for composite BPEL_BAM_Monitor
## No instances found for composite FaultHandlingByFaultCode
## No instances found for composite CustomXpathTest
## Purged 1 instances for composite FaulthandlingClientBPEL
## Cleaned a total of 21 instances.

Custom XPath Function in Oracle SOA 11G

September 24, 2011 2 comments

Step:1 Edit the file from the following location :

$MW_HOME/Oracle_SOA/soa/modules/oracle.soa.ext_11.1.1/classes/META-INF/ext-soa-xpath-functions-config.xml

Step:2 Add the following namespace, prefix and function declaration into the file ext-soa-xpath-functions-config.xml

<?xml version = '1.0' encoding = 'UTF-8'?>
<soa-xpath-functions xmlns="http://xmlns.oracle.com/soa/config/xpath"
	version="11.1.1" resourceBundle="oracle.tip.tools.ide.common.resource.IDEMessageBundle"
	xmlns:ora="http://schemas.oracle.com/xpath/extension"
	xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
	xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
	xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
	xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
	xmlns:hello="http://www.oracle.com/XSL/Transform/java/com.room.xpath.sample.SOACustomXpathTest">
	<function name="hello:sayHello">
		<className>com.room.xpath.sample.SOACustomXpathTest</className>
		<return type="string" />
		<params>
			<param name="name" type="string" />
		</params>
		<desc resourceKey="SAYHELLO" />
		<detail>
       <![CDATA[Append Hello with the string input passed]]>
		</detail>
	</function>
</soa-xpath-functions>

Step:3 Write custom xpath function like the following :

package com.room.xpath.sample;

import java.util.List;

import oracle.fabric.common.xml.xpath.IXPathContext;
import oracle.fabric.common.xml.xpath.XPathFunctionException;

public class SOACustomXpathTest {
	/**
	 * @param context  
	 */
	public Object call(IXPathContext context, List list) throws XPathFunctionException {
		String response="";
		try {
			if(list.size()==1 && list.get(0) instanceof String){
			 response=sayHello((String)list.get(0));
			}
			return response;
		} catch (Exception e) {
			e.printStackTrace();
			throw new XPathFunctionException(e.getMessage());
		}
	}

	private static String sayHello(String name) throws Exception{
		if(isEmpty(name)){
			throw new Exception("Please enter name");
		}
		return "Hello "+name+" !!!!";
	}
	
	private static Boolean isEmpty(String text){
		return text==null || "".equals(text.trim());
	}
	
}

Step:4 Build the jar file by including META-INF/ext-soa-xpath-functions-config.xml file with custom xpath class( SOACustomXpathTest.class )

Step:5 Copy the jar to the following location:

$MW_HOME/user_projects/domains/base_domain/lib

Step:6 Xpath function will be called from BPEL process as followed:

hello:sayHello('Rathina')

Step:7 Add the namespace in the component from where you are calling the custom xpath function

xmlns:hello="http://www.oracle.com/XSL/Transform/java/com.room.xpath.sample.SOACustomXpathTest"

Fault Handling in Oracle BPEL by checking the fault variable in fault-policies.xml

September 10, 2011 Leave a comment

Fault Handling in Oracle BPEL by specifically checking the fault variable in the fault element thrown by calling the external web service.

 

1. Snapshot of “sayHello” operation in external Web Service “SayHello.wsdl”

SayHello WSDL

SayHello WSDL

2. Fault Element structure thrown by the external web service

Fault Element Structure

Fault Element Structure

3. fault-policies.xml – Checking fault variable in fault element thrown by external WS

FaultPolicy_TestCondition

FaultPolicy_TestCondition

4. fault-policies.xml file to handle the fault by evaluating the value of the fault variable in the fault element thrown by external web service while calling the external web service from BPEL process.

<?xml version="1.0" encoding="UTF-8"?>
<faultPolicies xmlns="http://schemas.oracle.com/bpel/faultpolicy">
<faultPolicy version="2.0.1" 
                   id="SayHelloPolicy" 
                   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>
        <!-- Fault if wsdlRuntimeLocation is not reachable -->
        <faultName xmlns:bpelx="http://schemas.oracle.com/bpel/extension" name="bpelx:remoteFault">
            <condition>
                <test>$fault.code="WSDLReadingError"</test>
                <action ref="ora-terminate"/>
            </condition>
            <condition>
                <action ref="ora-retry"/>
            </condition>
        </faultName>
        <!-- Fault if SayHelloException is thrown from external service-->
        <!-- WL5G3N1 -Namespace of Exception defined in Fault message of "sayHello" Operation of SayHello.wsdl -->
        <!-- SayHelloException - is the fault name defined in the fault declaration of "sayHello" operation of SayHello.wsdl-->
        <faultName xmlns:WL5G3N1="http://com.test.ws" name="WL5G3N1:SayHelloException">
            <condition>
                <test>$SayHelloException.SayHelloException/java:SayHelloException/java:FaultCode[contains(.,"NOT_AN_ALPHABET")]</test>
                <action ref="ora-retry"/>
            </condition>
        </faultName>            
      </Conditions>
         <Actions>
           <Action id="ora-retry">
            <retry>
                <retryCount>3</retryCount>
                <retryInterval>2</retryInterval><!-- Retry interval in Seconds ( Delay between the retries )-->
                <exponentialBackoff/>
                <retryFailureAction ref="ora-human-intervention"/>
                <!--<retrySuccessAction ref="ora-java"/>-->
               <!-- Exponential back off indicates the next retry attempt is scheduled at 2 x the delay, 
                                          where delay is the current retry interval. 
                                          For example, if the current retry interval is 2 seconds, 
                                          the next retry attempt is scheduled at 4, the next at 8, 
                                          and the next at 16 seconds until the retryCount value is reached.--> 
            </retry>
        </Action>
        <Action id="ora-replay-scope">
            <replayScope/>
        </Action>
        <Action id="ora-rethrow-fault">
            <rethrowFault/>
        </Action>
        <Action id="ora-human-intervention">
            <humanIntervention/>
        </Action>
        <Action id="ora-terminate">
            <abort/>
        </Action>
        <Action id="ora-java">
            <!-- this is user provided class-->
            <javaAction className="com.oracle.bpel.client.config.faultpolicy.TestJavaAction"
                defaultAction="ora-terminate" propertySet="prop-for-billing">
                <returnValue value="REPLAY" ref="ora-terminate"/>
                <returnValue value="RETRHOW" ref="ora-rethrow-fault"/>
                <returnValue value="ABORT" ref="ora-terminate"/>
                <returnValue value="RETRY" ref="ora-retry"/>
                <returnValue value="MANUAL" ref="ora-human-intervention"/>
            </javaAction>
        </Action>
      </Actions>
</faultPolicy>
</faultPolicies>

5. Snapshot of SOA composite application

Composite

Composite

6. Snapshot of BPEL process

FaultHandlingBPEL

FaultHandlingBPEL

7.Result
If the faultCode in the fault element is “NOT_AN_ALPHABET”, the it will retry for 3 times at the interval of 2 seconds as defined in the fault-policies.xml file.

Result