Example usage for org.springframework.integration.ftp.dsl Ftp outboundGateway

List of usage examples for org.springframework.integration.ftp.dsl Ftp outboundGateway

Introduction

In this page you can find the example usage for org.springframework.integration.ftp.dsl Ftp outboundGateway.

Prototype

public static FtpOutboundGatewaySpec outboundGateway(RemoteFileTemplate<FTPFile> remoteFileTemplate,
        String command, String expression) 

Source Link

Document

Produce a FtpOutboundGatewaySpec based on the RemoteFileTemplate , AbstractRemoteFileOutboundGateway.Command and expression for the remoteFilePath.

Usage

From source file:org.springframework.integration.ftp.dsl.FtpTests.java

@Test
@SuppressWarnings("unchecked")
public void testFtpMgetFlow() {
    QueueChannel out = new QueueChannel();
    IntegrationFlow flow = f -> f//  ww w  .ja v  a2 s  .c  om
            .handle(Ftp
                    .outboundGateway(sessionFactory(), AbstractRemoteFileOutboundGateway.Command.MGET,
                            "payload")
                    .options(AbstractRemoteFileOutboundGateway.Option.RECURSIVE)
                    .filterExpression("name matches 'subFtpSource|.*1.txt'")
                    .localDirectoryExpression("'" + getTargetLocalDirectoryName() + "' + #remoteDirectory")
                    .localFilenameExpression("#remoteFileName.replaceFirst('ftpSource', 'localTarget')"))
            .channel(out);
    IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
    String dir = "ftpSource/";
    registration.getInputChannel().send(new GenericMessage<>(dir + "*"));
    Message<?> result = out.receive(10_000);
    assertNotNull(result);
    List<File> localFiles = (List<File>) result.getPayload();
    // should have filtered ftpSource2.txt
    assertEquals(2, localFiles.size());

    for (File file : localFiles) {
        assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
                Matchers.containsString(dir));
    }
    assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"),
            Matchers.containsString(dir + "subFtpSource"));

    registration.destroy();
}