2014-02-28 32 views
2

我試圖生成並設置一個映射(帶有2個鍵值對),作爲以下HTTP調用的有效負載。但是,創建Map的MEL表達式不起作用。使用MEL將Mule流中的地圖設置爲有效載荷

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

我按照說明在http://www.mulesoft.org/documentation/display/current/Mule+Expression+Language+MEL

提示 -

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, . . .] 

但是,它給我下面的例外 -

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) 

回答

6

你缺少方用括號來分隔地圖(只有你劃定了Mule表達式)。將其更改爲:

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

我想你也需要,如果你使用屬性佔位符來引用值:<設置荷載值=「#[‘用戶名’:‘$ {} my.username’,「密碼':'$ {my.password}']]「doc:name =」Set Payload「/>。 –

+0

謝謝!安東你是對的,它只適用於我添加引號。 – user1493140

相關問題