【问题标题】:MuleStudio set Request HTTP POST BodyMuleStudio 设置请求 HTTP POST 正文
【发布时间】:2014-03-04 12:30:43
【问题描述】:

我正在尝试将 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>

【问题讨论】:

    标签: http http-post mule mule-studio


    【解决方案1】:

    在 Mule 中为 http outbound 设置 POST 正文很简单。无论当前有效负载是什么,都将作为 POST 正文发送。试试这个例子,看看 http POST、headers 和 http 响应在 Mule 中是如何工作的:

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

    【讨论】:

    • 感谢 Anton,您的帮助为我指明了正确的方向,我对 Mule 还是很陌生,我注意到它在内容类型标题方面非常严格......
    【解决方案2】:

    在 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-10
      • 2011-01-27
      • 2016-08-11
      相关资源
      最近更新 更多