使用 MEL 在 Mule Flow 中将 Map 设置为有效载荷 [英] Setting Map as payload in Mule Flow using MEL

查看:74
本文介绍了使用 MEL 在 Mule Flow 中将 Map 设置为有效载荷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试动态生成和设置地图(带有 2 个键值对)作为以下 HTTP 调用的有效负载.但是,用于创建地图的 MEL 表达式不起作用.

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>

我按照 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, . . .]

但是,它给了我以下异常-

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)

推荐答案

您缺少用于分隔地图的方括号(您唯一可以分隔 Mule 表达式的方括号).改为:

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

这篇关于使用 MEL 在 Mule Flow 中将 Map 设置为有效载荷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆