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;
}
}
}
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();
}
}
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());
}
}
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());
}
}
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);
}
}
Aggregations