diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java index d9d3b56dcb..1e8e6c63de 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java @@ -35,7 +35,6 @@ import org.springframework.integration.MessagingException; import org.springframework.integration.file.FileHeaders; import org.springframework.integration.file.filters.FileListFilter; import org.springframework.integration.file.remote.AbstractFileInfo; -import org.springframework.integration.file.remote.session.ExtendedSession; import org.springframework.integration.file.remote.session.Session; import org.springframework.integration.file.remote.session.SessionFactory; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; @@ -377,9 +376,11 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply protected List mGet(Session session, String remoteDirectory, String remoteFilename) throws IOException { - Assert.isInstanceOf(ExtendedSession.class, session, "mget failed - "); String path = fixPath(remoteDirectory, remoteFilename); - String[] fileNames = ((ExtendedSession) session).listNames(path); + String[] fileNames = session.listNames(path); + if (fileNames == null) { + fileNames = new String[0]; + } if (fileNames.length == 0 && this.options.contains(OPTION_EXCEPTION_WHEN_EMPTY)) { throw new MessagingException("No files found at " + remoteDirectory + " with pattern " + remoteFilename); diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java index 2b24610a00..d5a1664c57 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/CachingSessionFactory.java @@ -25,7 +25,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.DisposableBean; import org.springframework.integration.util.UpperBound; -import org.springframework.util.Assert; /** * A {@link SessionFactory} implementation that caches Sessions for reuse without @@ -117,7 +116,7 @@ public class CachingSessionFactory implements SessionFactory, DisposableBe } - private class CachedSession implements ExtendedSession { + private class CachedSession implements Session { private final Session targetSession; @@ -166,8 +165,7 @@ public class CachingSessionFactory implements SessionFactory, DisposableBe } public String[] listNames(String path) throws IOException { - Assert.isInstanceOf(ExtendedSession.class, this.targetSession, "mget failed - "); - return ((ExtendedSession) this.targetSession).listNames(path); + return this.targetSession.listNames(path); } } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/ExtendedSession.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/ExtendedSession.java deleted file mode 100644 index efe8cdb27a..0000000000 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/ExtendedSession.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2002-2012 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.file.remote.session; - -import java.io.IOException; - -/** - * Temporary extension to {@link Session} to avoid a breaking change - * in a point release - merge with Session in 2.2. - *

- * **NOTE** This interface will be removed (not deprecated) in 2.2. - * It exists purely to avoid existing user implementations of Session from - * failing to compile if we had added the new method to that interface. - *

Any user implementations of ExtendedSession will need to be refactored to - * implement Session in 2.2. - * @author Gary Russell - * @since 2.1.1 - * - */ -public interface ExtendedSession extends Session { - - /** - * Returns an array of Strings containing just the names of - * the remote files at path. Will move to {@link Session} - * in 2.2. - * @param path The path - * @return The list of names - * @throws IOException - */ - String[] listNames(String path) throws IOException; -} diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/Session.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/Session.java index a6a6cd6eb9..4a5c325002 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/Session.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/session/Session.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -27,6 +27,7 @@ import java.io.OutputStream; * @author Mario Gray * @author Mark Fisher * @author Oleg Zhurakousky + * @author Gary Russell * @since 2.0 */ public interface Session { @@ -48,4 +49,7 @@ public interface Session { boolean isOpen(); boolean exists(String path) throws IOException; + + String[] listNames(String path) throws IOException; + } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java index 9f1462a993..d52c8972f0 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java @@ -38,7 +38,6 @@ import org.springframework.integration.MessagingException; import org.springframework.integration.file.FileHeaders; import org.springframework.integration.file.filters.AbstractSimplePatternFileListFilter; import org.springframework.integration.file.remote.AbstractFileInfo; -import org.springframework.integration.file.remote.session.ExtendedSession; import org.springframework.integration.file.remote.session.Session; import org.springframework.integration.file.remote.session.SessionFactory; import org.springframework.integration.message.GenericMessage; @@ -82,18 +81,6 @@ public class RemoteFileOutboundGatewayTests { out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY)); } - @Test(expected=IllegalArgumentException.class) - public void testMGetSession() throws Exception { - SessionFactory sessionFactory = mock(SessionFactory.class); - Session session = mock(Session.class); - TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway - (sessionFactory, "mget", "payload"); - when(sessionFactory.getSession()).thenReturn(session); - gw.setLocalDirectory(new File(this.tmpDir )); - gw.afterPropertiesSet(); - gw.handleRequestMessage(new GenericMessage("testremote/*")); - } - @Test public void testMGetWild() throws Exception { SessionFactory sessionFactory = mock(SessionFactory.class); @@ -103,7 +90,7 @@ public class RemoteFileOutboundGatewayTests { gw.afterPropertiesSet(); new File(this.tmpDir + "/f1").delete(); new File(this.tmpDir + "/f2").delete(); - when(sessionFactory.getSession()).thenReturn(new ExtendedSession() { + when(sessionFactory.getSession()).thenReturn(new Session() { public boolean remove(String path) throws IOException { return false; } @@ -153,7 +140,7 @@ public class RemoteFileOutboundGatewayTests { gw.setLocalDirectory(new File(this.tmpDir )); gw.afterPropertiesSet(); new File(this.tmpDir + "/f1").delete(); - when(sessionFactory.getSession()).thenReturn(new ExtendedSession() { + when(sessionFactory.getSession()).thenReturn(new Session() { public boolean remove(String path) throws IOException { return false; } @@ -204,7 +191,7 @@ public class RemoteFileOutboundGatewayTests { gw.afterPropertiesSet(); new File(this.tmpDir + "/f1").delete(); new File(this.tmpDir + "/f2").delete(); - when(sessionFactory.getSession()).thenReturn(new ExtendedSession() { + when(sessionFactory.getSession()).thenReturn(new Session() { public boolean remove(String path) throws IOException { return false; } @@ -416,7 +403,6 @@ public class RemoteFileOutboundGatewayTests { public boolean remove(String path) throws IOException { return false; } - public TestLsEntry[] list(String path) throws IOException { return new TestLsEntry[] { new TestLsEntry("f1", 1234, false, false, 12345, "-rw-r--r--") @@ -441,10 +427,12 @@ public class RemoteFileOutboundGatewayTests { public boolean isOpen() { return open; } - public boolean exists(String path) throws IOException { return true; } + public String[] listNames(String path) throws IOException { + return null; + } }); @SuppressWarnings("unchecked") Message out = (Message) gw.handleRequestMessage(new GenericMessage("f1")); @@ -475,7 +463,6 @@ public class RemoteFileOutboundGatewayTests { public boolean remove(String path) throws IOException { return false; } - public TestLsEntry[] list(String path) throws IOException { return new TestLsEntry[] { new TestLsEntry("f1", 1234, false, false, modified.getTime(), "-rw-r--r--") @@ -503,6 +490,9 @@ public class RemoteFileOutboundGatewayTests { public boolean exists(String path) throws IOException { return true; } + public String[] listNames(String path) throws IOException { + return null; + } }); @SuppressWarnings("unchecked") Message out = (Message) gw.handleRequestMessage(new GenericMessage("x/f1")); @@ -531,7 +521,6 @@ public class RemoteFileOutboundGatewayTests { public boolean remove(String path) throws IOException { return false; } - public TestLsEntry[] list(String path) throws IOException { return new TestLsEntry[] { new TestLsEntry("f1", 1234, false, false, 12345, "-rw-r--r--") @@ -559,6 +548,9 @@ public class RemoteFileOutboundGatewayTests { public boolean exists(String path) throws IOException { return true; } + public String[] listNames(String path) throws IOException { + return null; + } }); gw.handleRequestMessage(new GenericMessage("f1")); File out = new File(this.tmpDir + "/x/f1"); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java index 7337026b63..02ce576872 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/handler/FileTransferringMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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,7 +36,6 @@ import org.springframework.integration.file.remote.session.Session; import org.springframework.integration.file.remote.session.SessionFactory; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.support.MessageBuilder; -import org.springframework.test.annotation.ExpectedException; /** * @author Oleg Zhurakousky diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/FtpSession.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/FtpSession.java index 7fb3e06061..470d1116ca 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/FtpSession.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/session/FtpSession.java @@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; -import org.springframework.integration.file.remote.session.ExtendedSession; import org.springframework.integration.file.remote.session.Session; import org.springframework.util.Assert; @@ -36,7 +35,7 @@ import org.springframework.util.Assert; * @author Gary Russell * @since 2.0 */ -public class FtpSession implements ExtendedSession { +public class FtpSession implements Session { private final Log logger = LogFactory.getLog(this.getClass()); diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java index 4ea7198a81..96cdb9bf12 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java @@ -25,9 +25,7 @@ import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.core.NestedIOException; -import org.springframework.integration.file.remote.session.ExtendedSession; import org.springframework.integration.file.remote.session.Session; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; @@ -48,7 +46,7 @@ import com.jcraft.jsch.SftpException; * @author Gary Russell * @since 2.0 */ -class SftpSession implements ExtendedSession { +class SftpSession implements Session { private final Log logger = LogFactory.getLog(this.getClass());