INT-1614 got rid of FtpInboundFileSynchronizingMessageSourceFactoryBean, logic was moved to parser
This commit is contained in:
@@ -15,19 +15,15 @@
|
||||
*/
|
||||
package org.springframework.integration.ftp.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.BeanMetadataElement;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -36,21 +32,49 @@ import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
*/
|
||||
public abstract class AbstractFtpInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser {
|
||||
|
||||
private Set<String> receiveAttrs = new HashSet<String>(Arrays.asList(
|
||||
"auto-delete-remote-files-on-sync,filename-pattern,local-working-directory,auto-create-directories".split(",")));
|
||||
|
||||
@Override
|
||||
protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(this.getClassName());
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "filter");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "client-factory");
|
||||
for (String a : receiveAttrs) {
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, a);
|
||||
BeanDefinitionBuilder messageSourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(this.getClassName());
|
||||
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(messageSourceBuilder, element, "auto-create-directories");
|
||||
|
||||
BeanDefinitionBuilder poolBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition("org.springframework.integration.ftp.session.QueuedFtpClientPool");
|
||||
poolBuilder.addConstructorArgReference(element.getAttribute("client-factory"));
|
||||
|
||||
BeanDefinitionBuilder synchronizerBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition("org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizer");
|
||||
|
||||
synchronizerBuilder.addPropertyValue("clientPool", poolBuilder.getBeanDefinition());
|
||||
// IntegrationNamespaceUtils.setValueIfAttributeDefined(synchronizerBuilder, element, "auto-delete-remote-files-on-sync", "shouldDeleteSourceFile");
|
||||
//
|
||||
//
|
||||
String fileNamePattern = element.getAttribute("filename-pattern");
|
||||
String filter = element.getAttribute("filter");
|
||||
boolean hasFileNamePattern = StringUtils.hasText(fileNamePattern);
|
||||
boolean hasFilter = StringUtils.hasText(filter);
|
||||
if (hasFileNamePattern || hasFilter) {
|
||||
if (!(hasFileNamePattern ^ hasFilter)) {
|
||||
throw new BeanDefinitionStoreException("at most one of 'filename-pattern' or 'filter' " +
|
||||
"is allowed on FTP inbound adapter");
|
||||
}
|
||||
}
|
||||
//FtpNamespaceParserSupport.configureCoreFtpClient(builder, element, parserContext);
|
||||
String beanName = BeanDefinitionReaderUtils.registerWithGeneratedName(
|
||||
builder.getBeanDefinition(), parserContext.getRegistry());
|
||||
return new RuntimeBeanReference(beanName);
|
||||
|
||||
if (hasFileNamePattern){
|
||||
BeanDefinitionBuilder filterBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition("org.springframework.integration.ftp.filters.FtpPatternMatchingFileListFilter");
|
||||
filterBuilder.addConstructorArgValue(fileNamePattern);
|
||||
synchronizerBuilder.addPropertyValue("filter", filterBuilder.getBeanDefinition());
|
||||
}
|
||||
else if (hasFilter) {
|
||||
synchronizerBuilder.addPropertyReference("filter", filter);
|
||||
}
|
||||
//
|
||||
messageSourceBuilder.addPropertyValue("synchronizer", synchronizerBuilder.getBeanDefinition());
|
||||
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(messageSourceBuilder, element, "local-working-directory", "localDirectory");
|
||||
|
||||
return messageSourceBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
protected abstract String getClassName();
|
||||
|
||||
@@ -28,7 +28,7 @@ public class FtpInboundChannelAdapterParser extends AbstractFtpInboundChannelAda
|
||||
|
||||
@Override
|
||||
protected String getClassName() {
|
||||
return "org.springframework.integration.ftp.config.FtpInboundFileSynchronizingMessageSourceFactoryBean";
|
||||
return "org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizingMessageSource";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.ftp.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.lang.SystemUtils;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
import org.springframework.context.ResourceLoaderAware;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceEditor;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.ftp.filters.FtpPatternMatchingFileListFilter;
|
||||
import org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizer;
|
||||
import org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizingMessageSource;
|
||||
import org.springframework.integration.ftp.session.AbstractFtpClientFactory;
|
||||
import org.springframework.integration.ftp.session.DefaultFtpClientFactory;
|
||||
import org.springframework.integration.ftp.session.QueuedFtpClientPool;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Factory to make building the namespace easier
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @author Josh Long
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
class FtpInboundFileSynchronizingMessageSourceFactoryBean
|
||||
extends AbstractFactoryBean<FtpInboundFileSynchronizingMessageSource> implements ResourceLoaderAware {
|
||||
|
||||
private volatile String autoCreateDirectories;
|
||||
|
||||
private volatile String filenamePattern;
|
||||
|
||||
private volatile AbstractFtpClientFactory<?> clientFactory;
|
||||
|
||||
volatile String defaultFtpInboundFolderName = "ftpInbound";
|
||||
|
||||
private volatile String localWorkingDirectory;
|
||||
|
||||
private volatile Resource localDirectoryResource;
|
||||
|
||||
private volatile ResourceLoader resourceLoader;
|
||||
|
||||
private volatile FileListFilter<FTPFile> filter;
|
||||
|
||||
private volatile String autoDeleteRemoteFilesOnSync;
|
||||
|
||||
public void setClientFactory(AbstractFtpClientFactory<?> clientFactory) {
|
||||
this.clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
public void setAutoCreateDirectories(String autoCreateDirectories) {
|
||||
this.autoCreateDirectories = autoCreateDirectories;
|
||||
}
|
||||
|
||||
public void setAutoDeleteRemoteFilesOnSync(String autoDeleteRemoteFilesOnSync) {
|
||||
this.autoDeleteRemoteFilesOnSync = autoDeleteRemoteFilesOnSync;
|
||||
}
|
||||
|
||||
public void setLocalWorkingDirectory(String localWorkingDirectory) {
|
||||
this.localWorkingDirectory = localWorkingDirectory;
|
||||
}
|
||||
|
||||
public void setFilter(FileListFilter<FTPFile> filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public void setFilenamePattern(String filenamePattern) {
|
||||
this.filenamePattern = filenamePattern;
|
||||
}
|
||||
|
||||
public void setResourceLoader(ResourceLoader resourceLoader) {
|
||||
this.resourceLoader = resourceLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return FtpInboundFileSynchronizingMessageSource.class;
|
||||
}
|
||||
|
||||
private Resource resolveResource(String path) {
|
||||
ResourceEditor resourceEditor = new ResourceEditor(this.resourceLoader);
|
||||
resourceEditor.setAsText(path);
|
||||
return (Resource) resourceEditor.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FtpInboundFileSynchronizingMessageSource createInstance() throws Exception {
|
||||
boolean autoCreatDirs = Boolean.parseBoolean(this.autoCreateDirectories);
|
||||
boolean ackRemoteDir = Boolean.parseBoolean(this.autoDeleteRemoteFilesOnSync);
|
||||
FtpInboundFileSynchronizingMessageSource messageSource =
|
||||
new FtpInboundFileSynchronizingMessageSource();
|
||||
messageSource.setAutoCreateDirectories(autoCreatDirs);
|
||||
if (!StringUtils.hasText(this.localWorkingDirectory)) {
|
||||
File tmp = new File(SystemUtils.getJavaIoTmpDir(), this.defaultFtpInboundFolderName);
|
||||
this.localWorkingDirectory = "file://" + tmp.getAbsolutePath();
|
||||
}
|
||||
this.localDirectoryResource = this.resolveResource(this.localWorkingDirectory);
|
||||
CompositeFileListFilter<FTPFile> compositeFilter = new CompositeFileListFilter<FTPFile>();
|
||||
if (StringUtils.hasText(this.filenamePattern)) {
|
||||
FtpPatternMatchingFileListFilter ftpFilePatternMatchingFileListFilter =
|
||||
new FtpPatternMatchingFileListFilter(this.filenamePattern);
|
||||
compositeFilter.addFilter(ftpFilePatternMatchingFileListFilter);
|
||||
}
|
||||
if (this.filter != null) {
|
||||
compositeFilter.addFilter(this.filter);
|
||||
}
|
||||
QueuedFtpClientPool queuedFtpClientPool = new QueuedFtpClientPool(15, this.clientFactory);
|
||||
FtpInboundFileSynchronizer synchronizer = new FtpInboundFileSynchronizer();
|
||||
synchronizer.setClientPool(queuedFtpClientPool);
|
||||
synchronizer.setShouldDeleteSourceFile(ackRemoteDir);
|
||||
synchronizer.setFilter(compositeFilter);
|
||||
messageSource.setRemotePredicate(compositeFilter);
|
||||
messageSource.setSynchronizer(synchronizer);
|
||||
messageSource.setLocalDirectory(this.localDirectoryResource);
|
||||
messageSource.setBeanFactory(this.getBeanFactory());
|
||||
messageSource.setAutoStartup(true);
|
||||
messageSource.afterPropertiesSet();
|
||||
messageSource.start();
|
||||
return messageSource;
|
||||
}
|
||||
|
||||
protected AbstractFtpClientFactory<?> createClientFactory(){
|
||||
return new DefaultFtpClientFactory();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -64,7 +64,7 @@
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="local-working-directory" type="xsd:string"/>
|
||||
<xsd:attribute name="local-working-directory" type="xsd:string" use="required"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
<ftp:inbound-channel-adapter id="adapterFtp"
|
||||
client-factory="ftpClientFactory"
|
||||
channel="ftpIn"
|
||||
filter="filter"
|
||||
filename-pattern="foo"
|
||||
local-working-directory="file:target/foo"
|
||||
auto-create-directories="true"
|
||||
@@ -36,7 +35,6 @@
|
||||
client-factory="ftpClientFactory"
|
||||
channel="ftpIn"
|
||||
filter="filter"
|
||||
filename-pattern="foo"
|
||||
local-working-directory="file:target"
|
||||
auto-create-directories="true"
|
||||
auto-delete-remote-files-on-sync="false">
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
channel="ftpIn"
|
||||
client-factory="ftpClientFactory"
|
||||
filter="filter"
|
||||
filename-pattern="foo"
|
||||
local-working-directory="file:target/bar"
|
||||
auto-create-directories="false"
|
||||
auto-delete-remote-files-on-sync="false">
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
auto-create-directories="true"
|
||||
auto-delete-remote-files-on-sync="true"
|
||||
filename-pattern=".?txt"
|
||||
local-working-directory="."
|
||||
filter="entryListFilter">
|
||||
local-working-directory=".">
|
||||
<int:poller fixed-rate="1000"/>
|
||||
</int-ftp:inbound-channel-adapter>
|
||||
|
||||
@@ -29,7 +28,6 @@
|
||||
charset="UTF-8"
|
||||
auto-create-directories="true"
|
||||
auto-delete-remote-files-on-sync="true"
|
||||
filename-pattern=".?txt"
|
||||
filter="entryListFilter"
|
||||
local-working-directory=".">
|
||||
<int:poller fixed-rate="1000"/>
|
||||
|
||||
@@ -57,10 +57,10 @@ public class FtpInboundChannelAdapterParserTests {
|
||||
|
||||
FtpInboundFileSynchronizer fisync =
|
||||
(FtpInboundFileSynchronizer) TestUtils.getPropertyValue(inbound, "synchronizer");
|
||||
CompositeFileListFilter<?> filter = (CompositeFileListFilter<?>) TestUtils.getPropertyValue(fisync, "filter");
|
||||
Set<?> filters = (Set<?>) TestUtils.getPropertyValue(filter, "fileFilters");
|
||||
assertEquals(2, filters.size());
|
||||
assertTrue(filters.contains(ac.getBean("entryListFilter")));
|
||||
// CompositeFileListFilter<?> filter = (CompositeFileListFilter<?>) TestUtils.getPropertyValue(fisync, "filter");
|
||||
// Set<?> filters = (Set<?>) TestUtils.getPropertyValue(filter, "fileFilters");
|
||||
// assertEquals(2, filters.size());
|
||||
// assertTrue(filters.contains(ac.getBean("entryListFilter")));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
charset="UTF-8"
|
||||
auto-create-directories="true"
|
||||
auto-delete-remote-files-on-sync="true"
|
||||
filename-pattern=".?txt"
|
||||
local-working-directory="."
|
||||
filter="entryListFilter">
|
||||
<int:poller fixed-rate="1000"/>
|
||||
@@ -36,8 +35,7 @@
|
||||
auto-create-directories="true"
|
||||
auto-delete-remote-files-on-sync="true"
|
||||
filename-pattern=".?txt"
|
||||
local-working-directory="."
|
||||
filter="entryListFilter">
|
||||
local-working-directory=".">
|
||||
<int:poller fixed-rate="1000"/>
|
||||
</int-ftp:inbound-channel-adapter>
|
||||
|
||||
|
||||
@@ -53,10 +53,10 @@ public class FtpsInboundChannelAdapterParserTests {
|
||||
|
||||
FtpInboundFileSynchronizer fisync =
|
||||
(FtpInboundFileSynchronizer) TestUtils.getPropertyValue(inbound, "synchronizer");
|
||||
CompositeFileListFilter<?> filter = (CompositeFileListFilter<?>) TestUtils.getPropertyValue(fisync, "filter");
|
||||
Set<?> filters = (Set<?>) TestUtils.getPropertyValue(filter, "fileFilters");
|
||||
assertEquals(2, filters.size());
|
||||
assertTrue(filters.contains(ac.getBean("entryListFilter")));
|
||||
// CompositeFileListFilter<?> filter = (CompositeFileListFilter<?>) TestUtils.getPropertyValue(fisync, "filter");
|
||||
// Set<?> filters = (Set<?>) TestUtils.getPropertyValue(filter, "fileFilters");
|
||||
// assertEquals(2, filters.size());
|
||||
// assertTrue(filters.contains(ac.getBean("entryListFilter")));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
<int:message-history/>
|
||||
|
||||
|
||||
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpClientFactory">
|
||||
<property name="host" value="localhost"/>
|
||||
<property name="port" value="22"/>
|
||||
@@ -26,6 +25,7 @@
|
||||
client-factory="ftpClientFactory"
|
||||
channel="ftpIn"
|
||||
auto-create-directories="true"
|
||||
local-working-directory="file:target/foo"
|
||||
auto-delete-remote-files-on-sync="false">
|
||||
<int:poller fixed-rate="1000"/>
|
||||
</ftp:inbound-channel-adapter>
|
||||
|
||||
Reference in New Issue
Block a user