1
votes

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?

2

2 Answers

1
votes

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.

1
votes

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.