spring 集成 sftp 出站网关删除

spring integration sftp outbound gateway remove

我正在尝试删除 sftp 远程文件夹中的 out-of-date 个文件:

<int-sftp:outbound-gateway
        session-factory="sftpSessionFactory"
        request-channel="rmChannel"
        reply-channel="sftpOutputChannel"
        remote-file-separator="/"
        command="rm"
        expression="headers['file_remoteDirectory'] + headers['file_remoteFile']">
    <int-sftp:request-handler-advice-chain>
        <si:retry-advice />
    </int-sftp:request-handler-advice-chain>
</int-sftp:outbound-gateway>

在进入网关之前,有一个过滤器 select 只有过时的文件:

@Override
@Filter
public boolean accept(Message<?> message) {
    if (message.getPayload() instanceof FileInfo) {
        final FileInfo fileInfo = (FileInfo) message.getPayload();
        final DateTime lastModified = new DateTime(fileInfo.getModified());

        boolean accept = lastModified.plusDays(this.days).isBeforeNow();
        return accept;
    }
    return false;
}

问题是:

  1. 为什么 header 'file_remoteFile' 没有自动创建?
  2. 当远程文件夹为空且没有可删除的内容时,程序无法停止。我应该如何解决这个问题?

FileHeaders.REMOTE_FILE 以及 FileHeaders.REMOTE_DIRECTORY 是由 prducing 组件自动创建的。由于您要手动删除远程文件,因此您还必须手动指定那些 headers。或者使用任何其他属性来构建要在 expression.

中删除的远程路径

还有一个你的问题不清楚。

我刚刚测试并在没有要删除的远程文件时结束了这个:

org.springframework.core.NestedIOException: Failed to remove file.; nested exception is 2: /junk

    at org.springframework.integration.sftp.session.SftpSession.remove(SftpSession.java:83)
...
Caused by: 2: /junk
    at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)
    at com.jcraft.jsch.ChannelSftp.rm(ChannelSftp.java:1958)
    at org.springframework.integration.sftp.session.SftpSession.remove(SftpSession.java:79)

因此,如果没有要删除的内容,则会抛出异常。

请详细说明您的程序如何无法停止或当您尝试删除不存在的删除文件时会发生什么。