2013-10-04 47 views
4

我有一個soap服務,我想轉向並將消息發佈到外部服務器。帶表單數據的WSO2 ESB HTTP POST

我能夠通過捲曲做到這一點,像這樣:

curl --data-urlencode "filename=data.txt" --data-urlencode "filedir=/home/myfile/in" 
     --data-urlencode "busproc=MyBP" --data-urlencode "serverip=192.168.1.4" 
     --data-urlencode"uid=myuserid" --data-urlencode "pwd=mypwd" 
     http://somelocation.com:8833/webservice/inbound/here 

但我不能完全得到它正常工作。這裏是我的代理服務:

<proxy xmlns="http://ws.apache.org/ns/synapse" 
     name="ExampleHTTPPostWithFormData" 
     transports="http" 
     statistics="disable" 
     trace="disable" 
     startOnLoad="true"> 
    <target> 
     <inSequence> 
     <log/> 
     <property name="messageType" 
        value="application/x-www-form-urlencoded" 
        scope="axis2" 
        type="STRING"/> 
     <property name="HTTP_METHOD" value="post" scope="axis2" type="STRING"/> 
     <send> 
      <endpoint> 
       <address uri="http://somelocation.com:8833/webservice/inbound/here" 
         format="pox"/> 
       <property name="uid" value="user"/> 
       <property name="pwd" value="password"/> 
       <property name="filedir" value="/home/myfile/in"/> 
       <property name="busproc" value="myBP"/> 
       <property name="serverip" value="192.168.1.4"/> 
       <property name="filename" value="data.txt"/> 
      </endpoint> 
     </send> 
     <log level="full"/> 
     </inSequence> 
    </target> 
    <description/> 
</proxy> 

服務到底,似乎只看到我張貼到URL(而不是在數據屬性傳遞)。

回答

0

如果您在文件中發送SOAP有效負載,您將需要使用VFS傳輸。請參閱以下關於如何使用VFS運輸下面的示例來解決您的問題

http://docs.wso2.org/pages/viewpage.action?pageId=26838852 

或者您可以使用SOAPUI或SOAP客戶端有效載荷直接發送到ESB代理終結

+0

我爲什麼要用VFS發佈到網站?雖然上面有文件信息,但這不是目標。目標是用表單數據做一個HTTP帖子。 – user2836244

2

屬性是不構建消息內容的方式。我發現最好的辦法是用payloadFactory。您需要構建的消息具有一個根XML元素,每個表單字段包含一個子元素,然後Axis2似乎通過以適當的格式序列化來處理messageTypeapplication/x-www-form-urlencoded。因此,爲了您的代理最小的變化將是:

<proxy xmlns="http://ws.apache.org/ns/synapse" 
     name="ExampleHTTPPostWithFormData" 
     transports="http" 
     statistics="disable" 
     trace="disable" 
     startOnLoad="true"> 
    <target> 
     <inSequence> 
     <log/> 
     <property name="messageType" 
        value="application/x-www-form-urlencoded" 
        scope="axis2" 
        type="STRING"/> 
     <payloadFactory media-type="xml"> 
      <format> 
      <params xmlns=""> 
       <uid>user</uid> 
       <pwd>password</pwd> 
       <filedir>/home/myfile/in</filedir> 
       <busproc>myBP</busproc> 
       <serverip>192.168.1.4</serverip> 
       <filename>data.txt</filename> 
      </params> 
      </format> 
     </payloadFactory> 
     <send> 
      <endpoint> 
       <address uri="http://somelocation.com:8833/webservice/inbound/here" 
         format="rest"/> 
      </endpoint> 
     </send> 
     <log level="full"/> 
     </inSequence> 
    </target> 
    <description/> 
</proxy> 

它也可以很方便地根據添加<property name="FORCE_HTTP_1.0" value="true" scope="axis2" type="STRING"/>您的REST服務是否處理HTTP/1.1。

如果您需要參數,則可以使用XPath extensions將參數傳遞給payloadFactory。例如。

  <payloadFactory media-type="xml"> 
      <format> 
      <params xmlns=""> 
       <uid>user</uid> 
       <pwd>password</pwd> 
       <filedir>/home/myfile/in</filedir> 
       <busproc>myBP</busproc> 
       <serverip>192.168.1.4</serverip> 
       <filename>$1</filename> 
      </params> 
      </format> 
      <args> 
      <arg evaluator="xml" expression="$ctx:filename"/> 
      </args> 
     </payloadFactory>