4

我有一个肥皂服务,我想转身向外部服务器发布消息。

我可以像这样通过 curl 做到这一点:

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(而不是传入的数据属性)。

4

2 回答 2

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 ,添加也可能很方便。

如果您需要参数,那么您可以payloadFactory使用XPath 扩展将参数传递给. 例如

         <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>
于 2015-08-11T11:33:09.577 回答
0

如果您在文件中发送 SOAP 有效负载,则需要使用 VFS 传输。请参考以下示例,了解如何使用 VFS 传输来解决您的问题

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

或者,您可以使用 SOAPUI 或任何 SOAP 客户端将有效负载直接发送到 ESB 代理端点

于 2013-10-07T03:55:33.280 回答