Search in sources :

Example 1 with DefaultDirectoryScanner

use of org.springframework.integration.file.DefaultDirectoryScanner in project spring-integration by spring-projects.

the class FileInboundChannelAdapterParserTests method filter.

@Test
public void filter() throws Exception {
    DefaultDirectoryScanner scanner = (DefaultDirectoryScanner) accessor.getPropertyValue("scanner");
    DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(scanner);
    Object filter = scannerAccessor.getPropertyValue("filter");
    assertTrue("'filter' should be set and be of instance AcceptOnceFileListFilter but got " + filter.getClass().getSimpleName(), filter instanceof AcceptOnceFileListFilter);
    assertThat(scanner.getClass().getName(), containsString("FileReadingMessageSource$WatchServiceDirectoryScanner"));
    FileReadingMessageSource.WatchEventType[] watchEvents = (FileReadingMessageSource.WatchEventType[]) this.accessor.getPropertyValue("watchEvents");
    assertEquals(2, watchEvents.length);
    for (FileReadingMessageSource.WatchEventType watchEvent : watchEvents) {
        assertNotEquals(FileReadingMessageSource.WatchEventType.CREATE, watchEvent);
        assertThat(watchEvent, isOneOf(FileReadingMessageSource.WatchEventType.MODIFY, FileReadingMessageSource.WatchEventType.DELETE));
    }
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) AcceptOnceFileListFilter(org.springframework.integration.file.filters.AcceptOnceFileListFilter) DefaultDirectoryScanner(org.springframework.integration.file.DefaultDirectoryScanner) FileReadingMessageSource(org.springframework.integration.file.FileReadingMessageSource) Test(org.junit.Test)

Example 2 with DefaultDirectoryScanner

use of org.springframework.integration.file.DefaultDirectoryScanner in project spring-integration by spring-projects.

the class AbstractInboundFileSynchronizingMessageSource method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    Assert.notNull(this.localDirectory, "localDirectory must not be null");
    try {
        if (!this.localDirectory.exists()) {
            if (this.autoCreateLocalDirectory) {
                if (logger.isDebugEnabled()) {
                    logger.debug("The '" + this.localDirectory + "' directory doesn't exist; Will create.");
                }
                this.localDirectory.mkdirs();
            } else {
                throw new FileNotFoundException(this.localDirectory.getName());
            }
        }
        this.fileSource.setDirectory(this.localDirectory);
        if (this.localFileListFilter == null) {
            this.localFileListFilter = new FileSystemPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), getComponentName());
        }
        FileListFilter<File> filter = buildFilter();
        if (this.scannerExplicitlySet) {
            Assert.state(!this.fileSource.isUseWatchService(), "'useWatchService' and 'scanner' are mutually exclusive.");
            this.fileSource.getScanner().setFilter(filter);
        } else if (!this.fileSource.isUseWatchService()) {
            DirectoryScanner directoryScanner = new DefaultDirectoryScanner();
            directoryScanner.setFilter(filter);
            this.fileSource.setScanner(directoryScanner);
        } else {
            this.fileSource.setFilter(filter);
        }
        if (this.getBeanFactory() != null) {
            this.fileSource.setBeanFactory(this.getBeanFactory());
        }
        this.fileSource.afterPropertiesSet();
        this.synchronizer.afterPropertiesSet();
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new BeanInitializationException("Failure during initialization of MessageSource for: " + this.getClass(), e);
    }
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) FileSystemPersistentAcceptOnceFileListFilter(org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter) DirectoryScanner(org.springframework.integration.file.DirectoryScanner) DefaultDirectoryScanner(org.springframework.integration.file.DefaultDirectoryScanner) FileNotFoundException(java.io.FileNotFoundException) SimpleMetadataStore(org.springframework.integration.metadata.SimpleMetadataStore) File(java.io.File) DefaultDirectoryScanner(org.springframework.integration.file.DefaultDirectoryScanner) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException)

Aggregations

DefaultDirectoryScanner (org.springframework.integration.file.DefaultDirectoryScanner)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)1 DirectoryScanner (org.springframework.integration.file.DirectoryScanner)1 FileReadingMessageSource (org.springframework.integration.file.FileReadingMessageSource)1 AcceptOnceFileListFilter (org.springframework.integration.file.filters.AcceptOnceFileListFilter)1 FileSystemPersistentAcceptOnceFileListFilter (org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter)1 SimpleMetadataStore (org.springframework.integration.metadata.SimpleMetadataStore)1