WSO2 ESB:如何通过HTTP下载文件?

时间:2013-04-08 08:51:04

标签: wso2esb vfs

我想使用WSO2 ESB从网站下载XML文件。为简单起见,假设URL是静态的。

我已经尝试过VFS作为代理服务和单个序列而没有成功,并且在互联网上找不到任何相关资料。

这是序列XML:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="download">
   <in>
      <log level="headers">
         <property name="?" value="[download] in: started"/>
      </log>
      <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
      <property name="transport.vfs.ContentType" value="text/xml" scope="transport" type="STRING"/>
      <property name="transport.vfs.FileURI" value="http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-2013.xml" scope="transport" type="STRING"/>
      <log level="headers">
         <property name="?" value="[download] in: sending over vfs"/>
      </log>
      <send>
         <endpoint>
            <address uri="http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-2013.xml"/>
         </endpoint>
      </send>
      <log level="headers">
         <property name="?" value="[download] in: ended"/>
      </log>
   </in>
   <out>
      <log level="headers">
         <property name="?" value="[download] out: started"/>
      </log>
      <send/>
      <log level="headers">
         <property name="?" value="[download] out: ended"/>
      </log>
   </out>
</sequence>

那么,如何使用WSO2 ESB通过HTTP下载大型文件?

2 个答案:

答案 0 :(得分:1)

我遇到了类似的问题,目前我已经使用API​​和此代码解决了这个问题:

<api xmlns="http://ws.apache.org/ns/synapse" name="EcoRest" context="/services/ecorest">
   <resource methods="GET" uri-template="/{idFile}">
      <inSequence>
         <send>
            <endpoint>
               <http method="get" uri-template="http://slx00012001:8888/repositoryfiles/{uri.var.idFile}">
                  <suspendOnFailure>
                     <errorCodes>101500,101510,101001,101000</errorCodes>
                     <initialDuration>10</initialDuration>
                     <progressionFactor>1.0</progressionFactor>
                     <maximumDuration>10</maximumDuration>
                  </suspendOnFailure>
               </http>
            </endpoint>
         </send>
         <property name="enableSwA" value="true" scope="axis2"></property>
      </inSequence>
      <faultSequence>
         <log level="custom">
            <property name="FAULT GETTING FILE" expression="get-property('uri.var.idFile')"></property>
         </log>
         <payloadFactory media-type="json">
            <format>           {"descError":"$1", "error": "true"}           </format>
            <args>
               <arg evaluator="json" expression="$.descError"></arg>
            </args>
         </payloadFactory>
         <property name="HTTP_SC" value="500" scope="axis2" type="STRING"></property>
         <respond></respond>
      </faultSequence>
   </resource>
</api>

此API工作正常,并与文件进行通过。但是如果我发送的id_file不存在,后端服务会返回一个带有json消息的http 400,进程会进入故障序列,但是故障序列中的payloadFactory不起作用,我不会&# 39;不知道为什么:(

答案 1 :(得分:0)

使用此配置:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="download" transports="https,http,vfs" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
         <property name="ClientApiNonBlocking" value="true" scope="axis2" action="remove"/>
         <send>
            <endpoint>
               <address uri="vfs:file://home/secondary/file.xml"/>
            </endpoint>
         </send>
      </inSequence>
   </target>
   <parameter name="transport.vfs.Streaming">true</parameter>
   <parameter name="transport.vfs.FileURI">http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-2013.xml</parameter>
   <parameter name="transport.vfs.Locking">disable</parameter>
   <description></description>
</proxy>

您可以使用以下方式启动下载:

curl -v http://localhost:8280/services/download

您可以在此处找到有关VFS传输特定参数的更多信息:http://docs.wso2.org/wiki/display/ESB460/VFS+Transport。您还可以在此处找到另一个VFS示例:http://docs.wso2.org/wiki/pages/viewpage.action?pageId=16846489。希望这可以帮助。

相关问题