Setting Map as payload in Mule Flow using MEL

别等时光非礼了梦想. 提交于 2021-01-27 12:56:57

问题


I am trying to generate and set a map (with 2 key value pairs) on the fly as the payload for the following HTTP call. However, the MEL expression for creating the Map is not working.

<sub-flow name="call-myservice" doc:name="call-myservice">
    <set-payload value="#[username :${my.username}, password : ${my.password}]" doc:name="Set Payload"/>
    <https:outbound-endpoint exchange-pattern="request-response" host="${myservice.Host}"  method="POST" mimeType="application/json" doc:name="My Service call" path="mypath" port="443"/>
</sub-flow>

I followed the instructions at http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+MEL

which suggests --

MEL provides a streamlined way to access map data. 

Rather than constructing a map with a new statement, and then using its put method to populate it, you can simply write the following:

[key1 : value1, key2 : value2, . . .]

However, it is giving me the following exception --

ERROR 2014-02-28 15:27:51,424 [[services-proxy].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Execution of the expression "username :abc, password : pwd" failed.         (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. [Error: unresolvable property or identifier: username]
[Near : {... username :abc, pa ....}]
         ^
[Line: 1, Column: 1] (org.mvel2.PropertyAccessException)
  org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer:687 (null)

回答1:


You are missing square brackets to delimit the map (the only ones you have delimit the Mule expression). Change it to:

<set-payload value="#[['username' :${my.username}, 'password' : ${my.password}]]" doc:name="Set Payload"/>


来源:https://stackoverflow.com/questions/22106335/setting-map-as-payload-in-mule-flow-using-mel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!