Tuesday, 23 April 2013

Soa Suite 11g - Fault recovery

Using the Oracle SOA Suite's Infrastructure Management Java API, it's possible to query the BPEL Engine for faults and recover this faults programmatically using the following Facades:
  • Locator: entry point to Facades API.
  • BPELServiceEngine: allows to query for faults, get and set variables data and recovery faults.
  • Fault: allows retrieve fault details information.
  • FaultRecoveryActionTypeConstants: contains Action constants used to recover faults.
To develop the Java code, create a new Java project in jDeveloper and import the following libs:
  • <middleware_home>/oracle_common/modules/oracle.fabriccommon_11.1.1/fabric-common.jar
  • <middleware_home>/jdeveloper/soa/modules/oracle.soa.mgmt_11.1.1/soa-infra-mgmt.jar
  • <middleware_home>/wlserver_10.3/server/lib/weblogic.jar
  • <middleware_home>/jdeveloper/soa/modules/oracle.soa.fabric_11.1.1/oracle-soa-client-api.jar
  • <middleware_home>/oracle_common/webservices/wsclient_extended.jar
The example below shows how to use the API to search for faults using filter, update variable data and do a Retry to recover the fault:
001package br.inf.andrade.soasuite.faultRecovery;
002 
003import java.util.Hashtable;
004import java.util.List;
005 
006import javax.naming.Context;
007 
008import oracle.soa.management.facade.Fault;
009import oracle.soa.management.facade.FaultRecoveryActionTypeConstants;
010import oracle.soa.management.facade.Locator;
011import oracle.soa.management.facade.LocatorFactory;
012import oracle.soa.management.facade.bpel.BPELServiceEngine;
013import oracle.soa.management.util.FaultFilter;
014 
015public class FaultRecovery {
016 
017  private Locator locator = null;
018  private BPELServiceEngine mBPELServiceEngine;
019 
020  public FaultRecovery() {
021    locator = this.getLocator();
022    try {
023      mBPELServiceEngine =
024          (BPELServiceEngine)locator.getServiceEngine(Locator.SE_BPEL);
025    } catch (Exception e) {
026      e.printStackTrace();
027    }
028  }
029 
030  public Hashtable getJndiProps() {
031    Hashtable jndiProps = new Hashtable();
032    jndiProps.put(Context.PROVIDER_URL,
033                  "t3://soaserver11gr1ps2:8001/soa-infra");
034    jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
035                  "weblogic.jndi.WLInitialContextFactory");
036    jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
037    jndiProps.put(Context.SECURITY_CREDENTIALS, "welcome1");
038    jndiProps.put("dedicated.connection", "true");
039    return jndiProps;
040  }
041 
042  public Locator getLocator() {
043 
044    try {
045      return LocatorFactory.createLocator(getJndiProps());
046    } catch (Exception e) {
047      e.printStackTrace();
048    }
049    return null;
050  }
051 
052  public void recoverFaults() {
053    try {
054      System.out.println("Get Recoverable Faults");
055 
056      /*
057       * SEARCH FOR FAULTS
058       */
059 
060      //Set filter according desired criteria
061      FaultFilter filter = new FaultFilter();
062      //filter.setCompositeDN("default/FaultClient!1.0");
063      //filter.setCompositeInstanceId("40001");
064      //filter.setComponentName("FaultClientProcess");
065      //filter.setComponentInstanceId("bpel:40001");
066      //filter.setId("default/FaultClient!1.0*soa_911ae0fd-c5ca-44ae-922c-6641a4e7d51f/FaultClientProcess/40001-BpInv0-BpSeq0.3-3");
067      //filter.setFaultName("{http://xmlns.oracle.com/FaultRecovery_jws/FaultGenerator/FaultGeneratorProcess}BusinessFault");
068      //filter.setLike("%<code>0001%");
069      filter.setRecoverable(true);
070 
071      //Get faults using defined filter
072      List<fault> faultList = mBPELServiceEngine.getFaults(filter);
073      for (Fault fault : faultList) {
074        System.out.println("=============================================================================================================");
075        System.out.println("         Composite DN: " +
076                           fault.getCompositeDN().getStringDN());
077        System.out.println("Composite Instance ID: " +
078                           fault.getCompositeInstanceId());
079        System.out.println("       Component Name: " +
080                           fault.getComponentName());
081        System.out.println("Component Instance ID: " +
082                           fault.getComponentInstanceId());
083        System.out.println("        Activity Name: " + fault.getLabel());
084        System.out.println("             Fault ID: " + fault.getId());
085        System.out.println("           Fault Name: " + fault.getName());
086        System.out.println("     Recoverable flag: " + fault.isRecoverable());
087        System.out.println("        Fault Message: " + fault.getMessage());
088 
089        //Get fault variables
090        String[] variables = mBPELServiceEngine.getVariableNames(fault);
091        System.out.println("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
092        System.out.println("Variables:");
093        for (int i = 0; i < variables.length; i++) {
094          System.out.println("* Name: " + variables[i]);
095        }
096 
097        //Get operation input variable data, correct it and update the variable content
098        System.out.println("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
099        System.out.println("Operation Input Variable Data:");
100        String value =
101          mBPELServiceEngine.getVariable(fault, "invokeFaultGenerator_process_InputVariable");
102        System.out.println("Old value: " + value);
103        value = value.replace("BusinessFault", "Any string");
104        System.out.println("New value: " + value);
105        mBPELServiceEngine.setVariable(fault,
106                                       "invokeFaultGenerator_process_InputVariable",
107                                       value);
108 
109        //Retry each fault
110        mBPELServiceEngine.recoverFault(fault,
111                                        FaultRecoveryActionTypeConstants.ACTION_RETRY,
112                                        null);
113      }
114 
115      //Instead of recover each fault individually, you can recover all faults in a single API call
116      //mBPELServiceEngine.recoverFaults(faultList.toArray(new Fault[faultList.size()]), FaultRecoveryActionTypeConstants.ACTION_RETRY);
117 
118 
119    } catch (Exception e) {
120      e.printStackTrace();
121    }
122  }
123 
124  public static void main(String[] args) {
125    FaultRecovery faultRecovery = new FaultRecovery();
126    faultRecovery.recoverFaults();
127  }
128}
To download this source code together with 2 SOA Composites to simulate a Business Fault, click here.

for more info.
http://blog.andrade.inf.br/2010/07/soa-suite-11g-fault-recovery.html

No comments:

Post a Comment