2013-04-08 72 views
1

我想使用WSO2 ESB從Web站點下載XML文件。爲了簡單起見,假定URL是靜態的。WSO2 ESB:如何通過HTTP下載文件?

我已經嘗試過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> 

那麼,如何通過HTTP下載文件,WSO2 ESB?

回答

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。希望這可以幫助。

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完美的作品,並作出throught通與文件。但是,如果我發送一個id_file不存在,後端服務返回一個帶有json-message的http 400,該進程進入faultsequence,但fault序列中的payloadFactory不起作用,我不知道爲什麼: (

+0

嗨@Inigo Fernandez我有一個要求是我需要允許用戶下載文件,這是我的本地系統,我已經嘗試了上述API,但未能下載文件 我把這個API稱爲 curl - v http:// localhost:8282/services/ecorest/file.xml即使我給出有效的文件名,過程也會進入故障序列 給出的響應爲{「jsonObject」:{「descError」:「」, 「錯誤」: 「真正的」}} – user4045063 2016-02-08 11:08:07