@Override public String getMessage() { return MessageFormat.format("[{0}:{4} - {1}:{2}] -- {3}", getProcessId(), (getNodeName() == null ? "?" : getNodeName()), (getNodeId() == 0 ? "?" : getNodeId()), (getCause() == null ? getMessage() : getCause().getMessage()), getProcessInstanceId()); }
private void throwWorkflowRuntimeException(NodeInstanceContainer nodeInstanceContainer, ProcessInstance processInstance, String msg, Exception e) { if( nodeInstanceContainer instanceof NodeInstance ) { throw new WorkflowRuntimeException((org.kie.api.runtime.process.NodeInstance) nodeInstanceContainer, processInstance, msg, e ); } else { throw new WorkflowRuntimeException(null, processInstance, msg, e ); } } }
@Override public ExecutionError filter(ExecutionErrorContext errorContext) { WorkflowRuntimeException exception = extract(errorContext.getCause(), WorkflowRuntimeException.class); String stacktrace = getStackTrace(errorContext.getCause()); return ExecutionError.builder() .type(TYPE) .initActivityId(getInitActivityId(errorContext)) .deploymentId(exception.getDeploymentId()) .processInstanceId(exception.getProcessInstanceId()) .processId(exception.getProcessId()) .activityId(exception.getNodeInstanceId()) .activityName(exception.getNodeName()) .message(exception.getMessage()) .error(stacktrace) .errorDate(new Date()) .build(); }
public static void runExample() { RuntimeManager manager = createManager(); KieSession ksession = manager.getRuntimeEngine(null).getKieSession(); Map<String, Object> params = new HashMap<String, Object>(); String varName = "var1"; params.put( varName , "valueOne" ); try { ksession.startProcess("ExceptionScriptTask", params); } catch( WorkflowRuntimeException wfre ) { String msg = "An exception happened in " + "process instance [" + wfre.getProcessInstanceId() + "] of process [" + wfre.getProcessId() + "] in node [id: " + wfre.getNodeId() + ", name: " + wfre.getNodeName() + "] and variable " + varName + " had the value [" + wfre.getVariables().get(varName) + "]"; System.out.println(msg); } manager.close(); }
@Test public void testErrornousHandlerWithStrategyRethrow() throws Exception { KieBase kbase = createKnowledgeBaseWithoutDumper("handler/BPMN2-UserTaskWithBooleanOutput.bpmn2", "handler/BPMN2-ScriptTask.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); ErrornousWorkItemHandler workItemHandler = new ErrornousWorkItemHandler("ScriptTask", HandlingStrategy.RETHROW); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); try { Map<String, Object> params = new HashMap<>(); params.put("isChecked", false); ksession.startProcess("com.sample.boolean", params); fail("Should fail since strategy is rethrow"); } catch (WorkflowRuntimeException e) { assertEquals("On purpose", e.getCause().getMessage()); } }
@Test public void testErrornousHandlerWithStrategyRethrow() throws Exception { KieBase kbase = createKnowledgeBaseWithoutDumper("handler/BPMN2-UserTaskWithBooleanOutput.bpmn2", "handler/BPMN2-ScriptTask.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); ErrornousWorkItemHandler workItemHandler = new ErrornousWorkItemHandler("ScriptTask", HandlingStrategy.RETHROW); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); try { Map<String, Object> params = new HashMap<>(); params.put("isChecked", false); ksession.startProcess("com.sample.boolean", params); fail("Should fail since strategy is rethrow"); } catch (WorkflowRuntimeException e) { assertEquals("On purpose", e.getCause().getMessage()); } }
@Override public String getMessage() { return MessageFormat.format("[{0}:{4} - {1}:{2}] -- {3}", getProcessId(), (getNodeName() == null ? "?" : getNodeName()), (getNodeId() == 0 ? "?" : getNodeId()), (getCause() == null ? getMessage() : getCause().getMessage()), getProcessInstanceId()); }
@Override public ExecutionError filter(ExecutionErrorContext errorContext) { WorkflowRuntimeException exception = extract(errorContext.getCause(), WorkflowRuntimeException.class); String stacktrace = getStackTrace(errorContext.getCause()); return ExecutionError.builder() .type(TYPE) .initActivityId(getInitActivityId(errorContext)) .deploymentId(exception.getDeploymentId()) .processInstanceId(exception.getProcessInstanceId()) .processId(exception.getProcessId()) .activityId(exception.getNodeInstanceId()) .activityName(exception.getNodeName()) .message(exception.getMessage()) .error(stacktrace) .errorDate(new Date()) .build(); }
public void internalTrigger(final NodeInstance from, String type) { if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) { throw new IllegalArgumentException( "A Split only accepts default incoming connections!"); } final Split split = getSplit(); try { executeStrategy(split, type); } catch(WorkflowRuntimeException wre) { throw wre; } catch(Exception e) { throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Split: " + e.getMessage(), e); } }
private void handleException(Throwable e) { ExceptionScopeInstance exceptionScopeInstance = getExceptionScopeInstance(e); if(exceptionScopeInstance != null) { exceptionScopeInstance.handleException(e.getClass().getName(), e); return; } else { Throwable rootCause = ExceptionUtils.getRootCause(e); if(rootCause != null) { exceptionScopeInstance = getExceptionScopeInstance(rootCause); if(exceptionScopeInstance != null) { exceptionScopeInstance.handleException(rootCause.getClass().getName(), rootCause); return; } } throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e); } }
/** * This method is used in both instances of the {@link ExtendedNodeInstanceImpl} * and {@link ActionNodeInstance} instances in order to handle * exceptions thrown when executing actions. * * @param action An {@link Action} instance. */ protected void executeAction(Action action) { ProcessContext context = new ProcessContext(getProcessInstance().getKnowledgeRuntime()); context.setNodeInstance(this); try { action.execute(context); } catch (Exception e) { String exceptionName = e.getClass().getName(); ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName); if (exceptionScopeInstance == null) { throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e); } exceptionScopeInstance.handleException(exceptionName, e); cancel(); } }
public void internalTrigger(final NodeInstance from, String type) { if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) { throw new IllegalArgumentException( "An ActionNode only accepts default incoming connections!"); } Action action = (Action) getActionNode().getAction().getMetaData("Action"); try { ProcessContext context = new ProcessContext(getProcessInstance().getKnowledgeRuntime()); context.setNodeInstance(this); executeAction(action); } catch( WorkflowRuntimeException wre) { throw wre; } catch (Exception e) { // for the case that one of the following throws an exception // - the ProcessContext() constructor // - or context.setNodeInstance(this) throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e); } triggerCompleted(); }
throw new WorkflowRuntimeException(null, getProcessInstance(), "Compensation can only be triggered with String events, not an event of type " + activityRefStr == null ? "null" : activityRefStr.getClass().getSimpleName());
throw new WorkflowRuntimeException(this, getProcessInstance(), e);
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName); if (exceptionScopeInstance == null) { throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute work item " + handlerException.getMessage(), handlerException.getCause());
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName); if (exceptionScopeInstance == null) { throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e);
private void throwWorkflowRuntimeException(NodeInstanceContainer nodeInstanceContainer, ProcessInstance processInstance, String msg, Exception e) { if( nodeInstanceContainer instanceof NodeInstance ) { throw new WorkflowRuntimeException((org.kie.api.runtime.process.NodeInstance) nodeInstanceContainer, processInstance, msg, e ); } else { throw new WorkflowRuntimeException(null, processInstance, msg, e ); } } }
public void internalTrigger(final NodeInstance from, String type) { if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) { throw new IllegalArgumentException( "A Split only accepts default incoming connections!"); } final Split split = getSplit(); try { executeStrategy(split, type); } catch(WorkflowRuntimeException wre) { throw wre; } catch(Exception e) { throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Split: " + e.getMessage(), e); } }
private void handleException(Throwable e) { ExceptionScopeInstance exceptionScopeInstance = getExceptionScopeInstance(e); if(exceptionScopeInstance != null) { exceptionScopeInstance.handleException(e.getClass().getName(), e); return; } else { Throwable rootCause = ExceptionUtils.getRootCause(e); if(rootCause != null) { exceptionScopeInstance = getExceptionScopeInstance(rootCause); if(exceptionScopeInstance != null) { exceptionScopeInstance.handleException(rootCause.getClass().getName(), rootCause); return; } } throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e); } }
/** * This method is used in both instances of the {@link ExtendedNodeInstanceImpl} * and {@link ActionNodeInstance} instances in order to handle * exceptions thrown when executing actions. * * @param action An {@link Action} instance. */ protected void executeAction(Action action) { ProcessContext context = new ProcessContext(getProcessInstance().getKnowledgeRuntime()); context.setNodeInstance(this); try { action.execute(context); } catch (Exception e) { String exceptionName = e.getClass().getName(); ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName); if (exceptionScopeInstance == null) { throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute Action: " + e.getMessage(), e); } exceptionScopeInstance.handleException(exceptionName, e); cancel(); } }