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.

This commit is contained in:
Josh Long
2010-09-12 12:41:37 -07:00
parent 0c247c3a84
commit 86fafd0002
4 changed files with 10 additions and 7 deletions

View File

@@ -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);
}

View File

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

View File

@@ -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();

View File

@@ -107,7 +107,7 @@
<xsd:attribute name="username" type="xsd:string" use="required"/>
<xsd:attribute name="remote-directory" type="xsd:string" use="required"/>
<xsd:attribute name="local-working-directory" type="xsd:string"/>
<xsd:attribute name="local-directory-path" type="xsd:string"/>
<xsd:attribute name="host" type="xsd:string" use="required"/>
<xsd:attribute name="password" type="xsd:string"/>