0
votes

I'm using Jbpm 6.0.3 (targeting Jboss EAP 6.1). I'm trying to develop a business processs which receives a data structure in a start message, and returns the same structure at the end of the process. I'm trying to use a message end event to end the process, but it doesn't seem to be supported by JBPM.

As a test, I made this trivial process. It begins with a start message that receives a Date object, and returns the same object in an end message event.

Scratch business process

The actual process definition is as follows:

  <bpmn2:itemDefinition id="ItemDefinition_2" isCollection="false" structureRef="java.util.Date"/>
  <bpmn2:message id="date" itemRef="ItemDefinition_2" name="date"/>
  <bpmn2:process id="com.verizon.videa.publishwu.bpm.bp.Scratch" tns:packageName="com.verizon.videa.publishwu.bpm.bp" name="Scratch" isExecutable="true" processType="Private">
    <bpmn2:extensionElements>
      <tns:import name="java.util.Date"/>
    </bpmn2:extensionElements>
    <bpmn2:property id="dt" itemSubjectRef="ItemDefinition_2" name="dt"/>
    <bpmn2:startEvent id="StartEvent_1" name="StartProcess">
      <bpmn2:outgoing>SequenceFlow_1</bpmn2:outgoing>
      <bpmn2:dataOutput id="DataOutput_2" itemSubjectRef="ItemDefinition_2" name="event"/>
      <bpmn2:dataOutputAssociation id="DataOutputAssociation_1">
        <bpmn2:sourceRef>DataOutput_2</bpmn2:sourceRef>
        <bpmn2:targetRef>dt</bpmn2:targetRef>
      </bpmn2:dataOutputAssociation>
      <bpmn2:outputSet id="OutputSet_1" name="Output Set 1">
        <bpmn2:dataOutputRefs>DataOutput_2</bpmn2:dataOutputRefs>
      </bpmn2:outputSet>
      <bpmn2:messageEventDefinition id="MessageEventDefinition_1" messageRef="date"/>
    </bpmn2:startEvent>
    <bpmn2:endEvent id="EndEvent_1" name="End Event 1">
      <bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
      <bpmn2:dataInput id="DataInput_1" itemSubjectRef="ItemDefinition_2" name="Message_2_Input"/>
      <bpmn2:dataInputAssociation id="DataInputAssociation_1">
        <bpmn2:sourceRef>dt</bpmn2:sourceRef>
        <bpmn2:targetRef>DataInput_1</bpmn2:targetRef>
      </bpmn2:dataInputAssociation>
      <bpmn2:inputSet id="InputSet_1" name="Input Set 1">
        <bpmn2:dataInputRefs>DataInput_1</bpmn2:dataInputRefs>
      </bpmn2:inputSet>
      <bpmn2:messageEventDefinition id="MessageEventDefinition_2" messageRef="date"/>
    </bpmn2:endEvent>
    <bpmn2:sequenceFlow id="SequenceFlow_1" tns:priority="1" sourceRef="StartEvent_1" targetRef="EndEvent_1"/>
  </bpmn2:process>

I've run across two issues. First of all, Jbpm apparently implements message end events as a "Send Task" event. The process fails unless I register a work item handler for "Send Task". Second, The send task handler included with JBPM is a joke. Here's the meat of the handler:

public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
    String message = (String) workItem.getParameter("Message");
    logger.debug("Sending message: {}", message);
    manager.completeWorkItem(workItem.getId(), null);
}

It fails with a class cast exception unless the message payload is a string. And after logging that it's sending the message, then drops the message on the floor.

Is there a different send task handler that I should be using? Is there another way to return something more complex than a String from a process that's actually supported by JBPM?

1

1 Answers

1
votes

The send message event is defined in an abstract way, the BPMN2 specification doesn't define exactly what it means, for example sending an email, instant message, notification in a web application, etc. As a result, we provide a pluggable implementation where you can plug in your own implementation using a handler.

When you say 'return something', could you clarify what your use case is, what are you expecting it would do? Instead of using a message event, you could for example use a domain-specific task that models exactly what you want, for example send an email, tweet, etc.