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;
}
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();
}
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());
}
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.");
}
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
}
Aggregations