IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Developing client applications for BPEL processes and tasks > Developing EJB client applications > Developing applications for BPEL processes > Repairing activities

Forcing the completion of an activity

Activities in long-running processes can sometimes encounter faults. If these faults are not caught by a fault handler in the enclosing scope and the associated activity template specifies that the activity stops when an error occurs, the activity is put into the stopped state so that it can be repaired. In this state, you can force the completion of the activity.

You can also force the completion of activities in the running state if, for example, an activity is not responding.

Additional requirements exist for certain types of activities.

Human task activities

You can pass parameters in the force-complete call, such as the message that should have been sent or the fault that should have been raised.

Script activities

You cannot pass parameters in the force-complete call. However, you must set the variables that need to be repaired.

Invoke activities

You can also force the completion of invoke activities that call an asynchronous service that is not a subprocess if these activities are in the running state. You might want to do this, for example, if the asynchronous service is called and it does not respond.


Procedure

  1. List the stopped activities in the stopped state.
    FilterOptions fo = new FilterOptions();
    fo.setSelectedAttributes("AIID");
    fo.setQueryCondition("STATE=STATE_STOPPED AND NAME='CustomOrder'");
    EntityResultSet result = process.queryEntities("ACTIVITY", fo, null, null);

    This action returns the stopped activities for the CustomerOrder process instance.

  2. Complete the activity, for example, a stopped human task activity.

    In this example, an output message is passed.

    if (result.getEntities().size() > 0)
    {
       Entity activityEntity = (Entity) result.getEntities().get(0);
       AIID aiid = (AIID) activityEntity.getAttributeValue("AIID");
    	  ActivityInstanceData activity = process.getActivityInstance(aiid);
      ClientObjectWrapper output = 
            process.createMessage(aiid, activity.getOutputMessageTypeName());
      DataObject myMessage = null;
      if ( output.getObject()!= null && output.getObject() instanceof DataObject )
       {
         myMessage = (DataObject)output.getObject();
         //set the parts in your message, for example, an order number      myMessage.setInt("OrderNo", 4711);
       } 
       boolean continueOnError = true;
       process.forceComplete(aiid, output, continueOnError);}

    This action completes the activity. If an error occurs, the continueOnError parameter determines the action to be taken if a fault is provided with the forceComplete request.

    In the example, continueOnError is true. This value means that if a fault is provided, the activity is put into the failed state. The fault is propagated to the enclosing scopes of the activity until it is either handled or the process scope is reached. The process is then put into the failing state and it eventually reaches the failed state.

Repairing activities


Related concepts:
Continue-on-error behavior of BPEL processes and activities