Search in sources :

Example 6 with BpmnError

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

the class ServiceTaskExpressionActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    Object value = null;
    try {
        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_EXPRESSION)) {
                    String overrideExpression = taskElementProperties.get(DynamicBpmnConstants.SERVICE_TASK_EXPRESSION).asText();
                    if (StringUtils.isNotEmpty(overrideExpression) && overrideExpression.equals(expression.getExpressionText()) == false) {
                        expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(overrideExpression);
                    }
                }
            }
            value = expression.getValue(execution);
            if (resultVariable != null) {
                execution.setVariable(resultVariable, value);
            }
        }
        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 : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BpmnError(org.activiti.engine.delegate.BpmnError)

Example 7 with BpmnError

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

the class WebServiceTaskTest method testFaultManagement.

@Deployment
public void testFaultManagement() throws Exception {
    assertEquals(-1, webServiceMock.getCount());
    // Expected fault catched with a boundary error event
    webServiceMock.setTo(Integer.MAX_VALUE);
    ProcessInstance processInstanceWithExpectedFault = runtimeService.startProcessInstanceByKey("webServiceInvocation");
    waitForJobExecutorToProcessAllJobs(10000L, 250L);
    assertTrue(processInstanceWithExpectedFault.isEnded());
    final List<HistoricProcessInstance> historicProcessInstanceWithExpectedFault = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceWithExpectedFault.getId()).list();
    assertEquals(1, historicProcessInstanceWithExpectedFault.size());
    assertEquals("theEndWithError", historicProcessInstanceWithExpectedFault.get(0).getEndActivityId());
    // RuntimException occurring during processing of the web-service, so not catched in the process definition. The RuntimeException
    // is embedded as an unexpected fault at web-service server side
    webServiceMock.setTo(123456);
    try {
        runtimeService.startProcessInstanceByKey("webServiceInvocation");
    } catch (ActivitiException e) {
        assertFalse("Exception processed as Business fault", e instanceof BpmnError);
        assertTrue(e.getCause() instanceof SoapFault);
    }
    // Unexpected fault at ws-client side invoking the web-service, so not catched in the process definition
    server.stop();
    try {
        runtimeService.startProcessInstanceByKey("webServiceInvocation");
    } catch (ActivitiException e) {
        assertFalse("Exception processed as Business fault", e instanceof BpmnError);
        assertTrue(e.getCause() instanceof Fault);
    } finally {
        server.start();
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) SoapFault(org.apache.cxf.binding.soap.SoapFault) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Fault(org.apache.cxf.interceptor.Fault) SoapFault(org.apache.cxf.binding.soap.SoapFault) BpmnError(org.activiti.engine.delegate.BpmnError) Deployment(org.activiti.engine.test.Deployment)

Example 8 with BpmnError

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

the class BoundaryErrorEventTest method testUncaughtErrorOnCallActivity.

@Deployment(resources = { "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.testUncaughtErrorOnCallActivity-parent.bpmn20.xml", "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.subprocess.bpmn20.xml" })
public void testUncaughtErrorOnCallActivity() {
    runtimeService.startProcessInstanceByKey("uncaughtErrorOnCallActivity");
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("Task in subprocess", task.getName());
    try {
        // Completing the task will reach the end error event,
        // which is never caught in the process
        taskService.complete(task.getId());
    } catch (BpmnError e) {
        assertTextPresent("No catching boundary event found for error with errorCode 'myError', neither in same process nor in parent process", e.getMessage());
    }
}
Also used : Task(org.activiti.engine.task.Task) BpmnError(org.activiti.engine.delegate.BpmnError) Deployment(org.activiti.engine.test.Deployment)

Example 9 with BpmnError

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

the class BoundaryErrorEventTest method testUncaughtError.

@Deployment(resources = { "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.subprocess.bpmn20.xml" })
public void testUncaughtError() {
    runtimeService.startProcessInstanceByKey("simpleSubProcess");
    Task task = taskService.createTaskQuery().singleResult();
    assertEquals("Task in subprocess", task.getName());
    try {
        // Completing the task will reach the end error event,
        // which is never caught in the process
        taskService.complete(task.getId());
        fail("No catching boundary event found for error with errorCode 'myError', neither in same process nor in parent process but no Exception is thrown");
    } catch (BpmnError e) {
        assertTextPresent("No catching boundary event found for error with errorCode 'myError', neither in same process nor in parent process", e.getMessage());
    }
}
Also used : Task(org.activiti.engine.task.Task) BpmnError(org.activiti.engine.delegate.BpmnError) Deployment(org.activiti.engine.test.Deployment)

Example 10 with BpmnError

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

the class SecureJavascriptTaskActivityBehavior method execute.

@Override
public void execute(ActivityExecution execution) throws Exception {
    ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) execution.getEngineServices().getProcessEngineConfiguration();
    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 = SecureJavascriptUtil.evaluateScript(execution, script, config.getBeans());
        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) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) 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