2014-02-27 106 views
0

它又是我的了。Mule ESB - 如何通過HTTP POST方法調用API(一起發送參數)

我正在嘗試創建一個流程,該流程將向招聘門戶網站發佈招聘信息。他們通過Post方法公開他們的API。我不知道如何將值傳遞給HTTP端點。 這只是一個硬編碼值的測試樣本。當它工作時,我會讓流程從數據庫中獲取值。

<?xml version="1.0" encoding="UTF-8"?> 
<mule xmlns:wmq="http://www.mulesoft.org/schema/mule/ee/wmq" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
     xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.2" 
     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/wmq http://www.mulesoft.org/schema/mule/ee/wmq/current/mule-wmq-ee.xsd"> 
     <http:connector name="HTTP_CONFIG" cookieSpec="netscape" validateConnections="false" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="100000" serverSoTimeout="100000" socketSoLinger="0" proxyHostname="pta-proxy.work.co.za" proxyPort="3128" doc:name="HTTP\HTTPS" /> 
     <flow name="career24Flow1" doc:name="career24Flow1"> 
      <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" doc:name="HTTP" contentType="text/plain"/>  
      <message-properties-transformer doc:name="Set the post Values" > 
       <add-message-property key="apikey" value="XXXX"/> 
       <add-message-property key="integrationkey" value="567"/> 
       <add-message-property key="consultantemail" value="[email protected]"/> 
       <add-message-property key="title" value="Testing Mule API"/> 
       <add-message-property key="reference" value="33175"/> 
       <add-message-property key="jobtypeid" value="1"/> 
       <add-message-property key="closingdate" value="01/06/2014"/> 
       <add-message-property key="location" value="66"/> 
       <add-message-property key="salaryfrom" value="10000.00"/> 
       <add-message-property key="salaryto" value="20000.00"/> 
       <add-message-property key="salaryunitid" value="4"/> 
       <add-message-property key="description" value="Testing the Mule ESB to post to the portal"/> 
       <add-message-property key="companyname" value="CSIR"/> 
       <add-message-property key="sectorids" value="17"/> 
       <add-message-property key="applicationmethodid" value="2"/> 
       <add-message-property key="applicationurl" value="http://www.testing.com"/> 
       <add-message-property key="package" value="2"/> 
      </message-properties-transformer> 
      <http:outbound-endpoint exchange-pattern="request-response" host="api.work.com" port="80" method="POST" doc:name="Post on Career24" path="_integrations/httppost/vacancy.ashx" connector-ref="HTTP_CONFIG" contentType="application/x-www-form-urlencoded"/> 

     </flow> 
    </mule> 

我從站點得到這個回來,所以它似乎沒有通過HTTP端點發送值。

ERROR: 
- Field &#39;apikey&#39;, is required. 
- Field &#39;integrationkey&#39;, is required. 
- Field &#39;consultantemail&#39;, is required. 
- Field &#39;title&#39;, is required. 
- Field &#39;reference&#39;, is required. 
- Field &#39;jobtypeid&#39;, is required. 
- Field &#39;closingdate&#39;, is a required field. 
- Field &#39;sectorids&#39;, is required. 
- Field &#39;location&#39;, is required. 
- Field &#39;description&#39;, is required. 
- Field &#39;applicationmethodid&#39;, is required. 

我試過一個「消息到HTTP響應」變壓器以及但仍然沒有運氣。

感謝您的幫助。

問候。

雅科。

回答

0

使用屬性與http出站端點將它們設置爲http標頭。相反,您需要一個Map類型的有效載荷來將它們設置爲POST變量。

像這樣:

<set-payload value="#[['xxx':'yyy']]"/> 
+0

感謝Anton.I只是想確保語法。 還是這個錯誤? –

+0

是的,你有正確的語法。不過,根據您的使用情況,您可能希望以其他方式填充地圖。 –

+0

你又搖滾了!非常感謝您的幫助。 –

相關問題