use of org.kie.api.runtime.process.ProcessWorkItemHandlerException in project jbpm by kiegroup.
the class AbstractLogOrThrowWorkItemHandler method handleException.
protected void handleException(Throwable cause, Map<String, Object> handlerInfoMap) {
// we check first if the exception should be handle or not.
if (canExceptionTriggerSubprocess(cause) && handlingProcessId != null && handlingStrategy != null) {
throw new ProcessWorkItemHandlerException(handlingProcessId, handlingStrategy, cause, retries);
}
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;
}
}
use of org.kie.api.runtime.process.ProcessWorkItemHandlerException in project jbpm by kiegroup.
the class WebServiceWorkItemHandlerTest method testExecuteSyncOperationHandlingException.
@Test
public void testExecuteSyncOperationHandlingException() throws Exception {
when(clients.computeIfAbsent(any(), any())).thenReturn(null);
TestWorkItemManager manager = new TestWorkItemManager();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Interface", "someInterface");
workItem.setParameter("Operation", "someOperation");
workItem.setParameter("Parameter", "myParam");
workItem.setParameter("Mode", "SYNC");
WebServiceWorkItemHandler handler = new WebServiceWorkItemHandler("test", "COMPLETE", kieSession);
handler.setClients(clients);
try {
handler.executeWorkItem(workItem, manager);
fail("Should throw exception as it was instructed to do so");
} 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());
}
}
use of org.kie.api.runtime.process.ProcessWorkItemHandlerException in project businessautomation-cop by redhat-cop.
the class Script method handleStrategy.
public static void handleStrategy(ProcessContext kcontext) {
String strategy = (String) kcontext.getVariable("strategy");
ProcessWorkItemHandlerException pwihe = (ProcessWorkItemHandlerException) kcontext.getVariable("Error");
pwihe = new ProcessWorkItemHandlerException(pwihe.getProcessId(), ProcessWorkItemHandlerException.HandlingStrategy.valueOf(strategy), pwihe.getCause());
kcontext.setVariable("Error", pwihe);
}
use of org.kie.api.runtime.process.ProcessWorkItemHandlerException in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testHandleErrorOnNotSuccessfulResponseHandlingException.
@Test
public void testHandleErrorOnNotSuccessfulResponseHandlingException() {
RESTWorkItemHandler handler = new RESTWorkItemHandler("test", "COMPLETE", "user", "password");
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", serverURL + "/notexisting");
workItem.setParameter("Method", "GET");
workItem.setParameter("HandleResponseErrors", "true");
WorkItemManager manager = new TestWorkItemManager();
try {
handler.executeWorkItem(workItem, manager);
fail("Should throw exception as it was instructed to do so");
} catch (ProcessWorkItemHandlerException ex) {
RESTServiceException e = (RESTServiceException) ex.getCause().getCause();
assertEquals(405, e.getStatus());
assertEquals(serverURL + "/notexisting", e.getEndoint());
assertEquals("", e.getResponse());
assertEquals("test", ex.getProcessId());
assertEquals("COMPLETE", ex.getStrategy().name());
}
}
use of org.kie.api.runtime.process.ProcessWorkItemHandlerException in project jbpm by kiegroup.
the class EmailWorkItemHandlerTest method testSingleToHandleException.
@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());
}
}
Aggregations