Search in sources :

Example 1 with WorkItemHandlerRuntimeException

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);
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) WorkItemHandlerRuntimeException(org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test)

Example 2 with 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;
    }
}
Also used : WorkItemHandlerRuntimeException(org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException)

Example 3 with WorkItemHandlerRuntimeException

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());
    }
}
Also used : WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItemHandlerRuntimeException(org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 4 with WorkItemHandlerRuntimeException

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());
    }
}
Also used : WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItemHandlerRuntimeException(org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Test(org.junit.Test)

Example 5 with WorkItemHandlerRuntimeException

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());
    }
}
Also used : TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItemHandlerRuntimeException(org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) Test(org.junit.Test)

Aggregations

WorkItemHandlerRuntimeException (org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException)5 Test (org.junit.Test)4 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)3 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)3 HashMap (java.util.HashMap)1 TestWorkItemManager (org.jbpm.process.workitem.core.TestWorkItemManager)1 AbstractBaseTest (org.jbpm.test.AbstractBaseTest)1 KieBase (org.kie.api.KieBase)1 KieSession (org.kie.api.runtime.KieSession)1 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)1