如何将附加数据添加到mule负载? [英] How to add additional data to a mule payload?

查看:124
本文介绍了如何将附加数据添加到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>

这篇关于如何将附加数据添加到mule负载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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