use of org.kie.internal.runtime.error.ExecutionErrorHandler in project jbpm by kiegroup.
the class AsyncWorkItemHandlerCmdCallback method onCommandError.
@Override
public void onCommandError(CommandContext ctx, final Throwable exception) {
final Long processInstanceId = (Long) ctx.getData("processInstanceId");
final WorkItem workItem = (WorkItem) ctx.getData("workItem");
// find the right runtime to do the complete
RuntimeManager manager = getRuntimeManager(ctx);
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
final ExecutionErrorHandler errorHandler = getExecutionErrorHandler(manager);
try {
boolean isErrorHandled = engine.getKieSession().execute(new ExecutableCommand<Boolean>() {
private static final long serialVersionUID = 1L;
@Override
public Boolean execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(processInstanceId);
NodeInstance nodeInstance = getNodeInstance(workItem, processInstance);
Throwable actualException = exception;
if (actualException instanceof AsyncJobException) {
actualException = exception.getCause();
}
String exceptionName = actualException.getClass().getName();
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName);
if (exceptionScopeInstance != null) {
logger.debug("Handling job error '{}' via process error handling", actualException.getMessage());
exceptionScopeInstance.handleException(exceptionName, actualException);
return true;
} else {
logger.debug("No process level error handling for '{}' letting it to be handled by execution errors", exception.getMessage());
errorHandler.processing(nodeInstance);
return false;
}
}
});
if (!isErrorHandled) {
logger.debug("Error '{}' was not handled on process level, handling it via execution errors mechanism", exception.getMessage());
errorHandler.handle(exception);
}
} catch (Exception e) {
logger.error("Error when handling callback from executor", e);
} finally {
manager.disposeRuntimeEngine(engine);
closeErrorHandler(manager);
}
}
Aggregations