Question

I am trying to test MuleStudio as a proxy service, I would like to do a very simple SOAP request using a static XML request string - I am currently having problems doing a simple POST in Mule, the GET method works and appending the SOAPAction header also works, my problem is setting a xml string/payload as the POST body and getting a response.

Any help would be amazing as the documentation is limited...

here is what I currently have:

<?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>
Était-ce utile?

La solution

Setting the POST body for http outbound is trivial in Mule. Whatever is the current payload, will be sent as the POST body. Try this example to see how http POST, headers, and http response work in 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>

Autres conseils

There are different ways of creating SOAP request in Mule flow.. You can use set payload and directly set the SOAP xml there..
Other options are like using XSLT and create your SOAP request there
ref :- https://developer.mulesoft.com/docs/display/current/XSLT+Transformer
You can also set the SOAP request in a file and call it into a flow using File connector
ref :- https://developer.mulesoft.com/docs/display/current/File+Connector
and yes need to set all these option before your HTTP outbound endpoint and set the HTTP outbound endpoint method as POST

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top