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

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

Introduction

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

Prototype

public static FtpInboundChannelAdapterSpec inboundAdapter(SessionFactory<FTPFile> sessionFactory) 

Source Link

Document

A FtpInboundChannelAdapterSpec factory for an inbound channel adapter spec.

Usage

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

@Test
public void testFtpInboundFlow() {
    QueueChannel out = new QueueChannel();
    IntegrationFlow flow = IntegrationFlows.from(
            Ftp.inboundAdapter(sessionFactory()).preserveTimestamp(true).remoteDirectory("ftpSource")
                    .regexFilter(".*\\.txt$").localFilename(f -> f.toUpperCase() + ".a")
                    .localDirectory(getTargetLocalDirectory()),
            e -> e.id("ftpInboundAdapter").poller(Pollers.fixedDelay(100))).channel(out).get();
    IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
    Message<?> message = out.receive(10_000);
    assertNotNull(message);// w  w  w .  j a v a 2  s . c  om
    Object payload = message.getPayload();
    assertThat(payload, instanceOf(File.class));
    File file = (File) payload;
    assertThat(file.getName(), isOneOf(" FTPSOURCE1.TXT.a", "FTPSOURCE2.TXT.a"));
    assertThat(file.getAbsolutePath(), containsString("localTarget"));

    message = out.receive(10_000);
    assertNotNull(message);
    file = (File) message.getPayload();
    assertThat(file.getName(), isOneOf(" FTPSOURCE1.TXT.a", "FTPSOURCE2.TXT.a"));
    assertThat(file.getAbsolutePath(), containsString("localTarget"));

    assertNull(out.receive(10));

    File remoteFile = new File(this.sourceRemoteDirectory, " " + prefix() + "Source1.txt");
    remoteFile.setLastModified(System.currentTimeMillis() - 1000 * 60 * 60 * 24);

    message = out.receive(10_000);
    assertNotNull(message);
    payload = message.getPayload();
    assertThat(payload, instanceOf(File.class));
    file = (File) payload;
    assertEquals(" FTPSOURCE1.TXT.a", file.getName());

    registration.destroy();
}