WSO2 ESB:如何通过 HTTP 下载文件? [英] WSO2 ESB: How to download a file over HTTP?

查看:24
本文介绍了WSO2 ESB:如何通过 HTTP 下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to download an XML file from a Web site using WSO2 ESB. Assume that the URL is static for the sake of simplicity.

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

I have tried VFS both as a proxy service and an individual sequence without success, and couldn't find any relevant material on the 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 下载文件?

So, how to download a large file over HTTP with WSO2 ESB?

推荐答案

我有一个类似的问题,现在我已经用 API 和这段代码解决了它:

I have a similar problem, and by the moment I've solved it with an API and this code:

<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 不起作用,我不知道为什么:(

This API works perfectly and make a throught-pass with the files. But if I send an id_file doesn't exist, the backend service return an http 400 with a json-message, the process go into the faultsequence, but the payloadFactory in the faultsequence doesn't work, and I don't know why :(

这篇关于WSO2 ESB:如何通过 HTTP 下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆