Using “Mule Requester” and FTP loses originalFilename

白昼怎懂夜的黑 提交于 2020-01-23 03:30:51

问题


I am working on a flow that will, when triggered by an HTTP request, download files from an FTP server. In order to do this on request, instead of on polling, I am using the Mule Requester.

I have found that without the requestor, FTP connector will set the "incomingFilename" on the inboundProperties collection for each of the files. When used with the Mule Requester, the filename property is not set, therefore I have no idea what file I am processing... or in this case saving to the file system. In the code below I am using the 'counter' variable for thefilename in the case the the filename doesn't come through.

Any idea how to fix this issue? Here is the flow below:

<ftp:connector name="FTPConfig" pollingFrequency="3000" validateConnections="true" doc:name="FTP"></ftp:connector>


<flow name="FileRequestFlow"> 
        <http:listener config-ref="HTTP_Listener_Configuration" path="csvfilesready" allowedMethods="GET" doc:name="HTTP"></http:listener>  
        <mulerequester:request-collection config-ref="Mule_Requester" resource="ftp://username:pswd@127.0.0.1:21/Incoming?connector=FTPConfig" doc:name="Mule Requester"></mulerequester:request-collection>
                <foreach collection="#[payload]" doc:name="For Each">
        <set-variable variableName="thefilename" value="#[message.inboundProperties.originalFilename==null ? counter.toString()+'.csv' : message.inboundProperties.originalFilename] " doc:name="Variable"/> 
        <file:outbound-endpoint path="/IncomingComplete" outputPattern="#[flowVars.thefilename]" responseTimeout="10000" doc:name="File"></file:outbound-endpoint>
        <logger message="#['File saved as:  ' + payload]" level="INFO" doc:name="Logger"></logger>  
    </foreach>

        <logger message="#[payload]" level="INFO" doc:name="Logger"></logger>  
    </flow>

回答1:


UPDATE: Below is an option for working with the requester, however, you can use the request-collection. The key is to realize that it will return a MuleMessageCollection and to use the Collection Splitter directly after the Requester, which will then returning individually the ftp file messages with the originalFilename.


After playing with this a while, I have found that with FTP in the mule requester you can get the filename only if you use it as a request, not request-collection.

Have not been able to get the request-collection to work if you need filenames associated.

So.... If you need multiple files, you need do something like loop on the requester until the payload is null.

If you have alternate methods please let me know.




回答2:


I have written an alternate ftp-connector, it allows to issue a list-command in the flow, followed by a loop to read the files.

See: https://github.com/rbutenuth/ftp-client-connector/



来源:https://stackoverflow.com/questions/31843366/using-mule-requester-and-ftp-loses-originalfilename

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!