use of org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException in project jbpm by kiegroup.
the class JaxWSServiceTaskTest method testServiceInvocationWithErrorHandled.
@Test
public void testServiceInvocationWithErrorHandled() throws Exception {
KieBase kbase = readKnowledgeBase();
KieSession ksession = createSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler(ksession));
Map<String, Object> params = new HashMap<String, Object>();
params.put("s", "john");
params.put("mode", "sync");
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("WebServiceTaskError", params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
Object error = processInstance.getVariable("exception");
assertNotNull(error);
assertTrue(error instanceof WorkItemHandlerRuntimeException);
}
use of org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException in project jbpm by kiegroup.
the class AbstractLogOrThrowWorkItemHandler method handleException.
protected void handleException(Throwable cause, Map<String, Object> handlerInfoMap) {
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.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException in project jbpm by kiegroup.
the class BasicAuthRestWorkItemHandlerTest method testHandleErrorOnNotSuccessfulResponse.
@Test
public void testHandleErrorOnNotSuccessfulResponse() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, PASSWORD);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL + "/notexisting");
workItem.setParameter("Method", "GET");
workItem.setParameter("HandleResponseErrors", "true");
WorkItemManager manager = new TestWorkItemManager(workItem);
try {
handler.executeWorkItem(workItem, manager);
fail("Should throw exception as it was instructed to do so");
} catch (WorkItemHandlerRuntimeException ex) {
RESTServiceException e = (RESTServiceException) ex.getCause().getCause();
assertEquals(405, e.getStatus());
assertEquals(SERVER_URL + "/notexisting", e.getEndoint());
assertEquals("", e.getResponse());
}
}
use of org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException in project jbpm by kiegroup.
the class BasicAuthRestWorkItemHandlerTest method testHandleErrorOnNotSuccessfulResponseWrongCredentials.
@Test
public void testHandleErrorOnNotSuccessfulResponseWrongCredentials() {
RESTWorkItemHandler handler = new RESTWorkItemHandler(USERNAME, "wrongpassword");
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("Url", SERVER_URL);
workItem.setParameter("Method", "GET");
workItem.setParameter("HandleResponseErrors", "true");
WorkItemManager manager = new TestWorkItemManager(workItem);
try {
handler.executeWorkItem(workItem, manager);
fail("Should throw exception as it was instructed to do so");
} catch (WorkItemHandlerRuntimeException ex) {
RESTServiceException e = (RESTServiceException) ex.getCause().getCause();
assertEquals(401, e.getStatus());
assertEquals(SERVER_URL, e.getEndoint());
assertEquals("", e.getResponse());
}
}
use of org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException in project jbpm by kiegroup.
the class RestWorkItemHandlerTest method testHandleErrorOnNotSuccessfulResponse.
@Test
public void testHandleErrorOnNotSuccessfulResponse() {
RESTWorkItemHandler handler = new RESTWorkItemHandler();
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 (WorkItemHandlerRuntimeException ex) {
RESTServiceException e = (RESTServiceException) ex.getCause().getCause();
assertEquals(405, e.getStatus());
assertEquals(serverURL + "/notexisting", e.getEndoint());
assertEquals("", e.getResponse());
}
}
Aggregations