AnsweredAssumed Answered

Activiti Mule Integration - payloadExpression parsing

Question asked by sathyasankar on Jun 22, 2012
This may be more of a question for mule since it is about activiti-mule connector but since I saw a few posts on the topic here and it got some coverage in the Activiti in Action book, I figured I'll start here.

I have a mule flow which creates an Activiti process and as part of its processing, the process sends a message back to a VM endpoint in Mule. The payload that needs to be passed back to Mule is a non-String object (say, PaymentRequestDTO) which is available as a process variable ("paymentRequest"). When I add a sendTask similar to below in my process,

    <sendTask id="muleTask" name="Service Task" activiti:type="mule">
      <extensionElements>
            <activiti:field name="endpointUrl">
               <activiti:string>payment.endpoint.vmInbound</activiti:string>
            </activiti:field>
            <activiti:field name="language">
               <activiti:string>juel</activiti:string>
            </activiti:field>
            <activiti:field name="payloadExpression">
               <activiti:expression>${paymentRequest}</activiti:expression>
            </activiti:field>
            <activiti:field name="resultVariable" >
               <activiti:expression>muleResponse</activiti:expression>
            </activiti:field>     
      </extensionElements>
    </sendTask>

What I see getting passed as payload to that VM endpoint is the String "com.abc.PaymentRequestDTO@…" instead of the PaymentRequestDTO object. I've debugged and made sure the process variable "paymentRequest" is present in the "execution" passed into "MuleSendActivitiBehavior".

From what I can tell, the line

    String payloadExpressionValue = this.getStringFromField(this.payloadExpression, execution);

in "MuleSendActivitiBehavior", converts the ${paymentRequest} expression to "com.abc.PaymentRequestDTO@…" and when it reaches the line

    Object payload = scriptingEngines.evaluate(payloadExpressionValue, languageValue, execution);

the payloadExpressionValue (which now contains "com.abc.PaymentRequestDTO@…") is echoed back and makes it into the VM endpoint as the payload.

As a work around, I ended up creating another process variable called "muleRequest" which contains the String value "${paymentRequest}" and added that to the "sendTask" like below:

    <sendTask id="muleTask" name="Service Task" activiti:type="mule">
      <extensionElements>
            <activiti:field name="endpointUrl">
               <activiti:string>payment.endpoint.vmInbound</activiti:string>
            </activiti:field>
            <activiti:field name="language">
               <activiti:string>juel</activiti:string>
            </activiti:field>
            <activiti:field name="payloadExpression">
               <activiti:expression>${muleRequest}</activiti:expression>
            </activiti:field>
            <activiti:field name="resultVariable" >
               <activiti:expression>muleResponse</activiti:expression>
            </activiti:field>     
      </extensionElements>
    </sendTask>

This fixes the issue and I can see the PaymentRequestDTO object making it into the VM endpoint. I would have thought I should just have to specify the process variable name and that would make it to Mule as the payload. The examples I find in the book (Activiti in Action) and the various blogs seem to imply that.

This obviously won't be an issue for any "String" variables, which are mostly what I see in the blogs and documentation. Is this a known issue or a bug or am I just missing something here?

Any suggestions will be appreciated… Thanks

Outcomes