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