From 86fafd00028c018676ec169c844638b4eb417ddd Mon Sep 17 00:00:00 2001 From: Josh Long Date: Sun, 12 Sep 2010 12:41:37 -0700 Subject: [PATCH] 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 @@ - +