Example usage for org.springframework.integration.ftp.inbound FtpInboundFileSynchronizer FtpInboundFileSynchronizer

List of usage examples for org.springframework.integration.ftp.inbound FtpInboundFileSynchronizer FtpInboundFileSynchronizer

Introduction

In this page you can find the example usage for org.springframework.integration.ftp.inbound FtpInboundFileSynchronizer FtpInboundFileSynchronizer.

Prototype

public FtpInboundFileSynchronizer(SessionFactory<FTPFile> sessionFactory) 

Source Link

Document

Create a synchronizer with the SessionFactory used to acquire org.springframework.integration.file.remote.session.Session instances.

Usage

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

FtpInboundChannelAdapterSpec(SessionFactory<FTPFile> sessionFactory, Comparator<File> comparator) {
    super(new FtpInboundFileSynchronizer(sessionFactory));
    this.target = new FtpInboundFileSynchronizingMessageSource(this.synchronizer, comparator);
}

From source file:org.springframework.integration.ftp.inbound.FtpInboundRemoteFileSystemSynchronizerTests.java

@Test
public void testCopyFileToLocalDir() throws Exception {
    File localDirectoy = new File("test");
    assertFalse(localDirectoy.exists());

    TestFtpSessionFactory ftpSessionFactory = new TestFtpSessionFactory();
    ftpSessionFactory.setUsername("kermit");
    ftpSessionFactory.setPassword("frog");
    ftpSessionFactory.setHost("foo.com");
    FtpInboundFileSynchronizer synchronizer = spy(new FtpInboundFileSynchronizer(ftpSessionFactory));
    synchronizer.setDeleteRemoteFiles(true);
    synchronizer.setRemoteDirectory("remote-test-dir");
    synchronizer.setFilter(new FtpRegexPatternFileListFilter(".*\\.test$"));
    synchronizer.setIntegrationEvaluationContext(ExpressionUtils.createStandardEvaluationContext());

    ExpressionParser expressionParser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
    Expression expression = expressionParser.parseExpression("#this.toUpperCase() + '.a'");
    synchronizer.setLocalFilenameGeneratorExpression(expression);

    FtpInboundFileSynchronizingMessageSource ms = new FtpInboundFileSynchronizingMessageSource(synchronizer);

    ms.setAutoCreateLocalDirectory(true);

    ms.setLocalDirectory(localDirectoy);
    ms.afterPropertiesSet();//  www  . j a v  a 2 s  . co  m
    Message<File> atestFile = ms.receive();
    assertNotNull(atestFile);
    assertEquals("A.TEST.a", atestFile.getPayload().getName());
    Message<File> btestFile = ms.receive();
    assertNotNull(btestFile);
    assertEquals("B.TEST.a", btestFile.getPayload().getName());
    Message<File> nothing = ms.receive();
    assertNull(nothing);

    // two times because on the third receive (above) the internal queue will be empty, so it will attempt
    verify(synchronizer, times(2)).synchronizeToLocalDirectory(localDirectoy);

    assertTrue(new File("test/A.TEST.a").exists());
    assertTrue(new File("test/B.TEST.a").exists());
}