MuleStudio设置请求HTTP POST正文

时间:2014-03-04 12:30:43

标签: http http-post mule mule-studio

我正在尝试将MuleStudio作为代理服务进行测试,我想使用静态XML请求字符串执行一个非常简单的SOAP请求 - 我目前在Mule中执行简单的POST时遇到问题,GET方法正常工作并附加了SOAPAction标头也有效,我的问题是将xml字符串/有效负载设置为POST主体并获得响应。

由于文档有限,任何帮助都会令人惊讶......

这是我目前所拥有的:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core"
    version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd">
    <append-string-transformer message="testets" name="Append_String" doc:name="Append String"/>
    <flow name="testFlow1" doc:name="testFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
        <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="80" method="GET" followRedirects="true" doc:name="HTTP" >
        <set-property propertyName="SOAPAction" value="http://tempuri.org/getCurrencies" />          
        </http:outbound-endpoint>
    </flow>
</mule>

2 个答案:

答案 0 :(得分:2)

在Mule中为http outbound设置POST正文是微不足道的。无论当前的有效负载是什么,都将作为POST主体发送。试试这个例子来看看http:http:http:http://

中的http POST,header和http响应是如何工作的
<flow name="testFlow1"> 
  <http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8080" path="path1"/>
  <set-payload value="my post data"/> 
  <http:outbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8080" path="path2" method="POST"> 
    <set-property propertyName="SOAPAction" value="http://tempuri.org/getCurrencies" />
  </http:outbound-endpoint> 
  <object-to-string-transformer/> 
  <logger message="reply from post:#[payload]" level="INFO"/>
</flow>

<flow name="testFlow2"> 
  <http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8080" path="path2"/>    
  <object-to-string-transformer/> 
  <logger message="post data:#[payload]" level="INFO"/>
  <logger message="my header:#[message.inboundProperties['SOAPAction']]" level="INFO"/>
  <set-payload value="my reply"/> 
</flow>

答案 1 :(得分:1)

在Mule流程中有不同的方法来创建SOAP请求。 你可以使用set payload并直接设置SOAP xml ..
其他选项如使用 XSLT 并在那里创建SOAP请求 参考: - https://developer.mulesoft.com/docs/display/current/XSLT+Transformer
您还可以在文件中设置SOAP请求,并使用文件连接器
将其调用到流中 参考: - https://developer.mulesoft.com/docs/display/current/File+Connector
是的,需要在HTTP出站端点之前设置所有这些选项,并将HTTP出站端点方法设置为 POST