如何将附加数据添加到mule负载?

问题描述:

我正在尝试将一些额外的静态数据添加到入站http消息(作为URL参数接收)有效负载,然后再将其提交到基于出站http表单的端点。我的mule配置如下:

I'm trying to add some additional static data to an inbound http message (received as URL parameters) payload before submitting it to an outbound http form based endpoint. My mule config is as follows :

<flow name="login" doc:name="login">
    <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:8081/login" doc:name="Login"/>

    <http:body-to-parameter-map-transformer doc:name="Body to Parameter Map"/>  

    <http:outbound-endpoint address="http://localhost:8090/mayapp/Main/login.do"
            method="POST" contentType="application/x-www-form-urlencoded" exchange-pattern="request-response">
    </http:outbound-endpoint>
</flow>

上面将URL参数转换为http表单POST(名称/值对)非常好。我现在需要的是能够为POST(ed)数据添加新的名称 - 值对吗?我发布的表单需要一些静态数据(作为隐藏的HTML字段发布),我想在转换过程中处理这些数据。

The above transforms the URL parameters to a http form POST (name/values pairs) very nicely. What I need now is the ability to add new name-value pairs to the POST(ed) data ? The form I'm posting to expects some static data (posted as hidden HTML fields) that I would like to handle as part of the transformation process.

我管理过使用自定义组件完成此任务。我想知道是否有更简单的方法来处理这个使用Mule的本地变换器/消息处理器!

I've managed to accomplish this using a custom component. I'm wondering if there's an easier way to handle this using Mule's native transformers / message processors !

首先我会使用一个变压器,而不是一个组件,因为它实际上是你在有效载荷数据上做的转换。

First I would use a transformer and not a component for this, as it is really a transformation you're doing on the payload data.

第二我想不到另一个变压器而不是Groovy一个修改由body-to-parameter-map-transformer创建的Map有效负载。类似于:

Second I can't think of another transformer than the Groovy one to modify the Map payload created by the body-to-parameter-map-transformer. Something like:

<script:transformer>
    <script:script engine="groovy">
        <script:text>
            payload['newKey'] = 'newValue'
        </script:text>
    </script:script>
</script:transformer>