Skip to content

Instantly share code, notes, and snippets.

@jdeoliveira
Created July 11, 2012 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdeoliveira/3093611 to your computer and use it in GitHub Desktop.
Save jdeoliveira/3093611 to your computer and use it in GitHub Desktop.
Mule flow to PUT form encoded data through HTTP
<flow name="httpputFlow" doc:name="httpputFlow">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8086" doc:name="HTTP"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text>
<![CDATA[
HashMap map = new HashMap();
map.put("param1", "value1");
map.put("param2", "value2");
map.put("param3", "value3");
return map;
]]>
</scripting:text>
</scripting:script>
</scripting:component>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text>
<![CDATA[
message.payload = payload.collect { k,v -> "$k=$v"}.join('&');
]]>
</scripting:text>
</scripting:script>
</scripting:component>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" method="PUT" doc:name="HTTP">
<properties>
<spring:entry key="Content-Type" value="application/x-www-form-urlencoded"/>
</properties>
</http:outbound-endpoint>
</flow>
@damiancalabresi
Copy link

damiancalabresi commented Oct 2, 2017

Now it's not required to create the Form payload manually. When the HTTP Request connector receives a Map object, it will send the Form URL Encoded request, including the Content-Type.

https://docs.mulesoft.com/mule-user-guide/v/3.8/http-request-connector#generate-the-request-body-with-content-type-application-x-form-urlencoded

The Map can be created with Dataweave. For example:

<dw:transform-message doc:name="Transform to Map">
    <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
	request: write(payload, "application/xml")
}]]></dw:set-payload>
</dw:transform-message>
<http:request config-ref="HTTPConfiguration" path="/" method="POST" doc:name="Call Web Service">
</http:request>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment