Spring integration spring集成sftp出站网关删除

Spring integration spring集成sftp出站网关删除,spring-integration,sftp,Spring Integration,Sftp,我正在尝试使用以下方法删除sftp远程文件夹中的过期文件: <int-sftp:outbound-gateway session-factory="sftpSessionFactory" request-channel="rmChannel" reply-channel="sftpOutputChannel" remote-file-separator="/" command="rm" expr

我正在尝试使用以下方法删除sftp远程文件夹中的过期文件:

<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>

在进入网关之前,有一个过滤器,仅选择过期的文件:

@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;
}
@覆盖
@滤器
公共布尔接受(消息){
if(message.getPayload()instanceof FileInfo){
final FileInfo FileInfo=(FileInfo)message.getPayload();
final DateTime lastModified=新日期时间(fileInfo.getModified());
boolean accept=lastModified.plusDays(this.days).isBeforeNow();
退货接受;
}
返回false;
}
问题是:

  • 为什么头文件“file\u remoteFile”不是自动创建的
  • 当远程文件夹为空且没有要删除的内容时,程序无法停止。我应该如何解决这个问题
    FileHeaders.REMOTE\u文件
    ,以及
    FileHeaders.REMOTE\u目录
    ,是通过
    生成组件自动创建的。由于要手动删除远程文件,因此还必须手动指定这些头文件。或者使用任何其他属性构建远程路径,以便在该
    表达式中删除

    另一个问题是你的问题不清楚

    我刚刚进行了测试,在没有可删除的远程文件的情况下得出了以下结论:

    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)
    
    因此,如果没有要删除的内容,则会引发异常


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

    文件头。远程文件以及文件头。远程目录是由
    生成的
    组件自动创建的。由于要手动删除远程文件,因此还必须手动指定这些头文件。或者使用任何其他属性构建远程路径,以便在该
    表达式中删除

    另一个问题是你的问题不清楚

    我刚刚进行了测试,在没有可删除的远程文件的情况下得出了以下结论:

    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)
    
    因此,如果没有要删除的内容,则会引发异常


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

    谢谢您的回答!因此,我使用了
    标题enricher
    解决了这个问题。对于第二个问题,我的测试如下:对不起,垃圾邮件。。。。测试:
    public void can_call_sftp_bean()抛出异常{try{final Message Message=MessageBuilder.withPayload(“test”).build();sftpHousekeepingInputChannel.send(Message);final Message received=(Message)sftpHousekeepingOutputChannel.receive();}捕获(异常e){e.getStackTrace();}}
    测试无法停止。在这种情况下,这是真的,因为删除失败,出现异常,并且没有人会向出站频道发送回复。感谢您的回答!因此我使用了
    标题enricher
    解决了这个问题。对于第二个问题,我的测试如下:很抱歉收到垃圾邮件…测试:
    public void can_call_sftp_bean()抛出异常{try{final Message Message=MessageBuilder.withPayload(“test”).build();sftpHousekeepingInputChannel.send(Message);final Message received=(Message)sftpHousekeepingOutputChannel.receive();}捕获(异常e){e.getStackTrace();}}
    测试无法停止。在本例中,这是真的,因为delete失败,出现异常,并且没有人将应答发送到出站通道。