INT-1614 polishing SFTP module
This commit is contained in:
@@ -34,4 +34,5 @@ public class SftpNamespaceHandler extends AbstractIntegrationNamespaceHandler {
|
||||
registerBeanDefinitionParser("inbound-channel-adapter", new SftpInboundChannelAdapterParser());
|
||||
registerBeanDefinitionParser("outbound-channel-adapter", new RemoteFileOutboundChannelAdapterParser());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
|
||||
/**
|
||||
* Implementation of {@link AbstractRegexPatternFileListFilter} for SFTP.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
|
||||
@@ -22,6 +22,8 @@ import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
|
||||
/**
|
||||
* Implementation of {@link AbstractSimplePatternFileListFilter} for SFTP.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,8 @@ import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
|
||||
/**
|
||||
* a {@link org.springframework.integration.core.MessageSource} implementation for SFTP
|
||||
* A {@link org.springframework.integration.core.MessageSource} implementation for SFTP
|
||||
* that delegates to an InboundFileSynchronizer.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @author Oleg Zhurakousky
|
||||
|
||||
@@ -47,7 +47,7 @@ public class DefaultSftpSessionFactory implements SessionFactory {
|
||||
private volatile Resource privateKey;
|
||||
|
||||
private volatile String privateKeyPassphrase;
|
||||
|
||||
|
||||
private final JSch jsch = new JSch();
|
||||
|
||||
|
||||
@@ -83,8 +83,8 @@ public class DefaultSftpSessionFactory implements SessionFactory {
|
||||
Assert.hasText(this.host, "host must not be empty");
|
||||
Assert.hasText(this.user, "user must not be empty");
|
||||
Assert.isTrue(this.port >= 0, "port must be a positive number");
|
||||
Assert.isTrue(StringUtils.hasText(this.password) || privateKey != null || StringUtils.hasText(this.privateKeyPassphrase),
|
||||
"either a password or a private key and/or a private key passphrase is required");
|
||||
Assert.isTrue(StringUtils.hasText(this.password) || this.privateKey != null,
|
||||
"either a password or a private key is required");
|
||||
try {
|
||||
com.jcraft.jsch.Session jschSession = this.initJschSession();
|
||||
SftpSession sftpSession = new SftpSession(jschSession);
|
||||
@@ -124,8 +124,9 @@ public class DefaultSftpSessionFactory implements SessionFactory {
|
||||
|
||||
|
||||
/**
|
||||
* this is a simple, optimistic implementation of this interface. It simply returns in the positive where possible
|
||||
* and handles interactive authentication (i.e. 'Please enter your password: ' prompts are dispatched automatically using this)
|
||||
* this is a simple, optimistic implementation of the UserInfo interface.
|
||||
* It returns in the positive where possible and handles interactive authentication
|
||||
* (i.e. 'Please enter your password: ' prompts are dispatched automatically).
|
||||
*/
|
||||
private static class OptimisticUserInfoImpl implements UserInfo {
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import com.jcraft.jsch.JSchException;
|
||||
import com.jcraft.jsch.SftpException;
|
||||
|
||||
/**
|
||||
* Default SftpSession implementation.
|
||||
* Default SFTP {@link Session} implementation. Wraps a JSCH session instance.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @author Mario Gray
|
||||
@@ -48,14 +48,15 @@ class SftpSession implements Session {
|
||||
|
||||
|
||||
public SftpSession(com.jcraft.jsch.Session jschSession) {
|
||||
Assert.notNull(jschSession, "jschSession must not be null");
|
||||
this.jschSession = jschSession;
|
||||
}
|
||||
|
||||
|
||||
public boolean rm(String path) {
|
||||
Assert.state(channel != null, "session is not connected");
|
||||
Assert.state(this.channel != null, "session is not connected");
|
||||
try {
|
||||
channel.rm(path);
|
||||
this.channel.rm(path);
|
||||
return true;
|
||||
}
|
||||
catch (SftpException e) {
|
||||
@@ -68,9 +69,9 @@ class SftpSession implements Session {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public LsEntry[] ls(String path) {
|
||||
Assert.state(channel != null, "session is not connected");
|
||||
Assert.state(this.channel != null, "session is not connected");
|
||||
try {
|
||||
Vector<?> lsEntries = channel.ls(path);
|
||||
Vector<?> lsEntries = this.channel.ls(path);
|
||||
if (lsEntries != null) {
|
||||
LsEntry[] entries = new LsEntry[lsEntries.size()];
|
||||
for (int i = 0; i < lsEntries.size(); i++) {
|
||||
@@ -90,9 +91,9 @@ class SftpSession implements Session {
|
||||
}
|
||||
|
||||
public InputStream get(String source) {
|
||||
Assert.state(channel != null, "session is not connected");
|
||||
Assert.state(this.channel != null, "session is not connected");
|
||||
try {
|
||||
return channel.get(source);
|
||||
return this.channel.get(source);
|
||||
}
|
||||
catch (SftpException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
@@ -103,9 +104,9 @@ class SftpSession implements Session {
|
||||
}
|
||||
|
||||
public void put(InputStream inputStream, String destination) {
|
||||
Assert.state(channel != null, "session is not connected");
|
||||
Assert.state(this.channel != null, "session is not connected");
|
||||
try {
|
||||
channel.put(inputStream, destination);
|
||||
this.channel.put(inputStream, destination);
|
||||
}
|
||||
catch (SftpException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
@@ -115,8 +116,8 @@ class SftpSession implements Session {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (jschSession.isConnected()) {
|
||||
jschSession.disconnect();
|
||||
if (this.jschSession.isConnected()) {
|
||||
this.jschSession.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user