use of org.jbpm.bpmn2.core.Message in project jbpm by kiegroup.
the class SendTaskHandler method handleNode.
@SuppressWarnings("unchecked")
protected void handleNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
super.handleNode(node, element, uri, localName, parser);
WorkItemNode workItemNode = (WorkItemNode) node;
String messageRef = element.getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new IllegalArgumentException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new IllegalArgumentException("Could not find message " + messageRef);
}
workItemNode.getWork().setParameter("MessageType", message.getType());
}
use of org.jbpm.bpmn2.core.Message 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.core.Message 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