//***************************************************************************** //* * //* "This sample program is provided AS IS and may be used, executed, copied * //* and modified without royalty payment by customer * //* (a) for its own instruction and study, * //* (b) in order to develop applications designed to run with an * //* IBM WebSphere product, either for customer's own internal use or for * //* redistribution by customer, as part of such an application, in * //* customer's own products." * //* * //* Product 5655-FLW, * //* (C) COPYRIGHT International Business Machines Corp., 2006, 2009 * //* All Rights Reserved * Licensed Materials - Property of IBM * //* * //***************************************************************************** //* * //* DISCLAIMER * //* * //* This material contains programming source code for your consideration. * //* These examples have not been thoroughly tested under all conditions. * //* IBM, therefore, cannot guarantee or imply reliability, serviceability, * //* or function of these programs. * //* ALL PROGRAMS CONTAINED HEREIN ARE PROVIDED TO YOU "AS IS", WITHOUT ANY * //* WARRANTIES (EXPRESS OR IMPLIED) OR SUPPORT WHATSOEVER, INCLUDING BUT * //* NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS * //* FOR A PARTICULAR PURPOSE. * //* * //***************************************************************************** /* * If an error is encountered inside a staff activity and the corresponding * fault is not caught on the enclosing scope, the activity is put into the * stopped state if the associated activity template specifies that * the activity stops when an error occurs. * In this situation, you can retry the execution of the activity by passing * a new input message. * The caller must be an administrator of the associated process instance. */ import java.util.TimeZone; import com.ibm.bpe.api.AIID; import com.ibm.bpe.api.ActivityInstanceData; import com.ibm.bpe.api.BusinessFlowManager; import com.ibm.bpe.api.ClientObjectWrapper; import com.ibm.bpe.api.QueryResultSet; import commonj.sdo.DataObject; public class ForceRetry { public static void main(String[] args) { try { // initialize context and access the remote interface for the // BusinessFlowManager bean BusinessFlowManager bfm = ApiHelper.initializeBFM(); String processTemplateName = "OrderApprovalProcess"; // retrieve all stopped activities that belong to the Order Approval process. String selectClause = "DISTINCT ACTIVITY.AIID "; String whereClause = "ACTIVITY.STATE = ACTIVITY.STATE.STATE_STOPPED AND " + "ACTIVITY.KIND = ACTIVITY.KIND.KIND_STAFF AND " + "PROCESS_INSTANCE.STATE = PROCESS_INSTANCE.STATE.STATE_RUNNING AND " + "PROCESS_TEMPLATE.NAME = '" + processTemplateName + "'"; QueryResultSet result = bfm.query( selectClause, whereClause, (String)null, (Integer)null, (TimeZone)null ); System.out.println( "\n > query(), result size: " + result.size()); if ( result.size() == 0 ) { System.exit(0); } AIID aiid = null; while (result.next()) { aiid = (AIID) result.getOID(1); ActivityInstanceData activity = bfm.getActivityInstance(aiid); MyTrace.trace( activity, "activity retrieved"); // Create the input message and set new initial values ClientObjectWrapper input = bfm.createMessage( aiid, activity.getInputMessageTypeName() ); if (input.getObject()!= null && input.getObject() instanceof DataObject ) { DataObject inputMessage = (DataObject)input.getObject(); MyTrace.trace(inputMessage); // set the initial values, for instance: String request = "approvalRequest"; DataObject dataObject = inputMessage.createDataObject( request ); // set the initial values in the input message dataObject.setString("requester", "Smith"); dataObject.setString("item", "item_3738"); dataObject.setInt("number", 1); dataObject.setDouble("price", 1000); dataObject.setString("reason", "urgent"); MyTrace.trace(dataObject, "new equipment"); inputMessage.setDataObject(request, dataObject); } else { System.out.println(" input.getObject() == null"); System.out.println(" processing not successful."); System.exit(0); } // Retry the execution of the activity. // If a system error occurs and if you had specified continueOnError == false, // the activity stays in the stopped state. // If a system error occurs and if you had specified continueOnError == true, // the activity is put into the failed execution state. In this case // the process is put into the failing state. boolean continueOnError = true; bfm.forceRetry( aiid, input, continueOnError ); MyTrace.trace( aiid, "activity after calling forceRetry", bfm); } System.out.println("\n successfully processed \n"); System.exit(0); } catch ( com.ibm.bpe.api.ProcessException xcpt) { System.out.println(" " + xcpt.getMessage()); } catch ( java.rmi.RemoteException xcpt ) { System.out.println(" " + xcpt.getMessage()); } finally { System.exit(0); } } }