Search in sources :

Example 1 with ErrorEventDefinition

use of org.camunda.bpm.engine.impl.bpmn.parser.ErrorEventDefinition in project camunda-bpm-platform by camunda.

the class AbstractBpmnActivityBehavior method propagateError.

protected void propagateError(String errorCode, String errorMessage, Exception origException, ActivityExecution execution) throws Exception {
    ActivityExecutionHierarchyWalker walker = new ActivityExecutionHierarchyWalker(execution);
    final ErrorDeclarationForProcessInstanceFinder errorDeclarationFinder = new ErrorDeclarationForProcessInstanceFinder(origException, errorCode, execution.getActivity());
    ActivityExecutionMappingCollector activityExecutionMappingCollector = new ActivityExecutionMappingCollector(execution);
    walker.addScopePreVisitor(errorDeclarationFinder);
    walker.addExecutionPreVisitor(activityExecutionMappingCollector);
    // map variables to super executions in the hierarchy of called process instances
    walker.addExecutionPreVisitor(new OutputVariablesPropagator());
    try {
        walker.walkUntil(new ReferenceWalker.WalkCondition<ActivityExecutionTuple>() {

            @Override
            public boolean isFulfilled(ActivityExecutionTuple element) {
                return errorDeclarationFinder.getErrorEventDefinition() != null || element == null;
            }
        });
    } catch (Exception e) {
        // separate the exception handling to support a fail-safe error propagation
        throw new ErrorPropagationException(e);
    }
    PvmActivity errorHandlingActivity = errorDeclarationFinder.getErrorHandlerActivity();
    // process the error
    if (errorHandlingActivity == null) {
        if (origException == null) {
            if (Context.getCommandContext().getProcessEngineConfiguration().isEnableExceptionsAfterUnhandledBpmnError()) {
                throw LOG.missingBoundaryCatchEventError(execution.getActivity().getId(), errorCode);
            } else {
                LOG.missingBoundaryCatchEvent(execution.getActivity().getId(), errorCode);
                execution.end(true);
            }
        } else {
            // throw original exception
            throw origException;
        }
    } else {
        ErrorEventDefinition errorDefinition = errorDeclarationFinder.getErrorEventDefinition();
        PvmExecutionImpl errorHandlingExecution = activityExecutionMappingCollector.getExecutionForScope(errorHandlingActivity.getEventScope());
        if (errorDefinition.getErrorCodeVariable() != null) {
            errorHandlingExecution.setVariable(errorDefinition.getErrorCodeVariable(), errorCode);
        }
        if (errorDefinition.getErrorMessageVariable() != null) {
            errorHandlingExecution.setVariable(errorDefinition.getErrorMessageVariable(), errorMessage);
        }
        errorHandlingExecution.executeActivity(errorHandlingActivity);
    }
}
Also used : ActivityExecutionMappingCollector(org.camunda.bpm.engine.impl.tree.ActivityExecutionMappingCollector) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) OutputVariablesPropagator(org.camunda.bpm.engine.impl.tree.OutputVariablesPropagator) ActivityExecutionTuple(org.camunda.bpm.engine.impl.tree.ActivityExecutionTuple) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ActivityExecutionHierarchyWalker(org.camunda.bpm.engine.impl.tree.ActivityExecutionHierarchyWalker) ReferenceWalker(org.camunda.bpm.engine.impl.tree.ReferenceWalker) ErrorEventDefinition(org.camunda.bpm.engine.impl.bpmn.parser.ErrorEventDefinition)

Aggregations

ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 ErrorEventDefinition (org.camunda.bpm.engine.impl.bpmn.parser.ErrorEventDefinition)1 PvmActivity (org.camunda.bpm.engine.impl.pvm.PvmActivity)1 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)1 ActivityExecutionHierarchyWalker (org.camunda.bpm.engine.impl.tree.ActivityExecutionHierarchyWalker)1 ActivityExecutionMappingCollector (org.camunda.bpm.engine.impl.tree.ActivityExecutionMappingCollector)1 ActivityExecutionTuple (org.camunda.bpm.engine.impl.tree.ActivityExecutionTuple)1 OutputVariablesPropagator (org.camunda.bpm.engine.impl.tree.OutputVariablesPropagator)1 ReferenceWalker (org.camunda.bpm.engine.impl.tree.ReferenceWalker)1