I am trying to make use of field injection, with a class delegate, but my field values do not seem to be set by the process engine.
When using the below BPMN and JavaDelegate, the field values are always null, when the process instance executes the delegate code.
I created the below BPMN using the latest version of the Camunda modeller. Am I missing something or is this a genuine bug?
<bpmn2:intermediateThrowEvent id="IntermediateThrowEvent_1">
<bpmn2:extensionElements>
<camunda:field name="messageName">
<camunda:string>triggerMessage</camunda:string>
</camunda:field>
</bpmn2:extensionElements>
<bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_2</bpmn2:outgoing>
<bpmn2:messageEventDefinition id="_MessageEventDefinition_6" camunda:class="com.telrock.platform.themis.testpa.delegate.SendMessageDelegate"/>
</bpmn2:intermediateThrowEvent>
package com.telrock.platform.themis.testpa.delegate;
import java.util.HashMap;
public class SendMessageDelegate implements JavaDelegate
{
private Expression messageName;
private Expression variables;
@Override
@SuppressWarnings("unchecked")
public void execute(DelegateExecution execution) throws Exception
{
if (messageName == null)
{
throw new BpmnError(BpmnUtils.ERROR_MISSING_FIELD, "messageName cannot be null");
}
String message = messageName.getValue(execution).toString();
Map<String, Object> variableMap = null;
try
{
variableMap = variables != null ? (Map<String, Object>) variables.getValue(execution)
: new HashMap<String, Object>();
}
catch (ClassCastException e)
{
throw new BpmnError(BpmnUtils.ERROR_INCORRECT_FIELD_TYPE, "variables must resolve to a map<String,Object>");
}
String businessKey = execution.getProcessBusinessKey();
if (StringUtils.isBlank(businessKey))
{
execution.getProcessEngineServices().getRuntimeService().correlateMessage(message, variableMap);
}
else
{
execution.getProcessEngineServices().getRuntimeService().correlateMessage(message, businessKey, variableMap);
}
}
public Expression getMessageName()
{
return messageName;
}
public void setMessageName(Expression messageName)
{
this.messageName = messageName;
}
public Expression getVariables()
{
return variables;
}
public void setVariables(Expression variables)
{
this.variables = variables;
}
}
Cheers,
-MattD
<bpmn2:serviceTask id="ServiceTask_3" camunda:class="com.telrock.platform.themis.testpa.delegate.SendMessageDelegate" name="Trigger Process 2">
<bpmn2:extensionElements>
<camunda:field name="messageName">
<camunda:string>triggerMessage</camunda:string>
</camunda:field>
</bpmn2:extensionElements>
<bpmn2:incoming>SequenceFlow_7</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_8</bpmn2:outgoing>
</bpmn2:serviceTask>
The above snippet sets the JavaDelegate fields correctly. I can only assume this is a bug in the Intermediate Throwing Message Event, as the docs say that this should be handled the same as the Service Task: http://docs.camunda.org/latest/api-references/bpmn20/#events-message-events-message-intermediate-throwing-event
<bpmn2:intermediateThrowEvent id="IntermediateThrowEvent_1">
<bpmn2:incoming>SequenceFlow_1</bpmn2:incoming>
<bpmn2:outgoing>SequenceFlow_2</bpmn2:outgoing>
<bpmn2:messageEventDefinition id="_MessageEventDefinition_6" camunda:class="com.telrock.platform.themis.testpa.delegate.SendMessageDelegate">
<bpmn2:extensionElements>
<camunda:field name="messageName">
<camunda:string>triggerMessage</camunda:string>
</camunda:field>
</bpmn2:extensionElements>
</bpmn2:messageEventDefinition>
</bpmn2:intermediateThrowEvent>