From 6cc442345d5e2f8844035ababec505427579bf78 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sun, 21 Nov 2010 19:36:45 -0500 Subject: [PATCH] INT-1614 added SpEL support for remote filename generator on FTP outbound adapters, and renamed the 'filename-generator' reference attribute to 'remote-filename-generator' to match SFTP --- .../FtpOutboundChannelAdapterParser.java | 20 ++++++++++++-- .../ftp/config/spring-integration-ftp-2.0.xsd | 26 +++++++++---------- .../ftp/FtpParserOutboundTests-context.xml | 3 +-- ...boundChannelAdapterParserTests-context.xml | 2 +- ...boundChannelAdapterParserTests-context.xml | 3 ++- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java index 7ec3bf25eb..61b35d8d44 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java @@ -49,7 +49,7 @@ public class FtpOutboundChannelAdapterParser extends AbstractOutboundChannelAdap boolean hasDirectoryExpression = StringUtils.hasText(remoteDirectoryExpression); if (!(hasDirectory ^ hasDirectoryExpression)) { throw new BeanDefinitionStoreException("exactly one of 'remote-directory' or 'remote-directory-expression' " + - "is required on the SFTP outbound adapter"); + "is required on the FTP outbound adapter"); } BeanDefinition expressionDef = null; if (hasDirectory) { @@ -61,8 +61,24 @@ public class FtpOutboundChannelAdapterParser extends AbstractOutboundChannelAdap expressionDef.getConstructorArgumentValues().addGenericArgumentValue(remoteDirectoryExpression); } handlerBuilder.addPropertyValue("remoteDirectoryExpression", expressionDef); + String remoteFileExpression = element.getAttribute("remote-filename-generator-expression"); + String fileNameGenerator = element.getAttribute("remote-filename-generator"); + boolean hasRemoteFileExpression = StringUtils.hasText(remoteFileExpression); + boolean hasFileNameGenerator = StringUtils.hasText(fileNameGenerator); + if (hasRemoteFileExpression || hasFileNameGenerator) { + if (hasRemoteFileExpression && hasFileNameGenerator) { + throw new BeanDefinitionStoreException("at most one of 'remote-filename-generator-expression' or 'remote-filename-generator' " + + "is allowed on the FTP outbound adapter"); + } + if (StringUtils.hasText(remoteFileExpression)) { + BeanDefinitionBuilder fileNameGeneratorBuilder = BeanDefinitionBuilder.genericBeanDefinition( + "org.springframework.integration.file.DefaultFileNameGenerator"); + fileNameGeneratorBuilder.addPropertyValue("expression", remoteFileExpression); + handlerBuilder.addPropertyValue("fileNameGenerator", fileNameGeneratorBuilder.getBeanDefinition()); + } + } + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(handlerBuilder, element, "remote-filename-generator", "fileNameGenerator"); IntegrationNamespaceUtils.setValueIfAttributeDefined(handlerBuilder, element, "charset"); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(handlerBuilder, element,"filename-generator", "fileNameGenerator"); return handlerBuilder.getBeanDefinition(); } 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 4265fcc3f8..36ff36a7b7 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 @@ -24,19 +24,19 @@ - - - - Allows you to specify a reference to - [org.springframework.integration.file.FileNameGenerator] implementation. - - - - - - - - + + + + A reference to an implementation of org.springframework.integration.file.FileNameGenerator. + + + + + + + + + diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/FtpParserOutboundTests-context.xml b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/FtpParserOutboundTests-context.xml index 0504712fc3..a908d59ba9 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/FtpParserOutboundTests-context.xml +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/FtpParserOutboundTests-context.xml @@ -9,7 +9,6 @@ - @@ -24,7 +23,7 @@ session-factory="ftpSessionFactory" remote-directory="foo/bar" channel="ftpOutbound" - filename-generator="fileNameGenerator"/> + remote-filename-generator="fileNameGenerator"/> diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests-context.xml b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests-context.xml index 7cbe392f57..304a2a0a82 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests-context.xml +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests-context.xml @@ -22,7 +22,7 @@ session-factory="ftpSessionFactory" remote-directory="foo/bar" charset="UTF-8" - filename-generator="fileNameGenerator"/> + remote-filename-generator="fileNameGenerator"/> diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsOutboundChannelAdapterParserTests-context.xml b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsOutboundChannelAdapterParserTests-context.xml index 593adf783d..507994a3dc 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsOutboundChannelAdapterParserTests-context.xml +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpsOutboundChannelAdapterParserTests-context.xml @@ -40,11 +40,12 @@ session-factory="ftpSessionFactory" charset="UTF-8" remote-directory="foo/bar" - filename-generator="fileNameGenerator"/> + remote-filename-generator="fileNameGenerator"/> +