Search code examples
spring-integrationspring-integration-dslspring-integration-sftp

Multiple Filter Expression with Spring Integration Flow


I am working with spring integration flow and I know how to add filter expression

IntegrationFlows.from(Sftp.inboundAdapter(inboundSftp)
            .localDirectory(this.getlocalDirectory(config.getId()))
            .deleteRemoteFiles(true)
            .filterExpression(config.getFilterExpression())
            .autoCreateLocalDirectory(true)
            .remoteDirectory(config.getInboundDirectory()), e -> e.poller(Pollers.cron(config.getCron()).errorChannel(MessageHeaders.ERROR_CHANNEL).errorHandler((ex) -> {
           // action on exceptions are here
        }))).publishSubscribeChannel(s -> s
            .subscribe(f -> f
                .handle(Sftp.outboundAdapter(outboundSftp)
                        .useTemporaryFileName(false)
                        .autoCreateDirectory(true)
                        .remoteDirectory(config.getOutboundDirectory()), c -> c.advice(startup.deleteFileAdvice())
                ))
            .subscribe(f -> f
                .handle(m -> {
                    // all my custom logging logic is here
                })
            ))
            .get();

What I want to understand.

  • How I can give multiple filter expression for example I want to get .csv and .xml files from server.
  • How I can ignore a single file type for example I want to ignore only file with .txt type and get rest files.

Solution

  • You can use .regexFilter instead.

    ".*\\.(xml|csv)"

    or

    .filterExpression("name.endsWith('.csv') OR name.endsWith('xml')")

    or

    .filterExpression("!name.endsWith('.txt')")