0
votes

Rest call is implemented in Java. same thing i want to implement in mule,
Java code is below:

URL url = new URL(RestUriConstants.BUSINESS_PROCESS_BASE + businessProcessName);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Accept","application/json");
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); 
writer.write(data);
writer.flush();

in mule i'm sending two things
1. URL
2. pay load

the json is like below:
{"url":"http://mysystem.com:8080/rest/processData","param":{"claimNo":"9","status":"open", "customerName":"Rajesh"}}

how can i pass that url dynamically, as well as i need to pass param value into the rest call..

---UPDATE----

payload value is like
"action=start&params={'input':#[json:param]}&createTask=false&parts=all"

example:

<set-payload value="action=start&params={'input':#[json:param]}&createTask=false&parts=all"/>

but it is giving error.

thanks.

1

1 Answers

2
votes

To do rest calls with a dynamic url in Mule, you just need to set the json as payload first, and then

<http:outbound-endpoint exchange-pattern="request-response" address="http://#[url]" method="POST" />

with variable url defining the url.

If your payload is the above json string, you can do

<set-variable variableName="url" value="#[json:url]"/>

and

<set-payload value="#[json:param]"/>

before the outbound. Note that in this case you have to strip the "http://" url prefix in the outbound like this:

address="http://#[url.substring(7)]"

Hope this gets you started, your question is a bit unclear.