Field Injection in Intermediate Throw event

531 views
Skip to first unread message

mattd...@gmail.com

unread,
Jun 12, 2014, 6:58:37 AM6/12/14
to camunda-...@googlegroups.com
Hi guys,

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

mattd...@gmail.com

unread,
Jun 12, 2014, 7:14:23 AM6/12/14
to camunda-...@googlegroups.com, mattd...@gmail.com
I have since tried the same thing with a Service Task and it works:

<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

Sebastian Menski

unread,
Jun 13, 2014, 8:18:21 AM6/13/14
to camunda-...@googlegroups.com, mattd...@gmail.com
Hi Matt,

the field injections have to be extension elements of the message event definition and not of the intermediate throw event.

So this should work for you:

<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>


Cheers,
Sebastian

mattd...@gmail.com

unread,
Jun 13, 2014, 9:55:19 AM6/13/14
to camunda-...@googlegroups.com, mattd...@gmail.com
Hi Sebastian,

Thanks for your response. That does make sense to me, unfortuenately the Modeller, and the xsd: <bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:camunda="http://activiti.org/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="_WsQkYPIMEeOco9VopC8wwg" exporter="camunda modeler" exporterVersion="2.5.0" targetNamespace="http://activiti.org/bpmn">, does not allow me to generate BPMN like that.

For now I'll have to stick to using the Send or Service Task I think.

Cheers,
-MattD

Sebastian Menski

unread,
Jun 16, 2014, 4:37:32 AM6/16/14
to camunda-...@googlegroups.com, mattd...@gmail.com
Hi Matt,

it is correct that there is no way to configure the field injection of a message event definition with the Design view of the modeler. But I was able
to add them in the Source view with the last modeler release (1.2.0). Is this no option for you? I'm not sure why you think the xsd does not allow you to do this?

Cheers,
Sebastian
Reply all
Reply to author
Forward
0 new messages