user3353393
user3353393

Reputation: 149

MULE ESB send post with parameters from previous component

First of all I want to show you code:

    <flow name="SetParamFlow" doc:name="SetParamFlow">
    <http:inbound-endpoint exchange-pattern="request-response"
        host="localhost" port="8081" path="setParamFlow" doc:name="HTTP" />
    <response>
        <http:response-builder status="200"
            doc:name="HTTP Response Builder" contentType="application/json">
            <http:cache-control noCache="true" />
        </http:response-builder>
    </response>
    <json:json-to-object-transformer
        returnClass="com.integration.SetParamWrapper"
        doc:name="JSON to Object" />

    <expression-component doc:name="Args2SOAP">
      <![CDATA[
        import java.util.HashMap;
        payload = {
          payload.getParam1(),
          payload.getParam2()
        };
      ]]>

    </expression-component>

    <response>
        <json:object-to-json-transformer
            doc:name="Object to JSON" />
    </response>
    <response>
        <expression-component doc:name="Simplify">
          <![CDATA[
               payload = ['param1': payload.getParam1(), 'exception': payload.exception.getValue()];
             ]]>
        </expression-component>
        <logger message="Simplified result: #[message.payload]" level="INFO" doc:name="Simplified result"/>
    </response>
    <logger message="Setting params : #[message.payload]" level="INFO" doc:name="Setting params"/>
</flow>

This is part of my learning mule system as you can see I get Param1 and Param2 but I don't know how to pass them with post at the end.

I want post them to external location like:

www.foo.com/getParams?value1=getParam1()&value2=getParam2()

I can do this with java spring RestTemplates but this isn't best option I want fully use mule. Any ideas how can I pass those params ?

Upvotes: 2

Views: 892

Answers (1)

Anton Kupias
Anton Kupias

Reputation: 4015

Very hard to understand your question, as you are talking about POSTing and have an example with GET.

At the end of your flow the message payload is an array with whatever your expression-component set with getParam1() and getParam2(). If you want those params into the url described, you can set that in an http outbound with address="http://www.foo.com/getParams?value1=#[payload[0]]&amp;value2=#[payload[1]]".

If you remove your Args2SOAP expression-component, you can use address="http://www.foo.com/getParams?value1=#[payload.getParam1()]&amp;value2=#[payload.getParam2()]" directly.

If you actually want to use http POST, whatever you set as payload before the http outbound, will be sent as the POST data.

Upvotes: 1

Related Questions