Spring SFTP varying filename-regex

ぐ巨炮叔叔 提交于 2019-12-11 05:20:56

问题


Wondering whether Spring Integration SFTP inbound adapter supports a filename-regex that varies at runtime.

filename-regex will look like "^(foo_|bar_)" + new java.text.SimpleDateFormat("yyyyMMdd"). format(new java.util.Date()) +".txt$"

I have auto-startup="true" set in the inbound adapter settings.

In my test case, with a poller at fixed-rate="1000" time-unit="MILLISECONDS", it copies the right file for that day to the local directory. However, if I change the system date while it is still polling, it's not picking up the new date's file. If I rerun the test, it works.

My understanding is it should work. Is it not because it's running from JUnit?


回答1:


You could subclass the SftpRegexPatternFileListFilter and update the pattern on each call to accept - setPattern and return super.accept(file).

You could optimize it to only compile a new pattern when you detect a date change.




回答2:


The filename-regex option becomes SftpRegexPatternFileListFilter object at runtime.

You see it isn't designed for SpEL, just for regular pattern.

One of the solution for you is to implement your own FileListFilter with dynamic pattern compilation.

Another solution is to use SftpRegexPatternFileListFilter.setPattern() from, let's say, some pollers advice, if you need to be tied to the polling rate. Although the first solution will work, too, because looks like you are going to rely on the only new Date().

Nevertheless, it isn't good idea to "change the system date" and hope that all date-based components will recalculate their state. I think it so critical operation that it would be better to restart application after changing system date.



来源:https://stackoverflow.com/questions/40903674/spring-sftp-varying-filename-regex

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