Search in sources :

Example 1 with ProcessWorkItemHandlerException

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;
    }
}
Also used : WorkItemHandlerRuntimeException(org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException) ProcessWorkItemHandlerException(org.kie.api.runtime.process.ProcessWorkItemHandlerException)

Example 2 with ProcessWorkItemHandlerException

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

Example 3 with ProcessWorkItemHandlerException

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);
}
Also used : ProcessWorkItemHandlerException(org.kie.api.runtime.process.ProcessWorkItemHandlerException)

Example 4 with ProcessWorkItemHandlerException

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

Example 5 with ProcessWorkItemHandlerException

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

Aggregations

ProcessWorkItemHandlerException (org.kie.api.runtime.process.ProcessWorkItemHandlerException)7 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)3 Test (org.junit.Test)3 TestWorkItemManager (org.jbpm.process.workitem.core.TestWorkItemManager)2 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)2 HashMap (java.util.HashMap)1 DefaultWorkItemManager (org.drools.core.process.instance.impl.DefaultWorkItemManager)1 WorkItemHandlerRuntimeException (org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException)1 KogitoProcessContextImpl (org.jbpm.process.instance.KogitoProcessContextImpl)1 ExceptionScopeInstance (org.jbpm.process.instance.context.exception.ExceptionScopeInstance)1 WorkflowRuntimeException (org.jbpm.workflow.instance.WorkflowRuntimeException)1 InternalKogitoWorkItemManager (org.kie.kogito.process.workitems.InternalKogitoWorkItemManager)1