From 08d601a2ba0a4bce6a8290d74d2ebb55e12fa469 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 11 May 2011 15:03:09 -0400 Subject: [PATCH] INT-1901 added support for 'comparator' atribute for FTP/SFTP Inbound Channel adapters --- ...tractRemoteFileInboundChannelAdapterParser.java | 4 ++++ ...tractInboundFileSynchronizingMessageSource.java | 14 +++++++++++++- .../FtpInboundFileSynchronizingMessageSource.java | 8 ++++++++ .../ftp/config/spring-integration-ftp-2.0.xsd | 8 ++++++++ ...FtpInboundChannelAdapterParserTests-context.xml | 5 +++++ .../FtpInboundChannelAdapterParserTests.java | 5 +++++ .../SftpInboundFileSynchronizingMessageSource.java | 7 +++++++ .../sftp/config/spring-integration-sftp-2.0.xsd | 8 ++++++++ .../InboundChannelAdapterParserTests-context.xml | 5 +++++ .../config/InboundChannelAdapterParserTests.java | 5 ++++- 10 files changed, 67 insertions(+), 2 deletions(-) diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/config/AbstractRemoteFileInboundChannelAdapterParser.java b/spring-integration-file/src/main/java/org/springframework/integration/file/config/AbstractRemoteFileInboundChannelAdapterParser.java index 0e27f7b5f3..823b08f997 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/config/AbstractRemoteFileInboundChannelAdapterParser.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/config/AbstractRemoteFileInboundChannelAdapterParser.java @@ -64,6 +64,10 @@ public abstract class AbstractRemoteFileInboundChannelAdapterParser extends Abst // build the MessageSource BeanDefinitionBuilder messageSourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(this.getMessageSourceClassname()); messageSourceBuilder.addConstructorArgValue(synchronizerBuilder.getBeanDefinition()); + String comparator = element.getAttribute("comparator"); + if (StringUtils.hasText(comparator)){ + messageSourceBuilder.addConstructorArgReference(comparator); + } IntegrationNamespaceUtils.setValueIfAttributeDefined(messageSourceBuilder, element, "local-directory"); IntegrationNamespaceUtils.setValueIfAttributeDefined(messageSourceBuilder, element, "auto-create-local-directory"); return messageSourceBuilder.getBeanDefinition(); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java index 5c098ba5e3..08fd94df3c 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizingMessageSource.java @@ -19,6 +19,7 @@ package org.springframework.integration.file.remote.synchronizer; import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; +import java.util.Comparator; import java.util.regex.Pattern; import org.springframework.integration.Message; @@ -51,6 +52,7 @@ import org.springframework.util.Assert; * delivering new {@link File}s. * * @author Josh Long + * @author Oleg Zhurakousky */ public abstract class AbstractInboundFileSynchronizingMessageSource extends MessageProducerSupport implements MessageSource { @@ -73,12 +75,22 @@ public abstract class AbstractInboundFileSynchronizingMessageSource extends M /** * The actual {@link FileReadingMessageSource} that monitors the local file system once files are synchronized. */ - private final FileReadingMessageSource fileSource = new FileReadingMessageSource();; + private final FileReadingMessageSource fileSource; public AbstractInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer synchronizer) { + this(synchronizer, null); + } + + public AbstractInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer synchronizer, Comparator comparator) { Assert.notNull(synchronizer, "synchronizer must not be null"); this.synchronizer = synchronizer; + if (comparator == null){ + this.fileSource = new FileReadingMessageSource(); + } + else { + this.fileSource = new FileReadingMessageSource(comparator); + } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundFileSynchronizingMessageSource.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundFileSynchronizingMessageSource.java index 40a72ea4c9..040c36d28e 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundFileSynchronizingMessageSource.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/inbound/FtpInboundFileSynchronizingMessageSource.java @@ -16,6 +16,9 @@ package org.springframework.integration.ftp.inbound; +import java.io.File; +import java.util.Comparator; + import org.apache.commons.net.ftp.FTPFile; import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer; @@ -27,6 +30,7 @@ import org.springframework.integration.file.remote.synchronizer.AbstractInboundF * @author Iwein Fuld * @author Josh Long * @author Mark Fisher + * @author Oleg Zhurakousky * @since 2.0 */ public class FtpInboundFileSynchronizingMessageSource extends AbstractInboundFileSynchronizingMessageSource { @@ -34,6 +38,10 @@ public class FtpInboundFileSynchronizingMessageSource extends AbstractInboundFil public FtpInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer synchronizer) { super(synchronizer); } + + public FtpInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer synchronizer, Comparator comparator) { + super(synchronizer, comparator); + } public String getComponentType() { diff --git a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd b/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd index 668db1a4f5..c5572402a7 100644 --- a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd +++ b/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd @@ -116,6 +116,14 @@ endpoint itself is a Polling Consumer for a channel with a queue. + + + + + diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml index 05aeddee0b..d1ce5e8e4e 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml @@ -20,10 +20,15 @@ filename-pattern="*.txt" local-directory="." remote-file-separator="" + comparator="comparator" temporary-file-suffix=".foo" remote-directory="foo/bar"> + + + + comparator = TestUtils.getPropertyValue(adapter, "source.fileSource.toBeReceived.q.comparator", Comparator.class); + assertNotNull(comparator); assertEquals("ftpInbound", adapter.getComponentName()); assertEquals("ftp:inbound-channel-adapter", adapter.getComponentType()); assertNotNull(TestUtils.getPropertyValue(adapter, "poller")); diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundFileSynchronizingMessageSource.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundFileSynchronizingMessageSource.java index ceec0b5bcc..5b30972430 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundFileSynchronizingMessageSource.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/inbound/SftpInboundFileSynchronizingMessageSource.java @@ -16,6 +16,9 @@ package org.springframework.integration.sftp.inbound; +import java.io.File; +import java.util.Comparator; + import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer; import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource; @@ -35,6 +38,10 @@ public class SftpInboundFileSynchronizingMessageSource extends AbstractInboundFi public SftpInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer synchronizer) { super(synchronizer); } + + public SftpInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer synchronizer, Comparator comparator) { + super(synchronizer, comparator); + } public String getComponentType() { diff --git a/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.0.xsd b/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.0.xsd index 2c242fdeea..419af7c29f 100644 --- a/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.0.xsd +++ b/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.0.xsd @@ -157,6 +157,14 @@ endpoint itself is a Polling Consumer for a channel with a queue. + + + + + + + + + comparator = TestUtils.getPropertyValue(adapter, "source.fileSource.toBeReceived.q.comparator", Comparator.class); + assertNotNull(comparator); SftpInboundFileSynchronizer synchronizer = (SftpInboundFileSynchronizer) TestUtils.getPropertyValue(source, "synchronizer"); String remoteFileSeparator = (String) TestUtils.getPropertyValue(synchronizer, "remoteFileSeparator"); assertEquals(".bar", TestUtils.getPropertyValue(synchronizer, "temporaryFileSuffix", String.class));