INT-1664, INT-1665 added check for connection validity to recognize stale FTP connections, added 'throws IOException' to other relevant methods of Sessioin strategy, added debug statements to monitor session and session pool state, polished code

This commit is contained in:
Oleg Zhurakousky
2010-12-06 12:25:07 -05:00
parent 583b2771cd
commit 5f36b01024
5 changed files with 38 additions and 57 deletions

View File

@@ -162,7 +162,6 @@ public abstract class AbstractFtpSessionFactory<T extends FTPClient> implements
this.postProcessClientAfterConnect(client);
this.updateClientMode(client);
client.setFileType(fileType);
client.setBufferSize(bufferSize);
return client;

View File

@@ -48,35 +48,19 @@ class FtpSession implements Session {
}
public boolean remove(String path) {
public boolean remove(String path) throws IOException {
Assert.hasText(path, "path must not be null");
boolean completed = false;
try {
completed = this.client.deleteFile(path);
if (!completed){
throw new IOException("Failed to delete '" + path + "'. Server replied with: " + client.getReplyString());
}
}
catch (IOException e) {
if (logger.isWarnEnabled()) {
logger.warn("failed to delete file", e);
}
boolean completed = this.client.deleteFile(path);
if (!completed){
throw new IOException("Failed to delete '" + path + "'. Server replied with: " + client.getReplyString());
}
return completed;
}
@SuppressWarnings({"unchecked"})
public FTPFile[] list(String path) {
public FTPFile[] list(String path) throws IOException {
Assert.hasText(path, "path must not be null");
try {
return this.client.listFiles(path);
}
catch (IOException e) {
if (logger.isWarnEnabled()) {
logger.warn("failed to list files", e);
}
return new FTPFile[0];
}
return this.client.listFiles(path);
}
public void copy(String path, OutputStream fos) throws IOException{
@@ -111,6 +95,11 @@ class FtpSession implements Session {
}
public boolean isOpen() {
return this.client.isConnected();
try {
client.noop();
} catch (Exception e) {
return false;
}
return true;
}
}