Passing a map to a Java delegate in CMMN

Hi!

I’m currently trying to construct a CMMN model where a BPMN service task is invoked. This service task is responsible for constructing and sending an HTTP request. I’ve written a Java Delegate that is used to do this, but I’m having problems passing the data I need to it.

Part of the Java delegate’s job is to create the payload for the HTTP request. This payload is based on a template, which is then resolved against a map of context data to create the final request. I’ve tried to parameterise the service task as follows:

<cmmn:processTask id="ProcessTask_0hrgff5" name="Set Content Status" processRef="Send_Http_Request">
   <cmmn:extensionElements>
       <camunda:in sourceExpression="setContentStatusUrl" target="url"/>
       <camunda:in sourceExpression="${'POST'}" target="method"/>
       <camunda:in source="payload" target="payload"/>
       <camunda:in sourceExpression="${'DRAFT'}" target="contextMap['status']"/>
       <camunda:in sourceExpression="${15}" target="contextMap['contentId']"/>
   </cmmn:extensionElements>

</cmmn:processTask>

Note the references to “contextMap”. I want to be able to create a map like this and then refer to it in my Java delegate as a HashMap.

Has anyone tried something similar?

Hi @scottmackie,

The attribute target inside the camunda:in element is used as the name of the variable inside the sub instance (see 1). So that, the value of the source (or sourceExpression) can fetched by using the target variable name inside the sub instance. As a consequence, contextMap[...] will not work.

This

could be changed into something like this

<camunda:in sourceExpression="${'DRAFT'}" target="status"/>
<camunda:in sourceExpression="${15}" target="contentId"/>

Inside your JavaDelegate you could then add this values into a map, if this is still necessary.

Does it help you?

Cheers,
Roman

Hi @roman.smirnov, thanks for the reply.

It’s good to know that the approach I was following will not work. The issue with your suggested workaround is that the list of values to be resolved against the template needs to be dynamic. The values are used as a set of name value pairs that the delegate will use for String template placeholder expansion.

To do this the delegate has to be able to group the values to be placed in that map. Currently, I’m using a prefix to do this, so the delegate knows that any variables starting with the prefix are to be used in the placeholder expansion.

<camunda:in sourceExpression="${'DRAFT'}" target="contextMap_status"/>
<camunda:in sourceExpression="${15}" target="contextMap_contentId"/>

It’s not very nice though, and it would be nice to have access to a data structure that can be populated and passed to the delegate.

Does anyone have any suggestions for how able to inject values into a map for use inside a delegate class?

Hi @scottmackie,

This is not possible with camunda:in and camunda:out elements.

Cheers,
Roman

Ok, thanks @roman.smirnov. I’ll work around this.