INT-1562 renamed SftpSessionFactory to SftpSessionFactoryBean since it implements FactoryBean, and refactored it to extend AbstractFactoryBean as well
This commit is contained in:
@@ -21,7 +21,7 @@ import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.integration.sftp.outbound.SftpSendingMessageHandler;
|
||||
import org.springframework.integration.sftp.session.QueuedSftpSessionPool;
|
||||
import org.springframework.integration.sftp.session.SftpSessionFactory;
|
||||
import org.springframework.integration.sftp.session.SftpSessionFactoryBean;
|
||||
import org.springframework.integration.sftp.session.SftpSessionUtils;
|
||||
|
||||
/**
|
||||
@@ -87,7 +87,7 @@ public class SftpMessageSendingConsumerFactoryBean implements FactoryBean<SftpSe
|
||||
}
|
||||
|
||||
public SftpSendingMessageHandler getObject() throws Exception {
|
||||
SftpSessionFactory sessionFactory = SftpSessionUtils.buildSftpSessionFactory(
|
||||
SftpSessionFactoryBean sessionFactory = SftpSessionUtils.buildSftpSessionFactory(
|
||||
this.host, this.password, this.username, this.keyFile, this.keyFilePassword, this.port);
|
||||
QueuedSftpSessionPool sessionPool = new QueuedSftpSessionPool(15, sessionFactory);
|
||||
sessionPool.afterPropertiesSet();
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.integration.sftp.filters.SftpPatternMatchingFileListF
|
||||
import org.springframework.integration.sftp.inbound.SftpInboundRemoteFileSystemSynchronizer;
|
||||
import org.springframework.integration.sftp.inbound.SftpInboundRemoteFileSystemSynchronizingMessageSource;
|
||||
import org.springframework.integration.sftp.session.QueuedSftpSessionPool;
|
||||
import org.springframework.integration.sftp.session.SftpSessionFactory;
|
||||
import org.springframework.integration.sftp.session.SftpSessionFactoryBean;
|
||||
import org.springframework.integration.sftp.session.SftpSessionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -183,7 +183,7 @@ public class SftpRemoteFileSystemSynchronizingMessageSourceFactoryBean
|
||||
this.filter = compositeFtpFileListFilter;
|
||||
|
||||
// pools
|
||||
SftpSessionFactory sessionFactory = SftpSessionUtils.buildSftpSessionFactory(this.host, this.password, this.username, this.keyFile, this.keyFilePassword, this.port);
|
||||
SftpSessionFactoryBean sessionFactory = SftpSessionUtils.buildSftpSessionFactory(this.host, this.password, this.username, this.keyFile, this.keyFilePassword, this.port);
|
||||
QueuedSftpSessionPool pool = new QueuedSftpSessionPool(15, sessionFactory);
|
||||
pool.afterPropertiesSet();
|
||||
|
||||
|
||||
@@ -37,16 +37,16 @@ public class QueuedSftpSessionPool implements SftpSessionPool, InitializingBean
|
||||
|
||||
private volatile Queue<SftpSession> queue;
|
||||
|
||||
private final SftpSessionFactory sftpSessionFactory;
|
||||
private final SftpSessionFactoryBean sftpSessionFactory;
|
||||
|
||||
private final int maxPoolSize;
|
||||
|
||||
|
||||
public QueuedSftpSessionPool(SftpSessionFactory factory) {
|
||||
public QueuedSftpSessionPool(SftpSessionFactoryBean factory) {
|
||||
this(DEFAULT_POOL_SIZE, factory);
|
||||
}
|
||||
|
||||
public QueuedSftpSessionPool(int maxPoolSize, SftpSessionFactory sessionFactory) {
|
||||
public QueuedSftpSessionPool(int maxPoolSize, SftpSessionFactoryBean sessionFactory) {
|
||||
this.sftpSessionFactory = sessionFactory;
|
||||
this.maxPoolSize = maxPoolSize;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.springframework.integration.sftp.session;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.config.AbstractFactoryBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -28,34 +27,41 @@ import org.springframework.util.StringUtils;
|
||||
* @author Josh Long
|
||||
* @author Mario Gray
|
||||
*/
|
||||
public class SftpSessionFactory implements FactoryBean<SftpSession>, InitializingBean {
|
||||
public class SftpSessionFactoryBean extends AbstractFactoryBean<SftpSession> {
|
||||
|
||||
private volatile String knownHosts;
|
||||
private volatile String remoteHost;
|
||||
|
||||
private volatile int port = 22; // the default
|
||||
|
||||
private volatile String user;
|
||||
|
||||
private volatile String password;
|
||||
|
||||
private volatile String knownHosts;
|
||||
|
||||
private volatile String privateKey;
|
||||
|
||||
private volatile String privateKeyPassphrase;
|
||||
|
||||
private volatile String remoteHost;
|
||||
|
||||
private volatile String user;
|
||||
public void setRemoteHost(String remoteHost) {
|
||||
this.remoteHost = remoteHost;
|
||||
}
|
||||
|
||||
private volatile int port = 22; // the default
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setKnownHosts(String knownHosts) {
|
||||
this.knownHosts = knownHosts;
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
public void setKnownHosts(String knownHosts) {
|
||||
this.knownHosts = knownHosts;
|
||||
}
|
||||
|
||||
public void setPrivateKey(String privateKey) {
|
||||
@@ -66,32 +72,25 @@ public class SftpSessionFactory implements FactoryBean<SftpSession>, Initializin
|
||||
this.privateKeyPassphrase = privateKeyPassphrase;
|
||||
}
|
||||
|
||||
public void setRemoteHost(String remoteHost) {
|
||||
this.remoteHost = remoteHost;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.hasText(this.remoteHost, "remoteHost must not be empty");
|
||||
Assert.hasText(this.user, "user mut not be empty");
|
||||
Assert.state(StringUtils.hasText(this.password) || StringUtils.hasText(this.privateKey) || StringUtils.hasText(this.privateKeyPassphrase),
|
||||
"either a password or a private key and/or a private key passphrase is required");
|
||||
Assert.state(this.port >= 0, "port must be a positive number");
|
||||
}
|
||||
|
||||
public SftpSession getObject() throws Exception {
|
||||
return new SftpSession(this.user, this.remoteHost, this.password, this.port, this.knownHosts, null, this.privateKey, this.privateKeyPassphrase);
|
||||
}
|
||||
|
||||
public Class<? extends SftpSession> getObjectType() {
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return SftpSession.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SftpSession createInstance() throws Exception {
|
||||
Assert.hasText(this.remoteHost, "remoteHost 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) || StringUtils.hasText(this.privateKey) || StringUtils.hasText(this.privateKeyPassphrase),
|
||||
"either a password or a private key and/or a private key passphrase is required");
|
||||
return new SftpSession(this.user, this.remoteHost, this.password, this.port, this.knownHosts, null, this.privateKey, this.privateKeyPassphrase);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,8 +39,8 @@ public abstract class SftpSessionUtils {
|
||||
* commands against a remote SFTP/SSH filesystem
|
||||
* @throws Exception thrown in case of darned near <em>anything</em>
|
||||
*/
|
||||
public static SftpSessionFactory buildSftpSessionFactory(String host, String pw, String usr, String pvKey, String pvKeyPass, int port) throws Exception {
|
||||
SftpSessionFactory sftpSessionFactory = new SftpSessionFactory();
|
||||
public static SftpSessionFactoryBean buildSftpSessionFactory(String host, String pw, String usr, String pvKey, String pvKeyPass, int port) throws Exception {
|
||||
SftpSessionFactoryBean sftpSessionFactory = new SftpSessionFactoryBean();
|
||||
sftpSessionFactory.setPassword(pw);
|
||||
sftpSessionFactory.setPort(port);
|
||||
sftpSessionFactory.setRemoteHost(host);
|
||||
|
||||
Reference in New Issue
Block a user