java - mule http 中的错误请求(400)

标签 java mule

下面是我的java代码:

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();

以上数据是:

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

这工作正常。我在 Mule 中实现了同样的事情。我收到 400 错误。 我的骡子配置如下:

<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"/>

我的 json 是:

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

谢谢。

最佳答案

如果要设置 POST 变量,请使用 POST 方法和 Map 类型的有效负载。像这样:

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

这里的变量“param”当然只是您作为 POST 变量之一的 JSON 字符串,而不是所有变量。

关于java - mule http 中的错误请求(400),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22475395/

相关文章:

java - 将 org.w3c.dom.Document 漂亮地打印到标准输出的最短方法是什么?

java - 如何在命令行上覆盖类型安全配置列表值?

api - Mulesoft错误消息通过已部署的应用程序传播

java - Mule Dataweave 日期时间从完整日期时间转换为短日期时间

docker - 使用有限资源调整 Mule 性能

java - 从 Activiti 调用 Mule 非 Web 服务流程

java - NetBeans Hibernate 逆向工程数据类型不匹配

java - SQL INSERT 带有多行循环

java - Android 用户偏好设置错误

java - Mule SFTP 端点无法打开本地文件