我需要使用mule中的post方法将哈希映射对象传递给Http outbound。
怎么做?
答案 0 :(得分:0)
希望这可以提供帮助
<flow name="demoFlow1" doc:name="demoFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="hi" doc:name="HTTP"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<scripting:text><![CDATA[
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "Eddu");
map.put("lastname", "Melendez");
return map;
]]></scripting:text>
</scripting:script>
</scripting:component>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="print" method="POST" doc:name="HTTP"/>
</flow>
<flow name="demoFlow2" doc:name="demoFlow2">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="print" doc:name="HTTP"/>
<logger level="INFO" message="#[message.payloadAs(java.lang.String)]" doc:name="Logger"/>
</flow>
如果您通过服务发送地图,这将是输出:
INFO 2015-01-22 08:30:42,298 [[demo] .connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: name = Eddu&amp; lastname =梅伦德斯强>
你也可以在下面添加一行,以便在http
中获取json而不是查询参数
正如您所看到的,响应会有所不同
INFO 2015-01-22 08:32:31,014 [[demo] .connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: {&#34; name& #34;:&#34; Eddu&#34;&#34;姓&#34;:&#34;梅伦德斯&#34;} 强>