我一直试图让sftp入站适配器使用我的自定义过滤器,甚至使用我在选项中提供的过滤器。由于某种原因,它总是忽略我的过滤器。该模式也非常简单,并且确实匹配传入的文件名,如果过滤器将被调用。
有没有人有任何想法?
<int-sftp:inbound-channel-adapter id="cobaltInbound"
channel="dealerDataInboundChannelAdapterOutputChannel"
session-factory="dealerDataSftpSessionFactory"
filter="customInboundFTPFilter"
local-directory="${ftpOutputPath}"
remote-directory="outbound"
delete-remote-files="false"
preserve-timestamp="true"
charset="UTF-8"
local-filter="acceptAllFilter">
<int:poller cron="0 0/5 * * * *" max-messages-per-poll="10" error-channel="logger"/>
</int-sftp:inbound-channel-adapter>
自定义过滤器在很大程度上是基本的:
public class GenericInboundChannelFilter implements FileListFilter {
private Pattern pattern;
public GenericInboundChannelFilter() {
}
public GenericInboundChannelFilter(String patternString) {
this.pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
}
@Override
public List filterFiles(Object[] objects) {
ArrayList filteredFiles = new ArrayList();
if (pattern != null && objects != null && objects.length > 0) {
Object entry = null;
for (Object file : objects) {
Matcher matcher;
if (file instanceof File) {
matcher = pattern.matcher(((File) file).getName());
} else if (file instanceof FileInfo) {
matcher = pattern.matcher(((FileInfo) file).getFilename());
} else {
continue;
}
if (matcher.find()) {
if (entry != null) {
//compare the two entries
if (file instanceof File) {
if (((File) entry).lastModified() < ((File) file).lastModified()) {
entry = file;
}
} else {
if (((FileInfo) entry).getModified() < ((FileInfo) file).getModified()) {
entry = file;
}
}
} else {
entry = file;
}
}
}
if (entry != null) {
filteredFiles.add(entry);
}
}
return filteredFiles;
}
}