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

This commit is contained in:
Mark Fisher
2010-11-21 19:36:45 -05:00
parent 7519398d7c
commit 6cc442345d
5 changed files with 35 additions and 19 deletions

View File

@@ -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();
}

View File

@@ -24,19 +24,19 @@
<xsd:extension base="base-ftp-adapter-type">
<xsd:attribute name="remote-directory" type="xsd:string"/>
<xsd:attribute name="remote-directory-expression" type="xsd:string"/>
<xsd:attribute name="filename-generator" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Allows you to specify a reference to
[org.springframework.integration.file.FileNameGenerator] implementation.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.file.FileNameGenerator"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="remote-filename-generator" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
A reference to an implementation of org.springframework.integration.file.FileNameGenerator.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.file.FileNameGenerator"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="remote-filename-generator-expression" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

View File

@@ -9,7 +9,6 @@
<int:channel id="ftpOutbound"/>
<bean id="ftpSessionFactory" class="org.springframework.integration.ftp.session.DefaultFtpsSessionFactory">
<property name="host" value="localhost"/>
<property name="port" value="22"/>
@@ -24,7 +23,7 @@
session-factory="ftpSessionFactory"
remote-directory="foo/bar"
channel="ftpOutbound"
filename-generator="fileNameGenerator"/>
remote-filename-generator="fileNameGenerator"/>
<bean id="fileNameGenerator" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.integration.file.FileNameGenerator"/>

View File

@@ -22,7 +22,7 @@
session-factory="ftpSessionFactory"
remote-directory="foo/bar"
charset="UTF-8"
filename-generator="fileNameGenerator"/>
remote-filename-generator="fileNameGenerator"/>
<int:channel id="ftpChannel"/>

View File

@@ -40,11 +40,12 @@
session-factory="ftpSessionFactory"
charset="UTF-8"
remote-directory="foo/bar"
filename-generator="fileNameGenerator"/>
remote-filename-generator="fileNameGenerator"/>
<int:channel id="ftpChannel"/>
<bean id="fileNameGenerator" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.integration.file.FileNameGenerator"/>
</bean>
</beans>