INT-2494 Move listNames() Method to Session

ExtendedSession, with the listNames() method was introduced
in 2.1.1 (INT-2492) to support mget commands on the gateway.

This was to avoid breaking any user implementations of Session
in a point release. However, we documented this was temporary
and the interfaces would be consolidated in 2.2., and
ExtendedSession would be removed.

This is that consolidation.
This commit is contained in:
Gary Russell
2012-04-06 16:35:17 -04:00
parent 1ba24f7bb6
commit 00a71eefd2
8 changed files with 26 additions and 79 deletions

View File

@@ -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<F> extends AbstractReply
protected List<File> mGet(Session<F> session, String remoteDirectory,
String remoteFilename) throws IOException {
Assert.isInstanceOf(ExtendedSession.class, session, "mget failed - ");
String path = fixPath(remoteDirectory, remoteFilename);
String[] fileNames = ((ExtendedSession<F>) 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);

View File

@@ -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<F> implements SessionFactory<F>, DisposableBe
}
private class CachedSession implements ExtendedSession<F> {
private class CachedSession implements Session<F> {
private final Session<F> targetSession;
@@ -166,8 +165,7 @@ public class CachingSessionFactory<F> implements SessionFactory<F>, DisposableBe
}
public String[] listNames(String path) throws IOException {
Assert.isInstanceOf(ExtendedSession.class, this.targetSession, "mget failed - ");
return ((ExtendedSession<F>) this.targetSession).listNames(path);
return this.targetSession.listNames(path);
}
}

View File

@@ -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;
/**
* <b>Temporary extension</b> to {@link Session} to avoid a breaking change
* in a point release - merge with Session in 2.2.
* <p>
* <b>**NOTE**</b> This interface will be <b>removed</b> (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.
* <p>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<T> extends Session<T> {
/**
* 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;
}

View File

@@ -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<T> {
@@ -48,4 +49,7 @@ public interface Session<T> {
boolean isOpen();
boolean exists(String path) throws IOException;
String[] listNames(String path) throws IOException;
}

View File

@@ -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<String>("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<File> out = (Message<File>) gw.handleRequestMessage(new GenericMessage<String>("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<File> out = (Message<File>) gw.handleRequestMessage(new GenericMessage<String>("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<String>("f1"));
File out = new File(this.tmpDir + "/x/f1");

View File

@@ -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

View File

@@ -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<FTPFile> {
public class FtpSession implements Session<FTPFile> {
private final Log logger = LogFactory.getLog(this.getClass());

View File

@@ -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<LsEntry> {
class SftpSession implements Session<LsEntry> {
private final Log logger = LogFactory.getLog(this.getClass());