From 86fafd00028c018676ec169c844638b4eb417ddd Mon Sep 17 00:00:00 2001 From: Josh Long Date: Sun, 12 Sep 2010 12:41:37 -0700 Subject: [PATCH 1/3] INT-1433 fixing some bugs in the SFTP adapter reported by John Norton. the problems were mainly inconsistant propagation of a javabean property through the xsd and namespace handler, and failure to close input/outputstreams in the sftps synchronizer. --- .../integration/sftp/config/SftpNamespaceHandler.java | 2 +- .../impl/SftpInboundRemoteFileSystemSynchronizer.java | 11 +++++++---- ...leSystemSynchronizingMessageSourceFactoryBean.java | 2 +- .../sftp/config/spring-integration-sftp-2.0.xsd | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java index 4e2cbe8960..60ee242b96 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/config/SftpNamespaceHandler.java @@ -68,7 +68,7 @@ public class SftpNamespaceHandler extends NamespaceHandlerSupport { IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "filter"); - for (String p : "filename-pattern,auto-create-directories,username,password,host,key-file,key-file-password,remote-directory,local-working-directory,auto-delete-remote-files-on-sync".split(",")) { + for (String p : "filename-pattern,auto-create-directories,username,password,host,key-file,key-file-password,remote-directory,local-directory-path,auto-delete-remote-files-on-sync".split(",")) { IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, p); } diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/impl/SftpInboundRemoteFileSystemSynchronizer.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/impl/SftpInboundRemoteFileSystemSynchronizer.java index e564c1bc27..f376ba4380 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/impl/SftpInboundRemoteFileSystemSynchronizer.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/impl/SftpInboundRemoteFileSystemSynchronizer.java @@ -73,17 +73,20 @@ public class SftpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemo String remoteFqPath = this.remotePath + "/" + entry.getFilename(); in = sftpSession.getChannel().get(remoteFqPath); - IOUtils.copy(in, fileOutputStream); + try { + IOUtils.copy(in, fileOutputStream); + } finally { + IOUtils.closeQuietly(in); + IOUtils.closeQuietly(fileOutputStream); + } if (tmpLocalTarget.renameTo(localFile)) { - // last step this.acknowledge(sftpSession, entry); } return true; } catch (Throwable th) { - IOUtils.closeQuietly(in); - IOUtils.closeQuietly(fileOutputStream); + logger.error("exception thrown in #copyFromRemoteToLocalDirectory", th); } } else { return true; diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/impl/SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/impl/SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java index e34844c1b5..89ef3414e3 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/impl/SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/impl/SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java @@ -127,7 +127,7 @@ public class SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean extends A sftpMsgSrc.setAutoCreateDirectories(autoCreatDirs); // local directories - if ((this.localDirectoryResource == null) || !StringUtils.hasText(this.localDirectoryPath)) { + if ((this.localDirectoryResource == null) && !StringUtils.hasText(this.localDirectoryPath)) { File tmp = SystemUtils.getJavaIoTmpDir(); File sftpTmp = new File(tmp, "sftpInbound"); this.localDirectoryPath = "file://" + sftpTmp.getAbsolutePath(); 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 766d933e91..9a6ca08ef9 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 @@ -107,7 +107,7 @@ - + From 6c959e601079d1e2794be4c61710d636183c2af0 Mon Sep 17 00:00:00 2001 From: Josh Long Date: Sun, 12 Sep 2010 13:06:01 -0700 Subject: [PATCH 2/3] fixing issues related to fileType not propagating in the ftp handler --- .../integration/ftp/ClientFactorySupport.java | 3 ++- .../ftp/FtpSendingMessageHandlerFactoryBean.java | 9 ++++++++- .../ftp/FtpsSendingMessageHandlerFactoryBean.java | 3 +++ .../src/test/resources/outbound-ftp-context.xml | 1 + .../src/test/resources/outbound-ftps-context.xml | 1 + 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/ClientFactorySupport.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/ClientFactorySupport.java index 6ba29e5e87..0140ded251 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/ClientFactorySupport.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/ClientFactorySupport.java @@ -71,7 +71,7 @@ public class ClientFactorySupport { return defaultFtpClientFactory; } - public static DefaultFtpClientFactory ftpClientFactory(String host, int port, String remoteDir, String user, String pw, int clientMode) { + public static DefaultFtpClientFactory ftpClientFactory(String host, int port, String remoteDir, String user, String pw, int clientMode, int fileType) { DefaultFtpClientFactory defaultFtpClientFactory = new DefaultFtpClientFactory(); defaultFtpClientFactory.setHost(host); defaultFtpClientFactory.setPassword(pw); @@ -79,6 +79,7 @@ public class ClientFactorySupport { defaultFtpClientFactory.setRemoteWorkingDirectory(remoteDir); defaultFtpClientFactory.setUsername(user); defaultFtpClientFactory.setClientMode(clientMode); + defaultFtpClientFactory.setFileType( fileType ); return defaultFtpClientFactory; } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandlerFactoryBean.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandlerFactoryBean.java index 26782253f5..603175e8b3 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandlerFactoryBean.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandlerFactoryBean.java @@ -23,6 +23,12 @@ public class FtpSendingMessageHandlerFactoryBean extends AbstractFactoryBean Date: Sun, 12 Sep 2010 14:14:31 -0700 Subject: [PATCH 3/3] fixed a compiler error. --- ...RemoteFileSystemSynchronizingMessageSourceFactoryBean.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java index 2713aee47b..91d8aee891 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java @@ -38,6 +38,7 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean extends Ab protected volatile int clientMode = FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE; protected volatile int fileType = FTP.BINARY_FILE_TYPE; + @SuppressWarnings("unused") public void setFileType(int fileType) { this.fileType = fileType; } @@ -61,7 +62,8 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean extends Ab } protected AbstractFtpClientFactory defaultClientFactory() throws Exception { - return ClientFactorySupport.ftpClientFactory( this.host , Integer.parseInt(this.port) , this.remoteDirectory , this.username ,this.password, this.clientMode ); + return ClientFactorySupport.ftpClientFactory( this.host , Integer.parseInt(this.port) , this.remoteDirectory , + this.username ,this.password, this.clientMode , this.fileType); } protected String defaultFtpInboundFolderName = "ftpInbound";