Reputation: 95
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>
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.
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 !
Upvotes: 3
Views: 10450
Reputation: 3711
You can use an expression-component as well:
<expression-component doc:name="change_payload">
<![CDATA[#[ message.payload = 'foo';]]]>
</expression-component>
Upvotes: 0
Reputation: 33413
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.
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>
Upvotes: 5