switch (handlerException.getStrategy()) { case ABORT: ((WorkItemManager) ((ProcessInstance) getProcessInstance()) break; case RETHROW: String exceptionName = handlerException.getCause().getClass().getName(); 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.handleException(exceptionName, handlerException.getCause()); break; case RETRY:
parameters.put("WorkItemId", workItem.getId()); parameters.put("NodeInstanceId", this.getId()); parameters.put("ErrorMessage", handlerException.getMessage()); parameters.put("Error", handlerException); ProcessInstance processInstance = ( ProcessInstance ) kruntime.createProcessInstance(handlerException.getProcessId(), parameters);
protected void handleException(Throwable cause, Map<String, Object> handlerInfoMap) { if (handlingProcessId != null && handlingStrategy != null) { throw new ProcessWorkItemHandlerException(handlingProcessId, handlingStrategy, cause); } String service = (String) handlerInfoMap.get("Interface"); String operation = (String) handlerInfoMap.get("Operation"); if (this.logThrownException) { String message; if (service != null) { message = this.getClass().getSimpleName() + " failed when calling " + service + "." + operation; } else { message = this.getClass().getSimpleName() + " failed while trying to complete the task."; } logger.error(message, cause); } else { WorkItemHandlerRuntimeException wihRe = new WorkItemHandlerRuntimeException(cause); for (String key : handlerInfoMap.keySet()) { wihRe.setInformation(key, handlerInfoMap.get(key)); } wihRe.setInformation(WorkItemHandlerRuntimeException.WORKITEMHANDLERTYPE, this.getClass().getSimpleName()); throw wihRe; } }
} catch (ProcessWorkItemHandlerException ex) { assertEquals("Unable to create client for web service someInterface - someOperation", ex.getCause().getMessage()); assertEquals("test", ex.getProcessId()); assertEquals("COMPLETE", ex.getStrategy().name());
@Test public void testSingleToHandleException() throws Exception { EmailWorkItemHandler handler = new EmailWorkItemHandler("test", "COMPLETE"); handler.setConnection( null, null, null, null ); WorkItemImpl workItem = new WorkItemImpl(); workItem.setParameter( "To", "person1@domain.com" ); workItem.setParameter( "From", "person2@domain.com" ); workItem.setParameter( "Reply-To", "person3@domain.com" ); workItem.setParameter( "Subject", "Subject 1" ); workItem.setParameter( "Body", "Body 1" ); WorkItemManager manager = new DefaultWorkItemManager(null); try { handler.executeWorkItem( workItem, manager ); fail("Should throw exception as it was instructed to do so"); } catch (ProcessWorkItemHandlerException ex) { assertTrue(ex.getCause() instanceof NullPointerException); assertEquals(null, ex.getCause().getMessage()); assertEquals("test", ex.getProcessId()); assertEquals("COMPLETE", ex.getStrategy().name()); } } }
switch (handlerException.getStrategy()) { case ABORT: ((WorkItemManager) ((ProcessInstance) getProcessInstance()) break; case RETHROW: String exceptionName = handlerException.getCause().getClass().getName(); 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.handleException(exceptionName, handlerException.getCause()); break; case RETRY:
parameters.put("WorkItemId", workItem.getId()); parameters.put("NodeInstanceId", this.getId()); parameters.put("ErrorMessage", handlerException.getMessage()); parameters.put("Error", handlerException); ProcessInstance processInstance = ( ProcessInstance ) kruntime.createProcessInstance(handlerException.getProcessId(), parameters);
@Override public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { this.workItem = workItem; if (processId != null && strategy != null) { if (workItem.getParameter("isCheckedCheckbox") != null) { manager.completeWorkItem(workItem.getId(), workItem.getParameters()); } else { throw new ProcessWorkItemHandlerException(processId, strategy, new RuntimeException("On purpose")); } } manager.completeWorkItem(workItem.getId(), null); }
protected void handleException(Throwable cause, Map<String, Object> handlerInfoMap) { if (handlingProcessId != null && handlingStrategy != null) { throw new ProcessWorkItemHandlerException(handlingProcessId, handlingStrategy, cause); } String service = (String) handlerInfoMap.get("Interface"); String operation = (String) handlerInfoMap.get("Operation"); if (this.logThrownException) { String message; if (service != null) { message = this.getClass().getSimpleName() + " failed when calling " + service + "." + operation; } else { message = this.getClass().getSimpleName() + " failed while trying to complete the task."; } logger.error(message, cause); } else { WorkItemHandlerRuntimeException wihRe = new WorkItemHandlerRuntimeException(cause); for (String key : handlerInfoMap.keySet()) { wihRe.setInformation(key, handlerInfoMap.get(key)); } wihRe.setInformation(WorkItemHandlerRuntimeException.WORKITEMHANDLERTYPE, this.getClass().getSimpleName()); throw wihRe; } }
@Override public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { this.workItem = workItem; if (processId != null && strategy != null) { if (workItem.getParameter("isCheckedCheckbox") != null) { manager.completeWorkItem(workItem.getId(), workItem.getParameters()); } else { throw new ProcessWorkItemHandlerException(processId, strategy, new RuntimeException("On purpose")); } } manager.completeWorkItem(workItem.getId(), null); }