I can be so forgetful sometimes! I've just changed *SFTP* -> *Sftp*. Looks *much* better now and feels more like the Spring I know and love.

This commit is contained in:
Josh Long
2010-08-18 05:45:09 +00:00
parent a3ad837468
commit 9f3f0a91bf
18 changed files with 109 additions and 125 deletions

View File

@@ -26,7 +26,7 @@ import java.util.List;
*
* @author Josh Long
*/
public abstract class AbstractSFTPFileListFilter implements SFTPFileListFilter {
public abstract class AbstractSftpFileListFilter implements SftpFileListFilter {
abstract public boolean accept(ChannelSftp.LsEntry lsEntry);

View File

@@ -26,18 +26,18 @@ import java.util.*;
*
* @author Josh Long
*/
public class CompositeFTPFileListFilter implements SFTPFileListFilter {
private Set<SFTPFileListFilter> filters;
public class CompositeFtpFileListFilter implements SftpFileListFilter {
private Set<SftpFileListFilter> filters;
public CompositeFTPFileListFilter(SFTPFileListFilter... ftpFileListFilter) {
this.filters = new LinkedHashSet<SFTPFileListFilter>(Arrays.asList(ftpFileListFilter));
public CompositeFtpFileListFilter(SftpFileListFilter... ftpFileListFilter) {
this.filters = new LinkedHashSet<SftpFileListFilter>(Arrays.asList(ftpFileListFilter));
}
public CompositeFTPFileListFilter(Collection<SFTPFileListFilter> ftpFileListFilter) {
this.filters = new LinkedHashSet<SFTPFileListFilter>(ftpFileListFilter);
public CompositeFtpFileListFilter(Collection<SftpFileListFilter> ftpFileListFilter) {
this.filters = new LinkedHashSet<SftpFileListFilter>(ftpFileListFilter);
}
public void addFilter(SFTPFileListFilter ftpFileListFilter) {
public void addFilter(SftpFileListFilter ftpFileListFilter) {
this.filters.add(ftpFileListFilter);
}
@@ -46,7 +46,7 @@ public class CompositeFTPFileListFilter implements SFTPFileListFilter {
List<ChannelSftp.LsEntry> leftOver = Arrays.asList(files);
for (SFTPFileListFilter ff : this.filters)
for (SftpFileListFilter ff : this.filters)
leftOver = ff.filterFiles(leftOver.toArray(new ChannelSftp.LsEntry[leftOver.size()]));
return leftOver;

View File

@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
*
* @author Josh Long
*/
public class PatternMatchingSFTPFileListFilter extends AbstractSFTPFileListFilter implements InitializingBean {
public class PatternMatchingSftpFileListFilter extends AbstractSftpFileListFilter implements InitializingBean {
private Log logger = LogFactory.getLog(getClass());

View File

@@ -23,36 +23,36 @@ import java.util.concurrent.ArrayBlockingQueue;
/**
* This approach - of having a SessionPool ({@link org.springframework.integration.sftp.SFTPSessionPool}) that has an
* implementation of Queued*SessionPool ({@link org.springframework.integration.sftp.QueuedSFTPSessionPool}) - was
* This approach - of having a SessionPool ({@link SftpSessionPool}) that has an
* implementation of Queued*SessionPool ({@link QueuedSftpSessionPool}) - was
* taken pretty directly from the incredibly good Spring IntegrationFTP adapter.
*
* @author Josh Long
* @since 2.0
*/
public class QueuedSFTPSessionPool implements SFTPSessionPool, InitializingBean {
public class QueuedSftpSessionPool implements SftpSessionPool, InitializingBean {
public static final int DEFAULT_POOL_SIZE = 10;
private Queue<SFTPSession> queue;
private final SFTPSessionFactory sftpSessionFactory;
private Queue<SftpSession> queue;
private final SftpSessionFactory sftpSessionFactory;
private int maxPoolSize;
public QueuedSFTPSessionPool(SFTPSessionFactory factory) {
public QueuedSftpSessionPool(SftpSessionFactory factory) {
this(DEFAULT_POOL_SIZE, factory);
}
public QueuedSFTPSessionPool(int maxPoolSize, SFTPSessionFactory sessionFactory) {
public QueuedSftpSessionPool(int maxPoolSize, SftpSessionFactory sessionFactory) {
this.sftpSessionFactory = sessionFactory;
this.maxPoolSize = maxPoolSize;
}
public void afterPropertiesSet() throws Exception {
assert maxPoolSize > 0 : "poolSize must be greater than 0!";
queue = new ArrayBlockingQueue<SFTPSession>(maxPoolSize, true); // size, faireness to avoid starvation
queue = new ArrayBlockingQueue<SftpSession>(maxPoolSize, true); // size, faireness to avoid starvation
assert sftpSessionFactory != null : "sftpSessionFactory must not be null!";
}
public SFTPSession getSession() throws Exception {
SFTPSession session = this.queue.poll();
public SftpSession getSession() throws Exception {
SftpSession session = this.queue.poll();
if (null == session) {
session = this.sftpSessionFactory.getObject();
@@ -69,7 +69,7 @@ public class QueuedSFTPSessionPool implements SFTPSessionPool, InitializingBean
return session;
}
public void release(SFTPSession session) {
public void release(SftpSession session) {
if (queue.size() < maxPoolSize) {
queue.add(session); // somehow one snuck in before <code>session</code> was finished!
} else {
@@ -77,7 +77,7 @@ public class QueuedSFTPSessionPool implements SFTPSessionPool, InitializingBean
}
}
private void dispose(SFTPSession s) {
private void dispose(SftpSession s) {
if (s == null) {
return;
}

View File

@@ -20,6 +20,6 @@ package org.springframework.integration.sftp;
/**
* @author Josh Long
*/
public class SFTPConstants {
public class SftpConstants {
public static final String SFTP_REMOTE_DIRECTORY_HEADER = "SFTP_REMOTE_DIRECTORY_HEADER";
}
}

View File

@@ -25,6 +25,6 @@ import java.util.List;
*
* @author Josh Long
*/
public interface SFTPFileListFilter {
public interface SftpFileListFilter {
List<ChannelSftp.LsEntry> filterFiles (ChannelSftp.LsEntry [] files);
}

View File

@@ -45,29 +45,29 @@ import java.util.concurrent.ScheduledFuture;
* @author Josh Long
* @author Mario Gray
*/
public class SFTPInboundSynchronizer implements InitializingBean {
public class SftpInboundSynchronizer implements InitializingBean {
private static final long DEFAULT_REFRESH_RATE = 10 * 1000; // 10 seconds
// a lot of the approach for this (including the use of a FileReadingMessageSource and the regex / mask approach were lifted from FtpInboundSynchronizer
static final String INCOMPLETE_EXTENSION = ".INCOMPLETE";
private Log logger = LogFactory.getLog(getClass());
private volatile Resource localDirectory;
private volatile SFTPSessionPool pool;
private volatile SftpSessionPool pool;
private volatile ScheduledFuture<?> scheduledFuture;
private volatile String remotePath;
private volatile TaskScheduler taskScheduler;
private volatile Trigger trigger = new PeriodicTrigger(DEFAULT_REFRESH_RATE);
private volatile boolean autoCreatePath;
private volatile boolean running;
private SFTPFileListFilter filter;
private SftpFileListFilter filter;
public void setFilter(SFTPFileListFilter filter) {
public void setFilter(SftpFileListFilter filter) {
this.filter = filter;
}
private volatile boolean shouldDeleteDownloadedRemoteFiles; //.. this is false
private SFTPFileListFilter acceptAllFilteListFilter = new SFTPFileListFilter(){
private SftpFileListFilter acceptAllFilteListFilter = new SftpFileListFilter(){
public List<ChannelSftp.LsEntry> filterFiles(ChannelSftp.LsEntry[] files) {
return Arrays.asList( files);
}
@@ -108,7 +108,7 @@ public class SFTPInboundSynchronizer implements InitializingBean {
this.localDirectory = localDirectory;
}
public void setPool(SFTPSessionPool pool) {
public void setPool(SftpSessionPool pool) {
this.pool = pool;
}
@@ -157,7 +157,7 @@ public class SFTPInboundSynchronizer implements InitializingBean {
@SuppressWarnings("unchecked")
public void synchronize() throws Exception {
SFTPSession session = null;
SftpSession session = null;
try {
session = pool.getSession();
@@ -193,7 +193,7 @@ public class SFTPInboundSynchronizer implements InitializingBean {
* existed.)
*/
private boolean checkThatRemotePathExists(String remotePath) {
SFTPSession session = null;
SftpSession session = null;
ChannelSftp channelSftp = null;
try {
@@ -230,7 +230,7 @@ public class SFTPInboundSynchronizer implements InitializingBean {
}
@SuppressWarnings("ignored")
private boolean copyFromRemoteToLocalDirectory(SFTPSession sftpSession, ChannelSftp.LsEntry entry, Resource localDir)
private boolean copyFromRemoteToLocalDirectory(SftpSession sftpSession, ChannelSftp.LsEntry entry, Resource localDir)
throws Exception {
File fileForLocalDir = localDir.getFile();

View File

@@ -17,23 +17,18 @@
package org.springframework.integration.sftp;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.Lifecycle;
import org.springframework.core.io.Resource;
import org.springframework.integration.Message;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.file.AcceptOnceFileListFilter;
import org.springframework.integration.file.CompositeFileListFilter;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.integration.file.PatternMatchingFileListFilter;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.Trigger;
import java.io.File;
import java.io.IOException;
import java.util.regex.Pattern;
@@ -45,18 +40,18 @@ import java.util.regex.Pattern;
*
* @author Josh Long
*/
public class SFTPMessageSource implements MessageSource<File>, InitializingBean, Lifecycle {
public class SftpMessageSource implements MessageSource<File>, InitializingBean, Lifecycle {
private FileReadingMessageSource fileReadingMessageSource;
private Resource localDirectory;
private SFTPInboundSynchronizer synchronizer;
private SftpInboundSynchronizer synchronizer;
private TaskScheduler taskScheduler;
private Trigger trigger;
public SFTPMessageSource(FileReadingMessageSource fileSource, SFTPInboundSynchronizer synchronizer) {
public SftpMessageSource(FileReadingMessageSource fileSource, SftpInboundSynchronizer synchronizer) {
this.fileReadingMessageSource = fileSource;
this.synchronizer = synchronizer;
Pattern completePattern = Pattern.compile("^.*(?<!" + SFTPInboundSynchronizer.INCOMPLETE_EXTENSION + ")$");
Pattern completePattern = Pattern.compile("^.*(?<!" + SftpInboundSynchronizer.INCOMPLETE_EXTENSION + ")$");
fileReadingMessageSource.setFilter(new CompositeFileListFilter(new AcceptOnceFileListFilter(), new PatternMatchingFileListFilter(completePattern)));
}
@@ -73,7 +68,7 @@ public class SFTPMessageSource implements MessageSource<File>, InitializingBean,
return localDirectory;
}
public SFTPInboundSynchronizer getSynchronizer() {
public SftpInboundSynchronizer getSynchronizer() {
return synchronizer;
}
@@ -107,7 +102,7 @@ public class SFTPMessageSource implements MessageSource<File>, InitializingBean,
this.synchronizer.setLocalDirectory(localDirectory);
}
public void setSynchronizer(final SFTPInboundSynchronizer synchronizer) {
public void setSynchronizer(final SftpInboundSynchronizer synchronizer) {
this.synchronizer = synchronizer;
}
@@ -128,4 +123,4 @@ public class SFTPMessageSource implements MessageSource<File>, InitializingBean,
public void stop() {
synchronizer.stop();
}
}
}

View File

@@ -17,12 +17,9 @@
package org.springframework.integration.sftp;
import com.jcraft.jsch.ChannelSftp;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.*;
import org.springframework.integration.core.MessageHandler;
@@ -38,19 +35,19 @@ import java.io.InputStream;
*
* @author Josh Long
*/
public class SFTPSendingMessageHandler implements MessageHandler, InitializingBean {
private SFTPSessionPool pool;
public class SftpSendingMessageHandler implements MessageHandler, InitializingBean {
private SftpSessionPool pool;
private String remoteDirectory;
private volatile boolean afterPropertiesSetRan;
public SFTPSendingMessageHandler(SFTPSessionPool pool) {
public SftpSendingMessageHandler(SftpSessionPool pool) {
this.pool = pool;
}
public void afterPropertiesSet() throws Exception {
assert this.pool != null : "the pool can't be null!";
// logger.debug("afterPropertiesSet() called on SFTPSendingMessageHandler");
// logger.debug("afterPropertiesSet() called on SftpSendingMessageHandler");
if (!afterPropertiesSetRan) {
if (StringUtils.isEmpty(this.remoteDirectory)) {
remoteDirectory = null;
@@ -89,7 +86,7 @@ public class SFTPSendingMessageHandler implements MessageHandler, InitializingBe
throws Throwable {
assert this.pool != null : "need a working pool";
SFTPSession session = this.pool.getSession();
SftpSession session = this.pool.getSession();
if (session == null) {
throw new RuntimeException("the session returned from the pool is null, can't possibly proceed.");
@@ -113,8 +110,8 @@ public class SFTPSendingMessageHandler implements MessageHandler, InitializingBe
if (message != null) {
messageHeaders = message.getHeaders();
if ((messageHeaders != null) && messageHeaders.containsKey(SFTPConstants.SFTP_REMOTE_DIRECTORY_HEADER)) {
dynRd = (String) messageHeaders.get(SFTPConstants.SFTP_REMOTE_DIRECTORY_HEADER);
if ((messageHeaders != null) && messageHeaders.containsKey(SftpConstants.SFTP_REMOTE_DIRECTORY_HEADER)) {
dynRd = (String) messageHeaders.get(SftpConstants.SFTP_REMOTE_DIRECTORY_HEADER);
if (!StringUtils.isEmpty(dynRd)) {
baseOfRemotePath = dynRd;

View File

@@ -20,15 +20,13 @@ import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.UserInfo;
import org.apache.commons.lang.StringUtils;
import java.io.InputStream;
/**
* There are many ways to create a {@link org.springframework.integration.sftp.SFTPSession} just as there are many ways to SSH into a remote system.
* There are many ways to create a {@link SftpSession} just as there are many ways to SSH into a remote system.
* You may use a username and password, you may use a username and private key, you may use a username and a private key with a password, etc.
*
* This object represents the connection to the remote server, and to use it you must provide it with all the components you'd normally provide an
@@ -38,7 +36,7 @@ import java.io.InputStream;
* @author Josh Long
* @author Mario Gray
*/
public class SFTPSession {
public class SftpSession {
private volatile ChannelSftp channel;
private volatile Session session;
private String privateKey;
@@ -70,7 +68,7 @@ public class SFTPSession {
*
* @throws Exception thrown if any of a myriad of scenarios plays out
*/
public SFTPSession(String userName, String hostName, String userPassword, int port, String knownHostsFile, InputStream knownHostsInputStream, String privateKey, String pvKeyPassPhrase)
public SftpSession(String userName, String hostName, String userPassword, int port, String knownHostsFile, InputStream knownHostsInputStream, String privateKey, String pvKeyPassPhrase)
throws Exception {
JSch jSch = new JSch();
@@ -156,4 +154,4 @@ public class SFTPSession {
public void showMessage(String string) {
}
}
}
}

View File

@@ -22,14 +22,14 @@ import org.springframework.util.StringUtils;
/**
* Factories {@link org.springframework.integration.sftp.SFTPSession} instances. There are lots of ways to construct a
* {@link org.springframework.integration.sftp.SFTPSession} instance, and not all of them are obvious. This factory
* Factories {@link SftpSession} instances. There are lots of ways to construct a
* {@link SftpSession} instance, and not all of them are obvious. This factory
* does its best to make it work.
*
* @author Josh Long
* @author Mario Gray
*/
public class SFTPSessionFactory implements FactoryBean<SFTPSession>, InitializingBean {
public class SftpSessionFactory implements FactoryBean<SftpSession>, InitializingBean {
private volatile String knownHosts;
private volatile String password;
private volatile String privateKey;
@@ -46,12 +46,12 @@ public class SFTPSessionFactory implements FactoryBean<SFTPSession>, Initializin
Assert.state(this.port >= 0, "port must be a valid 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 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() {
return SFTPSession.class;
public Class<?extends SftpSession> getObjectType() {
return SftpSession.class;
}
public boolean isSingleton() {

View File

@@ -18,13 +18,13 @@ package org.springframework.integration.sftp;
/**
*
* Holds instances of {@link org.springframework.integration.sftp.SFTPSession} since they're stateful
* Holds instances of {@link SftpSession} since they're stateful
* and might be in use while another run happens.
*
*
* @author Josh Long
*/
public interface SFTPSessionPool {
public interface SftpSessionPool {
/**
* this returns a session that can be used to connct to an sftp instance and perform operations
*
@@ -32,7 +32,7 @@ public interface SFTPSessionPool {
* @throws Exception thrown if theres any of the numerous faults possible when trying to connect to the remote
* server
*/
SFTPSession getSession() throws Exception;
SftpSession getSession() throws Exception;
/**
* Frees up the client. Im not sure what the meaningful semantics of this are. Perhaps it just calls <code>(session
@@ -40,5 +40,5 @@ public interface SFTPSessionPool {
*
* @param session the session to relinquish / renew
*/
void release(SFTPSession session);
}
void release(SftpSession session);
}

View File

@@ -16,9 +16,9 @@
package org.springframework.integration.sftp.config;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.integration.sftp.QueuedSFTPSessionPool;
import org.springframework.integration.sftp.SFTPSendingMessageHandler;
import org.springframework.integration.sftp.SFTPSessionFactory;
import org.springframework.integration.sftp.QueuedSftpSessionPool;
import org.springframework.integration.sftp.SftpSendingMessageHandler;
import org.springframework.integration.sftp.SftpSessionFactory;
/**
@@ -27,7 +27,7 @@ import org.springframework.integration.sftp.SFTPSessionFactory;
*
* @author Josh Long
*/
public class SFTPMessageSendingConsumerFactoryBean implements FactoryBean<SFTPSendingMessageHandler> {
public class SftpMessageSendingConsumerFactoryBean implements FactoryBean<SftpSendingMessageHandler> {
private String host;
private String keyFile;
private String keyFilePassword;
@@ -37,22 +37,22 @@ public class SFTPMessageSendingConsumerFactoryBean implements FactoryBean<SFTPSe
private boolean autoCreateDirectories;
private int port;
public SFTPSendingMessageHandler getObject() throws Exception {
SFTPSessionFactory sessionFactory = SFTPSessionUtils.buildSftpSessionFactory(
public SftpSendingMessageHandler getObject() throws Exception {
SftpSessionFactory sessionFactory = SftpSessionUtils.buildSftpSessionFactory(
this.host, this.password, this.username, this.keyFile , this.keyFilePassword, this.port);
QueuedSFTPSessionPool queuedSFTPSessionPool = new QueuedSFTPSessionPool(15, sessionFactory);
QueuedSftpSessionPool queuedSFTPSessionPool = new QueuedSftpSessionPool(15, sessionFactory);
queuedSFTPSessionPool.afterPropertiesSet();
SFTPSendingMessageHandler sftpSendingMessageHandler = new SFTPSendingMessageHandler(queuedSFTPSessionPool);
SftpSendingMessageHandler sftpSendingMessageHandler = new SftpSendingMessageHandler(queuedSFTPSessionPool);
sftpSendingMessageHandler.setRemoteDirectory(this.remoteDirectory);
sftpSendingMessageHandler.afterPropertiesSet();
return sftpSendingMessageHandler;
}
public Class<?extends SFTPSendingMessageHandler> getObjectType() {
return SFTPSendingMessageHandler.class;
public Class<?extends SftpSendingMessageHandler> getObjectType() {
return SftpSendingMessageHandler.class;
}
public boolean isSingleton() {

View File

@@ -37,18 +37,18 @@ import java.util.Map;
/**
* Building a {@link org.springframework.integration.sftp.SFTPMessageSource} is a complicated because we also
* Building a {@link org.springframework.integration.sftp.SftpMessageSource} is a complicated because we also
* use a {@link org.springframework.integration.file.FileReadingMessageSource} to handle the "receipt" of files in
* a {@link #localWorkingDirectory}.
*
* @author Josh Long
*/
public class SFTPMessageSourceFactoryBean extends AbstractFactoryBean<SFTPMessageSource> implements ApplicationContextAware, ResourceLoaderAware {
public class SftpMessageSourceFactoryBean extends AbstractFactoryBean<SftpMessageSource> implements ApplicationContextAware, ResourceLoaderAware {
private ApplicationContext applicationContext;
private FileReadingMessageSource fileReadingMessageSource;
private Resource localDirectoryResource;
private ResourceLoader resourceLoader;
private SFTPInboundSynchronizer synchronizer;
private SftpInboundSynchronizer synchronizer;
private String host;
private String keyFile;
private String keyFilePassword;
@@ -61,7 +61,7 @@ public class SFTPMessageSourceFactoryBean extends AbstractFactoryBean<SFTPMessag
private boolean autoCreateDirectories;
private boolean autoDeleteRemoteFilesOnSync;
private int port = 22;
private SFTPFileListFilter filter;
private SftpFileListFilter filter;
private String filenamePattern;
public FileReadingMessageSource getFileReadingMessageSource() {
@@ -85,8 +85,8 @@ public class SFTPMessageSourceFactoryBean extends AbstractFactoryBean<SFTPMessag
}
@Override
public Class<?extends SFTPMessageSource> getObjectType() {
return SFTPMessageSource.class;
public Class<?extends SftpMessageSource> getObjectType() {
return SftpMessageSource.class;
}
public String getPassword() {
@@ -101,7 +101,7 @@ public class SFTPMessageSourceFactoryBean extends AbstractFactoryBean<SFTPMessag
return remoteDirectory;
}
public SFTPInboundSynchronizer getSynchronizer() {
public SftpInboundSynchronizer getSynchronizer() {
return synchronizer;
}
@@ -178,7 +178,7 @@ public class SFTPMessageSourceFactoryBean extends AbstractFactoryBean<SFTPMessag
this.resourceLoader = resourceLoader;
}
public void setSynchronizer(final SFTPInboundSynchronizer synchronizer) {
public void setSynchronizer(final SftpInboundSynchronizer synchronizer) {
this.synchronizer = synchronizer;
}
@@ -194,7 +194,7 @@ public class SFTPMessageSourceFactoryBean extends AbstractFactoryBean<SFTPMessag
this.filenamePattern = filenamePattern;
}
public void setFilter(SFTPFileListFilter filter) {
public void setFilter(SftpFileListFilter filter) {
this.filter = filter;
}
@@ -203,7 +203,7 @@ public class SFTPMessageSourceFactoryBean extends AbstractFactoryBean<SFTPMessag
}
@Override
protected SFTPMessageSource createInstance() throws Exception {
protected SftpMessageSource createInstance() throws Exception {
try {
if ((localWorkingDirectory == null) || !StringUtils.hasText(localWorkingDirectory)) {
File tmp = SystemUtils.getJavaIoTmpDir();
@@ -218,22 +218,22 @@ public class SFTPMessageSourceFactoryBean extends AbstractFactoryBean<SFTPMessag
fileReadingMessageSource = new FileReadingMessageSource();
synchronizer = new SFTPInboundSynchronizer();
synchronizer = new SftpInboundSynchronizer();
CompositeFTPFileListFilter compositeFTPFileListFilter = new CompositeFTPFileListFilter();
CompositeFtpFileListFilter compositeFtpFileListFilter = new CompositeFtpFileListFilter();
if (StringUtils.hasText(this.filenamePattern)) {
PatternMatchingSFTPFileListFilter flp = new PatternMatchingSFTPFileListFilter();
PatternMatchingSftpFileListFilter flp = new PatternMatchingSftpFileListFilter();
flp.setPatternExpression(this.filenamePattern);
flp.afterPropertiesSet();
compositeFTPFileListFilter.addFilter(flp);
compositeFtpFileListFilter.addFilter(flp);
}
if (this.filter != null) {
compositeFTPFileListFilter.addFilter(this.filter);
compositeFtpFileListFilter.addFilter(this.filter);
}
synchronizer.setFilter(compositeFTPFileListFilter);
synchronizer.setFilter(compositeFtpFileListFilter);
if (null == taskScheduler) {
Map<String, TaskScheduler> tss = null;
@@ -258,17 +258,17 @@ public class SFTPMessageSourceFactoryBean extends AbstractFactoryBean<SFTPMessag
this.taskScheduler = ts;
}
SFTPSessionFactory sessionFactory = SFTPSessionUtils.buildSftpSessionFactory(
SftpSessionFactory sessionFactory = SftpSessionUtils.buildSftpSessionFactory(
this.getHost(), this.getPassword(), this.getUsername(), this.getKeyFile(), this.getKeyFilePassword(), this.getPort());
QueuedSFTPSessionPool pool = new QueuedSFTPSessionPool(15, sessionFactory);
QueuedSftpSessionPool pool = new QueuedSftpSessionPool(15, sessionFactory);
pool.afterPropertiesSet();
synchronizer.setRemotePath(this.getRemoteDirectory());
synchronizer.setPool(pool);
synchronizer.setAutoCreatePath(this.isAutoCreateDirectories());
synchronizer.setShouldDeleteDownloadedRemoteFiles(this.isAutoDeleteRemoteFilesOnSync());
SFTPMessageSource sftpMessageSource = new SFTPMessageSource(fileReadingMessageSource, synchronizer);
SftpMessageSource sftpMessageSource = new SftpMessageSource(fileReadingMessageSource, synchronizer);
sftpMessageSource.setTaskScheduler(taskScheduler);

View File

@@ -33,8 +33,7 @@ import org.w3c.dom.Element;
* @author Josh Long
*/
@SuppressWarnings("unused")
public class SFTPNamespaceHandler extends NamespaceHandlerSupport {
private static final String PACKAGE_NAME = "org.springframework.integration.sftp";
public class SftpNamespaceHandler extends NamespaceHandlerSupport {
public void init() {
registerBeanDefinitionParser("inbound-channel-adapter", new SFTPMessageSourceBeanDefinitionParser());
@@ -47,7 +46,7 @@ public class SFTPNamespaceHandler extends NamespaceHandlerSupport {
private static class SFTPMessageSendingConsumerBeanDefinitionParser extends AbstractOutboundChannelAdapterParser {
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(SFTPMessageSendingConsumerFactoryBean.class.getName());
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(SftpMessageSendingConsumerFactoryBean.class.getName());
for (String p : "auto-create-directories,username,password,host,key-file,key-file-password,remote-directory".split(",")) {
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, p);
@@ -64,7 +63,7 @@ public class SFTPNamespaceHandler extends NamespaceHandlerSupport {
private static class SFTPMessageSourceBeanDefinitionParser extends AbstractPollingInboundChannelAdapterParser {
@Override
protected String parseSource(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( SFTPMessageSourceFactoryBean.class.getName());
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( SftpMessageSourceFactoryBean.class.getName());
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "filter");

View File

@@ -15,20 +15,20 @@
*/
package org.springframework.integration.sftp.config;
import org.springframework.integration.sftp.SFTPSessionFactory;
import org.springframework.integration.sftp.SftpSessionFactory;
/**
*
* Provides a single place to handle this tedious chore.
*
* todo : replace all the ad-hoc definitions of {@link org.springframework.integration.sftp.SFTPSessionFactory}
* todo : replace all the ad-hoc definitions of {@link org.springframework.integration.sftp.SftpSessionFactory}
*
* @author Josh Long
*/
public class SFTPSessionUtils {
public class SftpSessionUtils {
/**
* This method hides the minutae required to build an #SFTPSessionFactory.
* This method hides the minutae required to build an #SftpSessionFactory.
*
* @param host the host to connect to.
* @param usr this is required. It is the username of the credentials being authenticated.
@@ -38,13 +38,13 @@ public class SFTPSessionUtils {
* @param pvKeyPass the passphrase used to use the key file
* @param port the default (22) is used if the value here is N< 0. The value should be only be set if the port
* is non-standard (not 22)
* @return the SFTPSessionFactory that's used to create connections and get us in the right state to start issue
* @return the SftpSessionFactory that's used to create connections and get us in the right state to start issue
* 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)
public static SftpSessionFactory buildSftpSessionFactory(String host, String pw, String usr, String pvKey, String pvKeyPass, int port)
throws Exception {
SFTPSessionFactory sftpSessionFactory = new SFTPSessionFactory();
SftpSessionFactory sftpSessionFactory = new SftpSessionFactory();
sftpSessionFactory.setPassword(pw);
sftpSessionFactory.setPort(port);
sftpSessionFactory.setRemoteHost(host);

View File

@@ -1 +1 @@
http\://www.springframework.org/schema/integration/sftp=org.springframework.integration.sftp.config.SFTPNamespaceHandler
http\://www.springframework.org/schema/integration/sftp=org.springframework.integration.sftp.config.SftpNamespaceHandler

View File

@@ -2,19 +2,14 @@ package org.springframework.integration.sftp;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.ErrorHandler;
import java.io.File;
import java.util.logging.Logger;
@@ -26,7 +21,7 @@ import java.util.logging.Logger;
public class TestSFTPReceipt {
private static final Logger logger = Logger.getLogger(TestSFTPReceipt.class.getName());
private SFTPSessionFactory sftpSessionFactory;
private SftpSessionFactory sftpSessionFactory;
private String host;
private String password;
private String user;
@@ -59,7 +54,7 @@ public class TestSFTPReceipt {
Resource localDirectory = new FileSystemResource(local);
// pool
QueuedSFTPSessionPool queuedSFTPSessionPool = new QueuedSFTPSessionPool(sftpSessionFactory);
QueuedSftpSessionPool queuedSFTPSessionPool = new QueuedSftpSessionPool(sftpSessionFactory);
queuedSFTPSessionPool.afterPropertiesSet();
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
@@ -74,7 +69,7 @@ public class TestSFTPReceipt {
taskScheduler.initialize();
// synchronizer
final SFTPInboundSynchronizer sftpInboundSynchronizer = new SFTPInboundSynchronizer();
final SftpInboundSynchronizer sftpInboundSynchronizer = new SftpInboundSynchronizer();
sftpInboundSynchronizer.setLocalDirectory(localDirectory);
sftpInboundSynchronizer.setRemotePath(remoteMount);
sftpInboundSynchronizer.setAutoCreatePath(true);
@@ -97,9 +92,9 @@ public class TestSFTPReceipt {
}).start();
}
private SFTPSessionFactory buildSFTPSessionFactory(String host, String pw, String usr, String pvKey, String pvKeyPass, int port)
private SftpSessionFactory buildSFTPSessionFactory(String host, String pw, String usr, String pvKey, String pvKeyPass, int port)
throws Throwable {
SFTPSessionFactory sftpSessionFactory = new SFTPSessionFactory();
SftpSessionFactory sftpSessionFactory = new SftpSessionFactory();
sftpSessionFactory.setPassword(pw);
sftpSessionFactory.setPort(port);
sftpSessionFactory.setRemoteHost(host);