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 98c16eca45..3487b1a03e 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
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors.
+ * Copyright 2002-2011 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.
@@ -36,15 +36,22 @@ public abstract class AbstractRemoteFileInboundChannelAdapterParser extends Abst
@Override
protected final BeanMetadataElement parseSource(Element element, ParserContext parserContext) {
- // build the SessionFactory
- BeanDefinitionBuilder sessionFactoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(
- "org.springframework.integration.file.remote.session.CachingSessionFactory");
- sessionFactoryBuilder.addConstructorArgReference(element.getAttribute("session-factory"));
-
- // build the InboundFileSynchronizer
BeanDefinitionBuilder synchronizerBuilder = BeanDefinitionBuilder.genericBeanDefinition(
this.getInboundFileSynchronizerClassname());
- synchronizerBuilder.addConstructorArgValue(sessionFactoryBuilder.getBeanDefinition());
+
+ // build the SessionFactory and provide as a constructor argument
+ String cacheSessions = element.getAttribute("cache-sessions");
+ if ("false".equalsIgnoreCase(cacheSessions)) {
+ synchronizerBuilder.addConstructorArgReference(element.getAttribute("session-factory"));
+ }
+ else {
+ BeanDefinitionBuilder sessionFactoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(
+ "org.springframework.integration.file.remote.session.CachingSessionFactory");
+ sessionFactoryBuilder.addConstructorArgReference(element.getAttribute("session-factory"));
+ synchronizerBuilder.addConstructorArgValue(sessionFactoryBuilder.getBeanDefinition());
+ }
+
+ // configure the InboundFileSynchronizer properties
IntegrationNamespaceUtils.setValueIfAttributeDefined(synchronizerBuilder, element, "remote-directory");
IntegrationNamespaceUtils.setValueIfAttributeDefined(synchronizerBuilder, element, "delete-remote-files");
IntegrationNamespaceUtils.setValueIfAttributeDefined(synchronizerBuilder, element, "remote-file-separator");
diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/config/RemoteFileOutboundChannelAdapterParser.java b/spring-integration-file/src/main/java/org/springframework/integration/file/config/RemoteFileOutboundChannelAdapterParser.java
index d8033f3bb8..4a94afc433 100644
--- a/spring-integration-file/src/main/java/org/springframework/integration/file/config/RemoteFileOutboundChannelAdapterParser.java
+++ b/spring-integration-file/src/main/java/org/springframework/integration/file/config/RemoteFileOutboundChannelAdapterParser.java
@@ -37,15 +37,22 @@ public class RemoteFileOutboundChannelAdapterParser extends AbstractOutboundChan
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
- // build SessionFactory
- BeanDefinitionBuilder sessionFactoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(
- "org.springframework.integration.file.remote.session.CachingSessionFactory");
- sessionFactoryBuilder.addConstructorArgReference(element.getAttribute("session-factory"));
-
- // build MessageHandler
BeanDefinitionBuilder handlerBuilder = BeanDefinitionBuilder.genericBeanDefinition(
"org.springframework.integration.file.remote.handler.FileTransferringMessageHandler");
- handlerBuilder.addConstructorArgValue(sessionFactoryBuilder.getBeanDefinition());
+
+ // build the SessionFactory and provide as a constructor argument
+ String cacheSessions = element.getAttribute("cache-sessions");
+ if ("false".equalsIgnoreCase(cacheSessions)) {
+ handlerBuilder.addConstructorArgReference(element.getAttribute("session-factory"));
+ }
+ else {
+ BeanDefinitionBuilder sessionFactoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(
+ "org.springframework.integration.file.remote.session.CachingSessionFactory");
+ sessionFactoryBuilder.addConstructorArgReference(element.getAttribute("session-factory"));
+ handlerBuilder.addConstructorArgValue(sessionFactoryBuilder.getBeanDefinition());
+ }
+
+ // configure MessageHandler properties
IntegrationNamespaceUtils.setValueIfAttributeDefined(handlerBuilder, element, "temporary-file-suffix");
IntegrationNamespaceUtils.setValueIfAttributeDefined(handlerBuilder, element, "auto-create-directory");
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 e56af8089a..fe2f075c10 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
@@ -193,6 +193,13 @@ 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 804266c9ed..797a3d30f0 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
@@ -13,6 +13,7 @@
-
+
+
+
+
+
diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java
index d631518712..af75d22324 100644
--- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java
+++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors.
+ * Copyright 2002-2011 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.
@@ -18,6 +18,7 @@ package org.springframework.integration.ftp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -29,6 +30,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
+import org.springframework.integration.file.remote.session.CachingSessionFactory;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.ftp.filters.FtpSimplePatternFileListFilter;
import org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizer;
@@ -38,6 +40,7 @@ import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
+ * @author Mark Fisher
*/
public class FtpInboundChannelAdapterParserTests {
@@ -60,12 +63,22 @@ public class FtpInboundChannelAdapterParserTests {
assertNotNull(remoteFileSeparator);
assertEquals(".", remoteFileSeparator);
FtpSimplePatternFileListFilter filter = (FtpSimplePatternFileListFilter) TestUtils.getPropertyValue(fisync, "filter");
- assertNotNull(filter);
+ assertNotNull(filter);
+ Object sessionFactory = TestUtils.getPropertyValue(fisync, "sessionFactory");
+ assertTrue(DefaultFtpSessionFactory.class.isAssignableFrom(sessionFactory.getClass()));
}
-
+
+ @Test
+ public void cachingSessionFactoryByDefault() throws Exception{
+ ApplicationContext ac = new ClassPathXmlApplicationContext(
+ "FtpInboundChannelAdapterParserTests-context.xml", this.getClass());
+ SourcePollingChannelAdapter adapter = ac.getBean("simpleAdapter", SourcePollingChannelAdapter.class);
+ Object sessionFactory = TestUtils.getPropertyValue(adapter, "source.synchronizer.sessionFactory");
+ assertEquals(CachingSessionFactory.class, sessionFactory.getClass());
+ }
+
@Test
public void testFtpInboundChannelAdapterCompleteNoId() throws Exception{
-
ApplicationContext ac =
new ClassPathXmlApplicationContext("FtpInboundChannelAdapterParserTests-context.xml", this.getClass());
Map spcas = ac.getBeansOfType(SourcePollingChannelAdapter.class);
@@ -78,7 +91,8 @@ public class FtpInboundChannelAdapterParserTests {
assertNotNull(adapter);
}
- public static class TestSessionFactoryBean implements FactoryBean{
+
+ public static class TestSessionFactoryBean implements FactoryBean {
public DefaultFtpSessionFactory getObject() throws Exception {
DefaultFtpSessionFactory factory = mock(DefaultFtpSessionFactory.class);
@@ -94,6 +108,6 @@ public class FtpInboundChannelAdapterParserTests {
public boolean isSingleton() {
return true;
}
-
}
+
}
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 8349f253ae..0acdeb5166 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
@@ -19,6 +19,7 @@
+
+
diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests.java
index de16b0b5b2..79bc955f3a 100644
--- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests.java
+++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParserTests.java
@@ -59,10 +59,11 @@ public class FtpOutboundChannelAdapterParserTests {
assertEquals(ac.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "fileNameGenerator"));
assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "charset"));
assertNotNull(TestUtils.getPropertyValue(handler, "temporaryDirectory"));
- CachingSessionFactory cacheSf = (CachingSessionFactory) TestUtils.getPropertyValue(handler, "sessionFactory");
- DefaultFtpSessionFactory sf = (DefaultFtpSessionFactory) TestUtils.getPropertyValue(cacheSf, "sessionFactory");
- assertEquals("localhost", TestUtils.getPropertyValue(sf, "host"));
- assertEquals(22, TestUtils.getPropertyValue(sf, "port"));
+ Object sfProperty = TestUtils.getPropertyValue(handler, "sessionFactory");
+ assertEquals(DefaultFtpSessionFactory.class, sfProperty.getClass());
+ DefaultFtpSessionFactory sessionFactory = (DefaultFtpSessionFactory) sfProperty;
+ assertEquals("localhost", TestUtils.getPropertyValue(sessionFactory, "host"));
+ assertEquals(22, TestUtils.getPropertyValue(sessionFactory, "port"));
assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
//verify subscription order
@SuppressWarnings("unchecked")
@@ -74,4 +75,16 @@ public class FtpOutboundChannelAdapterParserTests {
assertSame(TestUtils.getPropertyValue(ac.getBean("ftpOutbound2"), "handler"), iterator.next());
assertSame(handler, iterator.next());
}
+
+ @Test
+ public void cachingByDefault() {
+ ApplicationContext ac = new ClassPathXmlApplicationContext(
+ "FtpOutboundChannelAdapterParserTests-context.xml", this.getClass());
+ Object adapter = ac.getBean("simpleAdapter");
+ Object sfProperty = TestUtils.getPropertyValue(adapter, "handler.sessionFactory");
+ assertEquals(CachingSessionFactory.class, sfProperty.getClass());
+ Object innerSfProperty = TestUtils.getPropertyValue(sfProperty, "sessionFactory");
+ assertEquals(DefaultFtpSessionFactory.class, innerSfProperty.getClass());
+ }
+
}
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 1a5884c983..2c242fdeea 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
@@ -31,7 +31,14 @@
+ ]]>
+
+
+
+
+
@@ -150,6 +157,13 @@ endpoint itself is a Polling Consumer for a channel with a queue.
+
+
+
+
+