Rajesh Narravula
Rajesh Narravula

Reputation: 1463

bad request(400) in mule http

below is my java code:

Authenticator.setDefault(new MyAuthenticator(){
   public PasswordAuthentication getPasswordAuthentication() {
    return (new PasswordAuthentication(username, password.toCharArray()));
  }
}); 
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();

above data is:

action=start&params={"input":{"claimNo":"9","status":"open","customerName":"Rajesh"}}&createTask=false&parts=all

this working fine. same thing i implemented in Mule. I'm getting 400 error. my mule configuration is below:

<set-variable variableName="url" value="#[json:url]" doc:name="Variable"></set-variable>
<set-variable variableName="param" value="action=start&amp;params={&quot;input&quot;:#[json:param]}&amp;createTask=false&amp;parts=all" doc:name="Variable"></set-variable>
<http:outbound-endpoint exchange-pattern="request-response" address="http://admin:admin@#[url.substring(7)]" method="GET" doc:name="HTTP">
    <set-property propertyName="Content-Type" value="application/x-www-form-urlencoded"></set-property>
     <set-property propertyName="Accept" value="application/json"></set-property>
     <set-payload value="#[param]"/>
 </http:outbound-endpoint>
 <logger message="#['\n'+message.inboundProperties['http.status']]" level="INFO" doc:name="Logger"/>

my json is:

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

thanks.

Upvotes: 0

Views: 3304

Answers (1)

Anton Kupias
Anton Kupias

Reputation: 4015

If you want to set POST variables, use method POST, and a payload of type Map. Like this:

<set-payload value="#[['action':'start','params':param,'createTask':'false','parts':'all']]"/>

Variable "param" here of course just the JSON String you have as a one of the POST variables, not all your variables.

Upvotes: 1

Related Questions