org.activiti.engine.delegate.BpmnError Java Examples

The following examples show how to use org.activiti.engine.delegate.BpmnError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MockJavaDelegate.java    From herd with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("all")
public void executeImpl(DelegateExecution execution) throws Exception
{
    if (activitiHelper.getExpressionVariableAsString(exceptionToThrow, execution) != null)
    {
        if (activitiHelper.getExpressionVariableAsString(exceptionToThrow, execution).equals(EXCEPTION_BPMN_ERROR))
        {
            throw new BpmnError(EXCEPTION_BPMN_ERROR);
        }
        else if (activitiHelper.getExpressionVariableAsString(exceptionToThrow, execution).equals(EXCEPTION_RUNTIME))
        {
            throw new RuntimeException(EXCEPTION_RUNTIME);
        }
    }
}
 
Example #2
Source File: BaseJavaDelegate.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * Handles any exception thrown by an Activiti task.
 *
 * @param execution The execution which identifies the task.
 * @param exception The exception that has been thrown
 *
 * @throws Exception Some exceptions may choose to bubble up the exception
 */
protected void handleException(DelegateExecution execution, Exception exception) throws Exception
{
    // Set the error status and stack trace as workflow variables.
    activitiRuntimeHelper.setTaskErrorInWorkflow(execution, exception.getMessage(), exception);

    // Continue throwing the original exception and let workflow handle it with a Boundary event handler.
    if (exception instanceof BpmnError)
    {
        throw exception;
    }

    // Log the error if the exception should be reported.
    if (errorInformationExceptionHandler.isReportableError(exception))
    {
        LOGGER.error("{} Unexpected error occurred during task. activitiTaskName=\"{}\"", activitiHelper.getProcessIdentifyingInformation(execution),
            getClass().getSimpleName(), exception);
    }
}
 
Example #3
Source File: MultiInstanceActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;
    if (getLocalLoopVariable(activityExecution, getCollectionElementIndexVariable()) == null) {
        try {
            createInstances(activityExecution);
        } catch (BpmnError error) {
            ErrorPropagation.propagateError(error, activityExecution);
        }

        if (resolveNrOfInstances(activityExecution) == 0) {
            leave(activityExecution);
        }
    } else {
        innerActivityBehavior.execute(execution);
    }
}
 
Example #4
Source File: ErrorPropagation.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static void propagateError(String errorCode, ActivityExecution execution) {

        while (execution != null) {
            String eventHandlerId = findLocalErrorEventHandler(execution, errorCode);
            if (eventHandlerId != null) {
                executeCatch(eventHandlerId, execution, errorCode);
                break;
            }

            if (execution.isProcessInstanceType()) {
                // dispatch process completed event
                if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
                    Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                            ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT, execution));
                }
            }
            execution = getSuperExecution(execution);
        }
        if (execution == null) {
            throw new BpmnError(errorCode, "No catching boundary event found for error with errorCode '"
                    + errorCode + "', neither in same process nor in parent process");
        }
    }
 
Example #5
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
        "org/activiti5/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());
  }
}
 
Example #6
Source File: MultiInstanceActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void execute(DelegateExecution execution) {
  if (getLocalLoopVariable(execution, getCollectionElementIndexVariable()) == null) {

    int nrOfInstances = 0;

    try {
      nrOfInstances = createInstances(execution);
    } catch (BpmnError error) {
      ErrorPropagation.propagateError(error, execution);
    }

    if (nrOfInstances == 0) {
      super.leave(execution);
    }

  } else {
    Context.getCommandContext().getHistoryManager().recordActivityStart((ExecutionEntity) execution);

    innerActivityBehavior.execute(execution);
  }
}
 
Example #7
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
        "org/activiti5/engine/test/bpmn/event/error/BoundaryErrorEventTest.testUncaughtErrorOnCallActivity-parent.bpmn20.xml",
        "org/activiti5/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());
  }
}
 
Example #8
Source File: ThrowBpmnErrorDelegate.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
  Integer executionsBeforeError = (Integer) execution.getVariable("executionsBeforeError");
  Integer executions = (Integer) execution.getVariable("executions");
  if (executions == null) {
    executions = 0;
  }
  executions++;
  if (executionsBeforeError == null || executionsBeforeError < executions) {
    throw new BpmnError("23", "This is a business fault, which can be caught by a BPMN Error Event.");
  } else {
    execution.setVariable("executions", executions);
  }
}
 
Example #9
Source File: ThrowBpmnExceptionBean.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Handler
public void throwNonBpmnException() throws Exception {
  LOG.debug("throwing non bpmn bug");

  switch (getExceptionType()) {
  case NO_EXCEPTION:
    break;
  case NON_BPMN_EXCEPTION:
    throw new Exception("arbitary non bpmn exception");
  case BPMN_EXCEPTION:
    throw new BpmnError("testError");
  }
}
 
Example #10
Source File: SecureJavascriptTaskActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
  ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) Context.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.getCurrentActivityId() + " : " + 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);
  }
}
 
Example #11
Source File: UncaughtErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test events related to error-events, thrown from within process-execution (eg. service-task).
 */
@Deployment
public void testUncaughtError() throws Exception {
	try {
		runtimeService.startProcessInstanceByKey("errorProcess");
		fail("Exception BPMN  error excepted due to not caught exception");
	} catch (BpmnError e) {
		
	}
}
 
Example #12
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {
        "org/activiti5/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorThrownByJavaDelegateOnCallActivity-child.bpmn20.xml"
})
public void testUncaughtErrorThrownByJavaDelegateOnServiceTask() {
  try {
    runtimeService.startProcessInstanceByKey("catchErrorThrownByJavaDelegateOnCallActivity-child");
  } catch (BpmnError e) {
    assertTextPresent("No catching boundary event found for error with errorCode '23', neither in same process nor in parent process", e.getMessage());
  }
}
 
Example #13
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {
        "org/activiti5/engine/test/bpmn/event/error/BoundaryErrorEventTest.testUncaughtErrorThrownByJavaDelegateOnCallActivity-parent.bpmn20.xml",
        "org/activiti5/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorThrownByJavaDelegateOnCallActivity-child.bpmn20.xml"
})
public void testUncaughtErrorThrownByJavaDelegateOnCallActivity() {
  try {
    runtimeService.startProcessInstanceByKey("uncaughtErrorThrownByJavaDelegateOnCallActivity-parent");
  } catch (BpmnError e) {
    assertTextPresent("No catching boundary event found for error with errorCode '23', neither in same process nor in parent process", e.getMessage());
  }
}
 
Example #14
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {
          "org/activiti5/engine/test/bpmn/event/error/BoundaryErrorEventTest.testUncaughtErrorOnScriptTask.bpmn20.xml"
})
public void testUncaughtErrorOnScriptTask() {
  try {
    String procId = runtimeService.startProcessInstanceByKey("uncaughtErrorOnScriptTask").getId();
    fail("The script throws error event with errorCode 'errorUncaught', but no catching boundary event was defined. An exception is expected which did not occur");
    assertProcessEnded(procId);
  } catch (BpmnError e) {
  	assertTextPresent("No catching boundary event found for error with errorCode 'errorUncaught', neither in same process nor in parent process (errorCode='errorUncaught')", e.getMessage());
  }
}
 
Example #15
Source File: ThrowBpmnExceptionBean.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Handler
public void throwNonBpmnException() throws Exception {
  LOG.debug("throwing non bpmn bug");

  switch (getExceptionType()) {
  case NO_EXCEPTION:
    break;
  case NON_BPMN_EXCEPTION:
    throw new Exception("arbitary non bpmn exception");
  case BPMN_EXCEPTION:
    throw new BpmnError("testError");
  }
}
 
Example #16
Source File: ThrowBpmnErrorDelegate.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
    Integer executionsBeforeError = (Integer) execution.getVariable("executionsBeforeError");
    Integer executions = (Integer) execution.getVariable("executions");
    if (executions == null) {
        executions = 0;
    }
    executions++;
    if (executionsBeforeError == null || executionsBeforeError < executions) {
        throw new BpmnError("23", "This is a business fault, which can be caught by a BPMN Error Event.");
    } else {
        execution.setVariable("executions", executions);
    }
}
 
Example #17
Source File: ThrowBpmnErrorDelegate.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
    Integer executionsBeforeError = (Integer) execution.getVariable("executionsBeforeError");
    Integer executions = (Integer) execution.getVariable("executions");
    if (executions == null) {
        executions = 0;
    }
    executions++;
    if (executionsBeforeError == null || executionsBeforeError < executions) {
        throw new BpmnError("23", "This is a business fault, which can be caught by a BPMN Error Event.");
    } else {
        execution.setVariable("executions", executions);
    }
}
 
Example #18
Source File: ClassDelegate.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;

    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)) {
                className = overrideClassName;
                activityBehaviorInstance = null;
            }
        }
    }

    if (activityBehaviorInstance == null) {
        activityBehaviorInstance = getActivityBehaviorInstance(activityExecution);
    }

    try {
        activityBehaviorInstance.execute(execution);
    } catch (BpmnError error) {
        ErrorPropagation.propagateError(error, activityExecution);
    } catch (RuntimeException e) {
        if (!ErrorPropagation.mapException(e, activityExecution, mapExceptions))
            throw e;
    }
}
 
Example #19
Source File: ScriptTaskActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;
    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)) {
                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 {} : {}", activityExecution.getActivity().getId(), e.getMessage());

        noErrors = false;
        Throwable rootCause = ExceptionUtils.getRootCause(e);
        if (rootCause instanceof BpmnError) {
            ErrorPropagation.propagateError((BpmnError) rootCause, activityExecution);
        } else {
            throw e;
        }
    }
    if (noErrors) {
        leave(activityExecution);
    }
}
 
Example #20
Source File: SequentialMultiInstanceBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * 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.
 */
@Override
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);
        }
    }
}
 
Example #21
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.testUncaughtErrorThrownByJavaDelegateOnCallActivity-parent.bpmn20.xml",
    "org/activiti/engine/test/bpmn/event/error/BoundaryErrorEventTest.testCatchErrorThrownByJavaDelegateOnCallActivity-child.bpmn20.xml" })
public void testUncaughtErrorThrownByJavaDelegateOnCallActivity() {
  try {
    runtimeService.startProcessInstanceByKey("uncaughtErrorThrownByJavaDelegateOnCallActivity-parent");
  } catch (BpmnError e) {
    assertTextPresent("No catching boundary event found for error with errorCode '23', neither in same process nor in parent process", e.getMessage());
  }
}
 
Example #22
Source File: ThrowBpmnErrorDelegate.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
  Integer executionsBeforeError = (Integer) execution.getVariable("executionsBeforeError");
  Integer executions = (Integer) execution.getVariable("executions");
  if (executions == null) {
    executions = 0;
  }
  executions++;
  if (executionsBeforeError == null || executionsBeforeError < executions) {
    throw new BpmnError("23", "This is a business fault, which can be caught by a BPMN Error Event.");
  } else {
    execution.setVariable("executions", executions);
  }
}
 
Example #23
Source File: DefaultActiviti5CompatibilityHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void propagateError(BpmnError bpmnError, DelegateExecution execution) {
  try {
    org.activiti5.engine.delegate.BpmnError activiti5BpmnError = new org.activiti5.engine.delegate.BpmnError(bpmnError.getErrorCode(), bpmnError.getMessage());
    ErrorPropagation.propagateError(activiti5BpmnError, (ActivityExecution) execution);
  } catch (org.activiti5.engine.ActivitiException e) {
    handleActivitiException(e);
  }
}
 
Example #24
Source File: DefaultActiviti5CompatibilityHandler.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void handleActivitiException(org.activiti5.engine.ActivitiException e) {
  if (e instanceof org.activiti5.engine.delegate.BpmnError) {
    org.activiti5.engine.delegate.BpmnError activiti5BpmnError = (org.activiti5.engine.delegate.BpmnError) e;
    throw new BpmnError(activiti5BpmnError.getErrorCode(), activiti5BpmnError.getMessage());
    
  } else if (e instanceof org.activiti5.engine.ActivitiClassLoadingException) {
    throw new ActivitiClassLoadingException(e.getMessage(), e.getCause());
    
  } else if (e instanceof org.activiti5.engine.ActivitiObjectNotFoundException) {
    org.activiti5.engine.ActivitiObjectNotFoundException activiti5ObjectNotFoundException = (org.activiti5.engine.ActivitiObjectNotFoundException) e;
    throw new ActivitiObjectNotFoundException(activiti5ObjectNotFoundException.getMessage(), 
        activiti5ObjectNotFoundException.getObjectClass(), activiti5ObjectNotFoundException.getCause());
    
  } else if (e instanceof org.activiti5.engine.ActivitiOptimisticLockingException) {
    throw new ActivitiOptimisticLockingException(e.getMessage());
    
  } else if (e instanceof org.activiti5.engine.ActivitiIllegalArgumentException) {
    throw new ActivitiIllegalArgumentException(e.getMessage(), e.getCause());
    
  } else {
    if (e.getCause() instanceof org.activiti5.engine.ActivitiClassLoadingException) {
      throw new ActivitiException(e.getMessage(), new ActivitiClassLoadingException(e.getCause().getMessage(), e.getCause().getCause()));
    } else if (e.getCause() instanceof org.activiti5.engine.impl.javax.el.PropertyNotFoundException) {
      throw new ActivitiException(e.getMessage(), new PropertyNotFoundException(e.getCause().getMessage(), e.getCause().getCause()));
    } else if (e.getCause() instanceof org.activiti5.engine.ActivitiException) {
      throw new ActivitiException(e.getMessage(), new ActivitiException(e.getCause().getMessage(), e.getCause().getCause()));
    } else {
      throw new ActivitiException(e.getMessage(), e.getCause());
    }
  }
}
 
Example #25
Source File: ContinueMultiInstanceOperation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeSynchronous(FlowNode flowNode) {
  
  // Execution listener
  if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) {
    executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START);
  }
  
  commandContext.getHistoryManager().recordActivityStart(execution);
  
  // Execute actual behavior
  ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior();
  if (activityBehavior != null) {
    logger.debug("Executing activityBehavior {} on activity '{}' with execution {}", activityBehavior.getClass(), flowNode.getId(), execution.getId());
    
    if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
      Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createActivityEvent(ActivitiEventType.ACTIVITY_STARTED, flowNode.getId(), flowNode.getName(), execution.getId(),
              execution.getProcessInstanceId(), execution.getProcessDefinitionId(), flowNode));
    }
    
    try {
      activityBehavior.execute(execution);
    } 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
      ErrorPropagation.propagateError(error, execution);
    } catch (RuntimeException e) {
      if (LogMDC.isMDCEnabled()) {
        LogMDC.putMDCExecution(execution);
      }
      throw e;
    }
  } else {
    logger.debug("No activityBehavior on activity '{}' with execution {}", flowNode.getId(), execution.getId());
  }
}
 
Example #26
Source File: ClassDelegate.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
  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();
    }

    try {
      activityBehaviorInstance.execute(execution);
    } catch (BpmnError error) {
      ErrorPropagation.propagateError(error, execution);
    } catch (RuntimeException e) {
      if (!ErrorPropagation.mapException(e, (ExecutionEntity) execution, mapExceptions))
        throw e;
    }
  }
}
 
Example #27
Source File: ScriptTaskActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {

    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.getCurrentFlowElement().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);
    }
  }
 
Example #28
Source File: UncaughtErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test events related to error-events, thrown from within process-execution (eg. service-task).
 */
@Deployment
public void testUncaughtError() throws Exception {
  try {
    runtimeService.startProcessInstanceByKey("errorProcess");
    fail("Exception BPMN  error excepted due to not caught exception");
  } catch (BpmnError e) {

  }
}
 
Example #29
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@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());
  }
}
 
Example #30
Source File: BoundaryErrorEventTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@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());
  }
}