Search in sources :

Example 1 with SignallingTaskHandlerDecorator

use of org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator in project jbpm by kiegroup.

the class ExceptionHandlingErrorExample method runExample.

public static ProcessInstance runExample() {
    // load up the knowledge base
    RuntimeManager manager = createManager();
    KieSession ksession = manager.getRuntimeEngine(null).getKieSession();
    String eventType = "Error-code";
    SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType);
    signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("serviceInputItem", "Input to Original Service");
    ProcessInstance processInstance = ksession.startProcess("ProcessWithExceptionHandlingError", params);
    manager.close();
    return processInstance;
}
Also used : HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance)

Example 2 with SignallingTaskHandlerDecorator

use of org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator in project jbpm by kiegroup.

the class ExceptionHandlingSignalExample method runExample.

public static void runExample() {
    // load up the knowledge base
    RuntimeManager manager = createManager();
    KieSession ksession = manager.getRuntimeEngine(null).getKieSession();
    String eventType = "exception-signal";
    SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType);
    signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("serviceInputItem", "Input to Original Service");
    ksession.startProcess("ProcessWithExceptionHandlingSignal", params);
    manager.close();
}
Also used : HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) KieSession(org.kie.api.runtime.KieSession)

Example 3 with SignallingTaskHandlerDecorator

use of org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator in project jbpm by kiegroup.

the class ErrorEventTest method testEventSubProcessErrorWithScript.

@Test
public void testEventSubProcessErrorWithScript() throws Exception {
    KieBase kbase = createKnowledgeBase("BPMN2-EventSubProcessErrorWithScript.bpmn2");
    ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Request Handler", new SignallingTaskHandlerDecorator(ExceptionOnPurposeHandler.class, "Error-90277"));
    ksession.getWorkItemManager().registerWorkItemHandler("Error Handler", new SystemOutWorkItemHandler());
    ProcessInstance processInstance = ksession.startProcess("com.sample.process");
    assertProcessInstanceAborted(processInstance);
    assertEquals("90277", ((WorkflowProcessInstance) processInstance).getOutcome());
}
Also used : ExceptionOnPurposeHandler(org.jbpm.bpmn2.objects.ExceptionOnPurposeHandler) KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 4 with SignallingTaskHandlerDecorator

use of org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator in project jbpm by kiegroup.

the class StandaloneBPMNProcessTest method runTestErrorSignallingExceptionServiceTask.

public static void runTestErrorSignallingExceptionServiceTask(KieSession ksession) throws Exception {
    // Setup
    String eventType = "Error-code";
    SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType);
    signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper);
    Object[] caughtEventObjectHolder = new Object[1];
    caughtEventObjectHolder[0] = null;
    ExceptionService.setCaughtEventObjectHolder(caughtEventObjectHolder);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
    // Start process
    Map<String, Object> params = new HashMap<String, Object>();
    String input = "this is my service input";
    params.put("serviceInputItem", input);
    ProcessInstance processInstance = ksession.startProcess("ServiceProcess", params);
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    WorkItem workItem = workItemHandler.getWorkItem();
    assertThat(workItem).isNotNull();
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    // Check that event was passed to Event SubProcess (and grabbed by WorkItemHandler);
    assertThat(caughtEventObjectHolder[0] != null && caughtEventObjectHolder[0] instanceof WorkItem).isTrue().withFailMessage("Event was not passed to Event Subprocess.");
    workItem = (WorkItem) caughtEventObjectHolder[0];
    Object throwObj = workItem.getParameter(ExceptionService.exceptionParameterName);
    assertThat(throwObj instanceof Throwable).isTrue().withFailMessage("WorkItem doesn't contain Throwable.");
    assertThat(((Throwable) throwObj).getMessage().endsWith(input)).isTrue().withFailMessage("Exception message does not match service input.");
    // Complete process
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertThat(processInstance == null || processInstance.getState() == ProcessInstance.STATE_ABORTED).isTrue().withFailMessage("Process instance has not been aborted.");
}
Also used : TestWorkItemHandler(org.jbpm.bpmn2.objects.TestWorkItemHandler) HashMap(java.util.HashMap) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem)

Example 5 with SignallingTaskHandlerDecorator

use of org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator in project jbpm by kiegroup.

the class StandaloneBPMNProcessTest method runTestSignallingExceptionServiceTask.

public static void runTestSignallingExceptionServiceTask(KieSession ksession) throws Exception {
    // Setup
    String eventType = "exception-signal";
    SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType);
    signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName);
    ksession.getWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper);
    Object[] caughtEventObjectHolder = new Object[1];
    caughtEventObjectHolder[0] = null;
    ExceptionService.setCaughtEventObjectHolder(caughtEventObjectHolder);
    // Start process
    Map<String, Object> params = new HashMap<String, Object>();
    String input = "this is my service input";
    params.put("serviceInputItem", input);
    ProcessInstance processInstance = ksession.startProcess("ServiceProcess", params);
    // Check that event was passed to Event SubProcess (and grabbed by WorkItemHandler);
    assertThat(caughtEventObjectHolder[0] != null && caughtEventObjectHolder[0] instanceof WorkItem).isTrue().withFailMessage("Event was not passed to Event Subprocess.");
    WorkItem workItem = (WorkItem) caughtEventObjectHolder[0];
    Object throwObj = workItem.getParameter(ExceptionService.exceptionParameterName);
    assertThat(throwObj instanceof Throwable).isTrue().withFailMessage("WorkItem doesn't contain Throwable.");
    assertThat(((Throwable) throwObj).getMessage().endsWith(input)).isTrue().withFailMessage("Exception message does not match service input.");
    // Complete process
    assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE).withFailMessage("Process instance is not active.");
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    processInstance = ksession.getProcessInstance(processInstance.getId());
    if (processInstance != null) {
        assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED).withFailMessage("Process instance is not completed.");
    }
// otherwise, persistence use => processInstance == null => process is completed
}
Also used : HashMap(java.util.HashMap) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) WorkItem(org.kie.api.runtime.process.WorkItem)

Aggregations

SignallingTaskHandlerDecorator (org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator)6 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)5 HashMap (java.util.HashMap)4 KieSession (org.kie.api.runtime.KieSession)3 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)2 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)2 Test (org.junit.Test)2 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)2 WorkItem (org.kie.api.runtime.process.WorkItem)2 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)2 ExceptionOnPurposeHandler (org.jbpm.bpmn2.objects.ExceptionOnPurposeHandler)1 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)1 WorkflowRuntimeException (org.jbpm.workflow.instance.WorkflowRuntimeException)1 KieBase (org.kie.api.KieBase)1 BZ (qa.tools.ikeeper.annotation.BZ)1