【问题标题】:WSO2 ESB: How to download a file over HTTP?WSO2 ESB:如何通过 HTTP 下载文件?
【发布时间】:2015-06-23 22:42:05
【问题描述】:

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

我尝试过将 VFS 作为代理服务和单独的序列都没有成功,并且在 Internet 上找不到任何相关资料。

这是序列 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 下载 大 文件?

【问题讨论】:

    标签: wso2esb vfs


    【解决方案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-message的http 400,进程进入faultsequence,但是faultsequence中的payloadFactory不起作用,我不知道为什么: (

    【讨论】:

    • 嗨@Inigo Fernandez 我有一个要求是我需要允许用户下载我本地系统中的文件,我尝试了上述API,但未能下载文件我将此API称为curl -v localhost:8282/services/ecorest/file.xml 每次进程都会进入故障序列,即使我给出了一个有效的文件名,也会给出响应为 {"jsonObject":{"descError":"","error":"true"}}跨度>
    【解决方案2】:

    试试这个配置:

    <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。希望这可以帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-06
      • 1970-01-01
      • 2021-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多