Search in sources :

Example 1 with BpmnError

use of org.activiti.engine.delegate.BpmnError in project Activiti by Activiti.

the class CamelBehavior method handleCamelException.

protected boolean handleCamelException(Exchange exchange, ActivityExecution execution) throws Exception {
    Exception camelException = exchange.getException();
    boolean notHandledByCamel = exchange.isFailed() && camelException != null;
    if (notHandledByCamel) {
        if (camelException instanceof BpmnError) {
            ErrorPropagation.propagateError((BpmnError) camelException, execution);
            return true;
        } else {
            if (ErrorPropagation.mapException(camelException, execution, mapExceptions))
                return true;
            else
                throw new ActivitiException("Unhandled exception on camel route", camelException);
        }
    }
    return false;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiException(org.activiti.engine.ActivitiException) BpmnError(org.activiti.engine.delegate.BpmnError)

Example 2 with BpmnError

use of org.activiti.engine.delegate.BpmnError in project Activiti by Activiti.

the class WebServiceActivityBehavior method execute.

/**
   * {@inheritDoc}
   */
public void execute(ActivityExecution execution) throws Exception {
    MessageInstance message;
    try {
        if (ioSpecification != null) {
            this.ioSpecification.initialize(execution);
            ItemInstance inputItem = (ItemInstance) execution.getVariable(this.ioSpecification.getFirstDataInputName());
            message = new MessageInstance(this.operation.getInMessage(), inputItem);
        } else {
            message = this.operation.getInMessage().createInstance();
        }
        execution.setVariable(CURRENT_MESSAGE, message);
        this.fillMessage(message, execution);
        ProcessEngineConfigurationImpl processEngineConfig = Context.getProcessEngineConfiguration();
        MessageInstance receivedMessage = this.operation.sendMessage(message, processEngineConfig.getWsOverridenEndpointAddresses());
        execution.setVariable(CURRENT_MESSAGE, receivedMessage);
        if (ioSpecification != null) {
            String firstDataOutputName = this.ioSpecification.getFirstDataOutputName();
            if (firstDataOutputName != null) {
                ItemInstance outputItem = (ItemInstance) execution.getVariable(firstDataOutputName);
                outputItem.getStructureInstance().loadFrom(receivedMessage.getStructureInstance().toArray());
            }
        }
        this.returnMessage(receivedMessage, execution);
        execution.setVariable(CURRENT_MESSAGE, null);
        leave(execution);
    } catch (Exception exc) {
        Throwable cause = exc;
        BpmnError error = null;
        while (cause != null) {
            if (cause instanceof BpmnError) {
                error = (BpmnError) cause;
                break;
            }
            cause = cause.getCause();
        }
        if (error != null) {
            ErrorPropagation.propagateError(error, execution);
        } else {
            throw exc;
        }
    }
}
Also used : MessageInstance(org.activiti.engine.impl.bpmn.webservice.MessageInstance) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ItemInstance(org.activiti.engine.impl.bpmn.data.ItemInstance) BpmnError(org.activiti.engine.delegate.BpmnError)

Example 3 with BpmnError

use of org.activiti.engine.delegate.BpmnError in project Activiti by Activiti.

the class ClassDelegate method execute.

// Activity Behavior
public void execute(ActivityExecution execution) throws Exception {
    boolean isSkipExpressionEnabled = SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpression);
    if (!isSkipExpressionEnabled || (isSkipExpressionEnabled && !SkipExpressionUtil.shouldSkipFlowElement(execution, skipExpression))) {
        if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
            ObjectNode taskElementProperties = Context.getBpmnOverrideElementProperties(serviceTaskId, execution.getProcessDefinitionId());
            if (taskElementProperties != null && taskElementProperties.has(DynamicBpmnConstants.SERVICE_TASK_CLASS_NAME)) {
                String overrideClassName = taskElementProperties.get(DynamicBpmnConstants.SERVICE_TASK_CLASS_NAME).asText();
                if (StringUtils.isNotEmpty(overrideClassName) && overrideClassName.equals(className) == false) {
                    className = overrideClassName;
                    activityBehaviorInstance = null;
                }
            }
        }
        if (activityBehaviorInstance == null) {
            activityBehaviorInstance = getActivityBehaviorInstance(execution);
        }
        try {
            activityBehaviorInstance.execute(execution);
        } catch (BpmnError error) {
            ErrorPropagation.propagateError(error, execution);
        } catch (Exception e) {
            if (!ErrorPropagation.mapException(e, execution, mapExceptions)) {
                throw e;
            }
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BpmnError(org.activiti.engine.delegate.BpmnError)

Example 4 with BpmnError

use of org.activiti.engine.delegate.BpmnError in project Activiti by Activiti.

the class ScriptTaskActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines();
    if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
        ObjectNode taskElementProperties = Context.getBpmnOverrideElementProperties(scriptTaskId, execution.getProcessDefinitionId());
        if (taskElementProperties != null && taskElementProperties.has(DynamicBpmnConstants.SCRIPT_TASK_SCRIPT)) {
            String overrideScript = taskElementProperties.get(DynamicBpmnConstants.SCRIPT_TASK_SCRIPT).asText();
            if (StringUtils.isNotEmpty(overrideScript) && overrideScript.equals(script) == false) {
                script = overrideScript;
            }
        }
    }
    boolean noErrors = true;
    try {
        Object result = scriptingEngines.evaluate(script, language, execution, storeScriptVariables);
        if (resultVariable != null) {
            execution.setVariable(resultVariable, result);
        }
    } catch (ActivitiException e) {
        LOGGER.warn("Exception while executing " + execution.getActivity().getId() + " : " + e.getMessage());
        noErrors = false;
        Throwable rootCause = ExceptionUtils.getRootCause(e);
        if (rootCause instanceof BpmnError) {
            ErrorPropagation.propagateError((BpmnError) rootCause, execution);
        } else {
            throw e;
        }
    }
    if (noErrors) {
        leave(execution);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ScriptingEngines(org.activiti.engine.impl.scripting.ScriptingEngines) BpmnError(org.activiti.engine.delegate.BpmnError)

Example 5 with BpmnError

use of org.activiti.engine.delegate.BpmnError in project Activiti by Activiti.

the class SequentialMultiInstanceBehavior method leave.

/**
   * Called when the wrapped {@link ActivityBehavior} calls the 
   * {@link AbstractBpmnActivityBehavior#leave(ActivityExecution)} method.
   * Handles the completion of one instance, and executes the logic for the sequential behavior.    
   */
public void leave(ActivityExecution execution) {
    int loopCounter = getLoopVariable(execution, getCollectionElementIndexVariable()) + 1;
    int nrOfInstances = getLoopVariable(execution, NUMBER_OF_INSTANCES);
    int nrOfCompletedInstances = getLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES) + 1;
    int nrOfActiveInstances = getLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES);
    if (loopCounter != nrOfInstances && !completionConditionSatisfied(execution)) {
        callActivityEndListeners(execution);
    }
    setLoopVariable(execution, getCollectionElementIndexVariable(), loopCounter);
    setLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);
    logLoopDetails(execution, "instance completed", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances);
    if (loopCounter >= nrOfInstances || completionConditionSatisfied(execution)) {
        super.leave(execution);
    } else {
        try {
            executeOriginalBehavior(execution, loopCounter);
        } catch (BpmnError error) {
            // re-throw business fault so that it can be caught by an Error Intermediate Event or Error Event Sub-Process in the process
            throw error;
        } catch (Exception e) {
            throw new ActivitiException("Could not execute inner activity behavior of multi instance behavior", e);
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) BpmnError(org.activiti.engine.delegate.BpmnError)

Aggregations

BpmnError (org.activiti.engine.delegate.BpmnError)10 ActivitiException (org.activiti.engine.ActivitiException)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 Deployment (org.activiti.engine.test.Deployment)3 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)2 Task (org.activiti.engine.task.Task)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)1 ItemInstance (org.activiti.engine.impl.bpmn.data.ItemInstance)1 MessageInstance (org.activiti.engine.impl.bpmn.webservice.MessageInstance)1 ScriptingEngines (org.activiti.engine.impl.scripting.ScriptingEngines)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 SoapFault (org.apache.cxf.binding.soap.SoapFault)1 Fault (org.apache.cxf.interceptor.Fault)1