【问题标题】:Spring Integration - Use filename with gatewaySpring Integration - 将文件名与网关一起使用
【发布时间】:2018-10-09 07:31:39
【问题描述】:

我在使用 spring 集成时遇到了问题。

我想在 ftp 服务器上发出请求以检索文件名 (在命令行:ls“文件名”)

但我无法动态恢复文件名。 我知道有一个关于有效负载或标题的故事,但我不能

这就是我所拥有的:

查看我的控制器,我使用这个:

private FtpConfig.MyGateway gateway;
...
gateway.fichierExist(filename);

在我的 FTP 文件中:

@Bean
public SessionFactory<FTPFile> ftpSessionFactory() {
    DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
    sf.setHost("");
    sf.setPort(21);
    sf.setUsername("");
    sf.setPassword("");
    return new CachingSessionFactory<FTPFile>(sf);
}


@Bean
@ServiceActivator(inputChannel = "ftpChannelExist")
public MessageHandler handler2() {
    FtpOutboundGateway ftpOutboundGateway =
            new FtpOutboundGateway(ftpSessionFactory(), "ls");
    ftpOutboundGateway.setOptions("-a -1")
    FtpSimplePatternFileListFilter filter = new FtpSimplePatternFileListFilter("filename"); //on filtre sur le nom

    return ftpOutboundGateway;
}


@MessagingGateway
public interface MyGateway {

    @Gateway(requestChannel = "ftpChannelExist")
    ArrayList<String> fichierExist(String filename);

}

我也尝试过使用标题,但我无能为力...

谢谢。

(对不起我的英语,我是法国人)

【问题讨论】:

    标签: spring spring-integration gateway


    【解决方案1】:

    参见Reference Manual中的LS命令说明:

    此外,还提供文件名过滤,方式与inbound-channel-adapter 相同。

    ls 操作产生的消息负载是文件名列表或FileInfo 对象列表。这些对象提供修改时间、权限等信息。

    ls 命令作用的远程目录在file_remoteDirectory 标头中提供。

    您的配置中缺少的是remote directory 的事实,可以从中获取文件。通常,我们建议在 payload 中拥有这样的目录,就像使用 fichierExist(String filename) 一样,并为 FtpOutboundGateway 配置第三个 ctor arg:

    FtpOutboundGateway ftpOutboundGateway =
            new FtpOutboundGateway(ftpSessionFactory(), "ls", "payload");
    

    根据FtpOutboundGateway 中的逻辑,该表达式在LS 命令中充当远程目录的源。在您的情况下,这将成为您的 fichierExist(String filename) 网关的参数。

    您确实可以在那里使用FtpSimplePatternFileListFilter,但请务必指定适当的模式来过滤远程文件。

    最终请求目录中的远程文件的名称,过滤后将返回到您网关的ArrayList&lt;String&gt;。没错。

    否则你的问题不清楚。

    【讨论】:

      【解决方案2】:

      感谢您的回复。

      我已更改我的 FtpOutboundGateway 以添加“有效负载”,但我无法为我的 FtpSimplePatternFileListFilter 使用有效负载。

      我试过了:

      FtpSimplePatternFileListFilter filter = new FtpSimplePatternFileListFilter("filename"); 
      
      FtpSimplePatternFileListFilter filter = new FtpSimplePatternFileListFilter("payload"); 
      
      FtpSimplePatternFileListFilter filter = new FtpSimplePatternFileListFilter("payload.filename"); 
      
      FtpSimplePatternFileListFilter filter = new FtpSimplePatternFileListFilter("payload['filename']"); 
      

      【讨论】:

        猜你喜欢
        • 2018-08-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-29
        • 1970-01-01
        • 2014-02-17
        相关资源
        最近更新 更多