fixing an issue with charsets in the FTP namespace parser support int-950

This commit is contained in:
Josh Long
2010-10-04 01:17:58 -07:00
parent fb0ae7332b
commit 8e6a1f2b29
19 changed files with 542 additions and 512 deletions

View File

@@ -14,7 +14,8 @@ import java.io.IOException;
import java.net.SocketException;
abstract public class AbstractFtpClientFactory<T extends FTPClient> implements FtpClientFactory<T> {
abstract public class AbstractFtpClientFactory<T extends FTPClient>
implements FtpClientFactory<T> {
private static final Log logger = LogFactory.getLog(FtpClientFactory.class);
private static final String DEFAULT_REMOTE_WORKING_DIRECTORY = "/";
protected FTPClientConfig config;
@@ -95,7 +96,8 @@ abstract public class AbstractFtpClientFactory<T extends FTPClient> implements F
onAfterConnect(client);
if (!FTPReply.isPositiveCompletion(client.getReplyCode())) {
throw new MessagingException("Connecting to server [" + host + ":" + port + "] failed, please check the connection");
throw new MessagingException("Connecting to server [" + host + ":" +
port + "] failed, please check the connection");
}
if (logger.isDebugEnabled()) {
@@ -103,7 +105,8 @@ abstract public class AbstractFtpClientFactory<T extends FTPClient> implements F
}
if (!client.login(username, password)) {
throw new MessagingException("Login failed. Please check the username and password.");
throw new MessagingException(
"Login failed. Please check the username and password.");
}
setClientMode(client);
@@ -114,12 +117,15 @@ abstract public class AbstractFtpClientFactory<T extends FTPClient> implements F
logger.debug("login successful");
}
if (!remoteWorkingDirectory.equals(client.printWorkingDirectory()) && !client.changeWorkingDirectory(remoteWorkingDirectory)) {
throw new MessagingException("Could not change directory to '" + remoteWorkingDirectory + "'. Please check the path.");
if (!remoteWorkingDirectory.equals(client.printWorkingDirectory()) &&
!client.changeWorkingDirectory(remoteWorkingDirectory)) {
throw new MessagingException("Could not change directory to '" +
remoteWorkingDirectory + "'. Please check the path.");
}
if (logger.isDebugEnabled()) {
logger.debug("working directory is: " + client.printWorkingDirectory());
logger.debug("working directory is: " +
client.printWorkingDirectory());
}
return client;

View File

@@ -12,75 +12,84 @@ import javax.net.ssl.TrustManager;
* @author Josh Long
*/
public class ClientFactorySupport {
public static DefaultFtpsClientFactory ftpsClientFactory(String host, int port, String remoteDir, String user, String pw, int fileType, int clientMode, String prot, String protocol,
String authValue, Boolean implicit, TrustManager trustManager, KeyManager keyManager, Boolean sessionCreation, Boolean useClientMode, Boolean wantsClientAuth, Boolean needClientAuth , String [] cipherSuites) {
DefaultFtpsClientFactory defaultFtpClientFactory = new DefaultFtpsClientFactory();
defaultFtpClientFactory.setHost(host);
defaultFtpClientFactory.setPassword(pw);
defaultFtpClientFactory.setPort((port));
defaultFtpClientFactory.setRemoteWorkingDirectory(remoteDir);
defaultFtpClientFactory.setUsername(user);
defaultFtpClientFactory.setFileType(fileType);
defaultFtpClientFactory.setClientMode(clientMode);
public static DefaultFtpsClientFactory ftpsClientFactory(String host,
int port, String remoteDir, String user, String pw, int fileType,
int clientMode, String prot, String protocol, String authValue,
Boolean implicit, TrustManager trustManager, KeyManager keyManager,
Boolean sessionCreation, Boolean useClientMode,
Boolean wantsClientAuth, Boolean needClientAuth, String[] cipherSuites) {
DefaultFtpsClientFactory defaultFtpClientFactory = new DefaultFtpsClientFactory();
defaultFtpClientFactory.setHost(host);
defaultFtpClientFactory.setPassword(pw);
defaultFtpClientFactory.setPort((port));
defaultFtpClientFactory.setRemoteWorkingDirectory(remoteDir);
defaultFtpClientFactory.setUsername(user);
defaultFtpClientFactory.setFileType(fileType);
defaultFtpClientFactory.setClientMode(clientMode);
if(cipherSuites !=null)
defaultFtpClientFactory.setCipherSuites( cipherSuites );
if (cipherSuites != null) {
defaultFtpClientFactory.setCipherSuites(cipherSuites);
}
if (StringUtils.hasText(prot)) {
defaultFtpClientFactory.setProt(prot);
}
if (StringUtils.hasText(protocol)) {
defaultFtpClientFactory.setProtocol(protocol);
}
if (StringUtils.hasText(prot)) {
defaultFtpClientFactory.setProt(prot);
}
if (StringUtils.hasText(authValue)) {
defaultFtpClientFactory.setAuthValue(authValue);
}
if (StringUtils.hasText(protocol)) {
defaultFtpClientFactory.setProtocol(protocol);
}
if (null != implicit) {
defaultFtpClientFactory.setImplicit(implicit);
}
if (StringUtils.hasText(authValue)) {
defaultFtpClientFactory.setAuthValue(authValue);
}
if (trustManager != null) {
defaultFtpClientFactory.setTrustManager(trustManager);
}
if (null != implicit) {
defaultFtpClientFactory.setImplicit(implicit);
}
if (keyManager != null) {
defaultFtpClientFactory.setKeyManager(keyManager);
}
if (trustManager != null) {
defaultFtpClientFactory.setTrustManager(trustManager);
}
if (needClientAuth != null) {
defaultFtpClientFactory.setNeedClientAuth(needClientAuth);
}
if (keyManager != null) {
defaultFtpClientFactory.setKeyManager(keyManager);
}
if (wantsClientAuth != null) {
defaultFtpClientFactory.setWantsClientAuth(wantsClientAuth);
}
if (needClientAuth != null) {
defaultFtpClientFactory.setNeedClientAuth(needClientAuth);
}
if (sessionCreation != null) {
defaultFtpClientFactory.setSessionCreation(sessionCreation);
}
if (wantsClientAuth != null) {
defaultFtpClientFactory.setWantsClientAuth(wantsClientAuth);
}
if (useClientMode != null) {
defaultFtpClientFactory.setUseClientMode(useClientMode);
}
if (sessionCreation != null) {
defaultFtpClientFactory.setSessionCreation(sessionCreation);
}
return defaultFtpClientFactory;
}
if (useClientMode != null) {
defaultFtpClientFactory.setUseClientMode(useClientMode);
}
public static DefaultFtpClientFactory ftpClientFactory(String host,
int port,
String remoteDir,
String user,
String pw,
int clientMode,
int fileType) {
DefaultFtpClientFactory defaultFtpClientFactory = new DefaultFtpClientFactory();
defaultFtpClientFactory.setHost(host);
defaultFtpClientFactory.setPassword(pw);
defaultFtpClientFactory.setPort(port);
defaultFtpClientFactory.setRemoteWorkingDirectory(remoteDir);
defaultFtpClientFactory.setUsername(user);
defaultFtpClientFactory.setClientMode(clientMode);
defaultFtpClientFactory.setFileType(fileType);
return defaultFtpClientFactory;
}
public static DefaultFtpClientFactory ftpClientFactory(String host, int port, String remoteDir, String user, String pw, int clientMode, int fileType) {
DefaultFtpClientFactory defaultFtpClientFactory = new DefaultFtpClientFactory();
defaultFtpClientFactory.setHost(host);
defaultFtpClientFactory.setPassword(pw);
defaultFtpClientFactory.setPort(port);
defaultFtpClientFactory.setRemoteWorkingDirectory(remoteDir);
defaultFtpClientFactory.setUsername(user);
defaultFtpClientFactory.setClientMode(clientMode);
defaultFtpClientFactory.setFileType( fileType );
return defaultFtpClientFactory;
}
return defaultFtpClientFactory;
}
}

View File

@@ -3,26 +3,19 @@ package org.springframework.integration.ftp;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPSClient;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.security.NoSuchAlgorithmException;
import java.util.Properties;
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import java.security.NoSuchAlgorithmException;
import java.util.Properties;
/**
@@ -31,163 +24,131 @@ import javax.net.ssl.TrustManager;
* @author Josh Long
*/
public class DefaultFtpsClientFactory extends AbstractFtpClientFactory<FTPSClient> {
private Boolean useClientMode;
private Boolean sessionCreation;
private String authValue;
private TrustManager trustManager;
private String[] cipherSuites;
private String[] protocols;
private KeyManager keyManager;
private Boolean needClientAuth;
private Boolean wantsClientAuth;
private boolean implicit = false;
private String prot = "P";
private String protocol;
private Boolean useClientMode;
private Boolean sessionCreation;
private String authValue;
private TrustManager trustManager;
private String[] cipherSuites;
private String[] protocols;
private KeyManager keyManager;
private Boolean needClientAuth;
private Boolean wantsClientAuth;
private boolean implicit = false;
private String prot = "P";
private String protocol;
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public static void main(String[] args) throws Throwable {
File file = new File(SystemUtils.getUserHome(), "Desktop/ftp.properties");
Resource r = new FileSystemResource(file);
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean.setLocation(r);
propertiesFactoryBean.afterPropertiesSet();
public void setUseClientMode(Boolean useClientMode) {
this.useClientMode = useClientMode;
}
Properties props = propertiesFactoryBean.getObject();
public void setSessionCreation(Boolean sessionCreation) {
this.sessionCreation = sessionCreation;
}
String user = props.getProperty("ftp.username");
String pw = props.getProperty("ftp.password");
String host = props.getProperty("ftp.host");
public void setAuthValue(String authValue) {
this.authValue = authValue;
}
if (!file.exists()) {
throw new RuntimeException("doesn't exist");
}
public void setTrustManager(TrustManager trustManager) {
this.trustManager = trustManager;
}
DefaultFtpsClientFactory defaultFtpsClientFactory = new DefaultFtpsClientFactory();
defaultFtpsClientFactory.setUsername(user);
defaultFtpsClientFactory.setImplicit(false);
defaultFtpsClientFactory.setPassword(pw);
defaultFtpsClientFactory.setClientMode(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
defaultFtpsClientFactory.setHost(host);
public void setCipherSuites(String[] cipherSuites) {
this.cipherSuites = cipherSuites;
}
FTPSClient ftpClient = defaultFtpsClientFactory.getClient();
public void setProtocols(String[] protocols) {
this.protocols = protocols;
}
InputStream fileStream = r.getInputStream();
ftpClient.storeFile("pushed.java", fileStream);
fileStream.close();
ftpClient.disconnect();
}
public void setKeyManager(KeyManager keyManager) {
this.keyManager = keyManager;
}
public void setUseClientMode(Boolean useClientMode) {
this.useClientMode = useClientMode;
}
public void setNeedClientAuth(Boolean needClientAuth) {
this.needClientAuth = needClientAuth;
}
public void setSessionCreation(Boolean sessionCreation) {
this.sessionCreation = sessionCreation;
}
public void setWantsClientAuth(Boolean wantsClientAuth) {
this.wantsClientAuth = wantsClientAuth;
}
public void setAuthValue(String authValue) {
this.authValue = authValue;
}
public void setProt(String prot) {
this.prot = prot;
}
public void setTrustManager(TrustManager trustManager) {
this.trustManager = trustManager;
}
@Override
protected void onAfterConnect(FTPSClient ftpsClient)
throws IOException {
ftpsClient.execPBSZ(0);
ftpsClient.execPROT(this.prot);
}
public void setCipherSuites(String[] cipherSuites) {
this.cipherSuites = cipherSuites;
}
@Override
public FTPSClient getClient() throws SocketException, IOException {
FTPSClient ftpsClient = super.getClient();
public void setProtocols(String[] protocols) {
this.protocols = protocols;
}
if (StringUtils.hasText(this.authValue)) {
ftpsClient.setAuthValue(authValue);
}
public void setKeyManager(KeyManager keyManager) {
this.keyManager = keyManager;
}
if (this.trustManager != null) {
ftpsClient.setTrustManager(this.trustManager);
}
public void setNeedClientAuth(Boolean needClientAuth) {
this.needClientAuth = needClientAuth;
}
if (this.cipherSuites != null) {
ftpsClient.setEnabledCipherSuites(this.cipherSuites);
}
public void setWantsClientAuth(Boolean wantsClientAuth) {
this.wantsClientAuth = wantsClientAuth;
}
if (this.protocols != null) {
ftpsClient.setEnabledProtocols(this.protocols);
}
public void setProt(String prot) {
this.prot = prot;
}
if (this.sessionCreation != null) {
ftpsClient.setEnabledSessionCreation(this.sessionCreation);
}
@Override
protected void onAfterConnect(FTPSClient ftpsClient)
throws IOException {
ftpsClient.execPBSZ(0);
ftpsClient.execPROT(this.prot);
}
if (this.useClientMode != null) {
ftpsClient.setUseClientMode(this.useClientMode);
}
@Override
public FTPSClient getClient() throws SocketException, IOException {
FTPSClient ftpsClient = super.getClient();
if (this.sessionCreation != null) {
ftpsClient.setEnabledSessionCreation(this.sessionCreation);
}
if (StringUtils.hasText(this.authValue)) {
ftpsClient.setAuthValue(authValue);
}
if (this.keyManager != null) {
ftpsClient.setKeyManager(keyManager);
}
if (this.trustManager != null) {
ftpsClient.setTrustManager(this.trustManager);
}
if (this.needClientAuth != null) {
ftpsClient.setNeedClientAuth(this.needClientAuth);
}
if (this.cipherSuites != null) {
ftpsClient.setEnabledCipherSuites(this.cipherSuites);
}
if (this.wantsClientAuth != null) {
ftpsClient.setWantClientAuth(this.wantsClientAuth);
}
if (this.protocols != null) {
ftpsClient.setEnabledProtocols(this.protocols);
}
return ftpsClient;
}
if (this.sessionCreation != null) {
ftpsClient.setEnabledSessionCreation(this.sessionCreation);
}
public void setImplicit(boolean implicit) {
this.implicit = implicit;
}
if (this.useClientMode != null) {
ftpsClient.setUseClientMode(this.useClientMode);
}
@Override
protected FTPSClient createSingleInstanceOfClient() {
try {
if (StringUtils.hasText(this.protocol)) {
return new FTPSClient(this.protocol, this.implicit);
}
if (this.sessionCreation != null) {
ftpsClient.setEnabledSessionCreation(this.sessionCreation);
}
if (this.keyManager != null) {
ftpsClient.setKeyManager(keyManager);
}
if (this.needClientAuth != null) {
ftpsClient.setNeedClientAuth(this.needClientAuth);
}
if (this.wantsClientAuth != null) {
ftpsClient.setWantClientAuth(this.wantsClientAuth);
}
return ftpsClient;
}
public void setImplicit(boolean implicit) {
this.implicit = implicit;
}
@Override
protected FTPSClient createSingleInstanceOfClient() {
try {
if (StringUtils.hasText(this.protocol)) {
return new FTPSClient(this.protocol, this.implicit);
}
return new FTPSClient(this.implicit);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
return new FTPSClient(this.implicit);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -25,7 +25,7 @@ import java.io.IOException;
*
* @author Iwein Fuld
*/
public interface FtpClientFactory <T extends FTPClient>{
public interface FtpClientFactory<T extends FTPClient> {
/**
* @return Fully configured and connected FTPClient. Never <code>null</code>.
* @throws IOException thrown when a networking IO subsystem error occurs

View File

@@ -1,4 +1,4 @@
package org.springframework.integration.ftp.impl;
package org.springframework.integration.ftp;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
@@ -23,7 +23,8 @@ import java.util.Collection;
*
* @author Josh Long
*/
public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemoteFileSystemSychronizer<FTPFile> {
public class FtpInboundRemoteFileSystemSynchronizer
extends AbstractInboundRemoteFileSystemSychronizer<FTPFile> {
protected FtpClientPool clientPool;
@Override
@@ -44,14 +45,17 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
this.clientPool = clientPool;
}
protected boolean copyFileToLocalDirectory(FTPClient client, FTPFile ftpFile, Resource localDirectory)
protected boolean copyFileToLocalDirectory(FTPClient client,
FTPFile ftpFile, Resource localDirectory)
throws IOException, FileNotFoundException {
String remoteFileName = ftpFile.getName();
String localFileName = localDirectory.getFile().getPath() + "/" + remoteFileName;
String localFileName = localDirectory.getFile().getPath() + "/" +
remoteFileName;
File localFile = new File(localFileName);
if (!localFile.exists()) {
String tempFileName = localFileName + AbstractInboundRemoteFileSystemSynchronizingMessageSource.INCOMPLETE_EXTENSION;
String tempFileName = localFileName +
AbstractInboundRemoteFileSystemSynchronizingMessageSource.INCOMPLETE_EXTENSION;
File file = new File(tempFileName);
FileOutputStream fos = new FileOutputStream(file);
@@ -78,21 +82,26 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
protected void syncRemoteToLocalFileSystem() {
try {
FTPClient client = this.clientPool.getClient();
Assert.state(client != null, FtpClientPool.class.getSimpleName() + " returned a 'null' client. " + "This most likely a bug in the pool implementation.");
Assert.state(client != null,
FtpClientPool.class.getSimpleName() +
" returned a 'null' client. " +
"This most likely a bug in the pool implementation.");
Collection<FTPFile> fileList = this.filter.filterEntries(client.listFiles());
try {
for (FTPFile ftpFile : fileList) {
if ((ftpFile != null) && ftpFile.isFile()) {
copyFileToLocalDirectory(client, ftpFile, this.localDirectory);
copyFileToLocalDirectory(client, ftpFile,
this.localDirectory);
}
}
} finally {
this.clientPool.releaseClient(client);
}
} catch (IOException e) {
throw new MessagingException("Problem occurred while synchronizing remote to local directory", e);
throw new MessagingException("Problem occurred while synchronizing remote to local directory",
e);
}
}
@@ -108,6 +117,7 @@ public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemot
public void acknowledge(Object useful, FTPFile msg)
throws Exception {
FTPClient ftpClient = (FTPClient) useful;
if ((msg != null) && ftpClient.deleteFile(msg.getName())) {
if (logger.isDebugEnabled()) {
logger.debug("deleted " + msg.getName());

View File

@@ -1,8 +1,7 @@
package org.springframework.integration.ftp.impl;
package org.springframework.integration.ftp;
import org.apache.commons.net.ftp.FTPFile;
import org.springframework.integration.file.AbstractInboundRemoteFileSystemSynchronizingMessageSource;
import org.springframework.integration.ftp.FtpClientPool;
/**
@@ -10,15 +9,15 @@ import org.springframework.integration.ftp.FtpClientPool;
*
* @author Josh Long
*/
public class FtpInboundRemoteFileSystemSynchronizingMessageSource
extends AbstractInboundRemoteFileSystemSynchronizingMessageSource<FTPFile, FtpInboundRemoteFileSystemSynchronizer> {
public class FtpInboundRemoteFileSystemSynchronizingMessageSource
extends AbstractInboundRemoteFileSystemSynchronizingMessageSource<FTPFile, FtpInboundRemoteFileSystemSynchronizer> {
private volatile FtpClientPool clientPool;
public void setClientPool(FtpClientPool clientPool) {
this.clientPool = clientPool;
}
@Override
@Override
protected void doStart() {
this.synchronizer.start();
}
@@ -33,8 +32,8 @@ public class FtpInboundRemoteFileSystemSynchronizingMessageSource
super.onInit();
this.synchronizer.setClientPool(this.clientPool);
}
public String getComponentType(){
public String getComponentType() {
return "ftp:inbound-channel-adapter";
}
}

View File

@@ -1,4 +1,4 @@
package org.springframework.integration.ftp.impl;
package org.springframework.integration.ftp;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.net.ftp.FTP;
@@ -12,7 +12,6 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.integration.file.entries.CompositeEntryListFilter;
import org.springframework.integration.file.entries.EntryListFilter;
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
import org.springframework.integration.ftp.*;
import org.springframework.util.StringUtils;
import java.io.File;
@@ -23,7 +22,9 @@ import java.io.File;
*
* @author Josh Long
*/
public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean extends AbstractFactoryBean<FtpInboundRemoteFileSystemSynchronizingMessageSource> implements ResourceLoaderAware {
public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean
extends AbstractFactoryBean<FtpInboundRemoteFileSystemSynchronizingMessageSource>
implements ResourceLoaderAware {
protected volatile String port;
protected volatile String autoCreateDirectories;
protected volatile String filenamePattern;
@@ -37,16 +38,17 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean extends Ab
protected volatile EntryListFilter<FTPFile> filter;
protected volatile int clientMode = FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE;
protected volatile int fileType = FTP.BINARY_FILE_TYPE;
private volatile String autoDeleteRemoteFilesOnSync;
protected String defaultFtpInboundFolderName = "ftpInbound";
@SuppressWarnings("unused")
public void setFileType(int fileType) {
this.fileType = fileType;
}
private volatile String autoDeleteRemoteFilesOnSync;
@SuppressWarnings("unused")
public void setAutoDeleteRemoteFilesOnSync(String autoDeleteRemoteFilesOnSync) {
public void setAutoDeleteRemoteFilesOnSync(
String autoDeleteRemoteFilesOnSync) {
this.autoDeleteRemoteFilesOnSync = autoDeleteRemoteFilesOnSync;
}
@@ -58,23 +60,25 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean extends Ab
private Resource fromText(String path) {
ResourceEditor resourceEditor = new ResourceEditor(this.resourceLoader);
resourceEditor.setAsText(path);
return (Resource) resourceEditor.getValue();
}
protected AbstractFtpClientFactory defaultClientFactory() throws Exception {
return ClientFactorySupport.ftpClientFactory( this.host , Integer.parseInt(this.port) , this.remoteDirectory ,
this.username ,this.password, this.clientMode , this.fileType);
protected AbstractFtpClientFactory defaultClientFactory()
throws Exception {
return ClientFactorySupport.ftpClientFactory(this.host,
Integer.parseInt(this.port), this.remoteDirectory, this.username,
this.password, this.clientMode, this.fileType);
}
protected String defaultFtpInboundFolderName = "ftpInbound";
@Override
protected FtpInboundRemoteFileSystemSynchronizingMessageSource createInstance()
throws Exception {
boolean autoCreatDirs = Boolean.parseBoolean(this.autoCreateDirectories);
boolean ackRemoteDir = Boolean.parseBoolean(this.autoDeleteRemoteFilesOnSync);
FtpInboundRemoteFileSystemSynchronizingMessageSource ftpRemoteFileSystemSynchronizingMessageSource = new FtpInboundRemoteFileSystemSynchronizingMessageSource();
FtpInboundRemoteFileSystemSynchronizingMessageSource ftpRemoteFileSystemSynchronizingMessageSource =
new FtpInboundRemoteFileSystemSynchronizingMessageSource();
ftpRemoteFileSystemSynchronizingMessageSource.setAutoCreateDirectories(autoCreatDirs);
if (!StringUtils.hasText(this.localWorkingDirectory)) {
@@ -88,7 +92,8 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean extends Ab
CompositeEntryListFilter<FTPFile> compositeFtpFileListFilter = new CompositeEntryListFilter<FTPFile>();
if (StringUtils.hasText(this.filenamePattern)) {
PatternMatchingEntryListFilter<FTPFile> ftpFilePatternMatchingEntryListFilter = new PatternMatchingEntryListFilter<FTPFile>(ftpFileEntryNamer, filenamePattern);
PatternMatchingEntryListFilter<FTPFile> ftpFilePatternMatchingEntryListFilter =
new PatternMatchingEntryListFilter<FTPFile>(ftpFileEntryNamer, filenamePattern);
compositeFtpFileListFilter.addFilter(ftpFilePatternMatchingEntryListFilter);
}
@@ -96,7 +101,8 @@ public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean extends Ab
compositeFtpFileListFilter.addFilter(this.filter);
}
QueuedFtpClientPool queuedFtpClientPool = new QueuedFtpClientPool(15, defaultClientFactory());
QueuedFtpClientPool queuedFtpClientPool = new QueuedFtpClientPool(15,
defaultClientFactory());
FtpInboundRemoteFileSystemSynchronizer ftpRemoteFileSystemSynchronizer = new FtpInboundRemoteFileSystemSynchronizer();
ftpRemoteFileSystemSynchronizer.setClientPool(queuedFtpClientPool);

View File

@@ -39,11 +39,16 @@ import java.net.SocketException;
*
* @author Iwein Fuld
* @author Mark Fisher
* @author Josh Long
* @author Josh Long
*/
public class FtpSendingMessageHandler implements MessageHandler, InitializingBean {
public class FtpSendingMessageHandler implements MessageHandler,
InitializingBean {
private static final String TEMPORARY_FILE_SUFFIX = ".writing";
private FtpClientPool ftpClientPool;
private FileNameGenerator fileNameGenerator = new DefaultFileNameGenerator();
private File temporaryBufferFolderFile;
private Resource temporaryBufferFolder = new FileSystemResource(SystemUtils.getJavaIoTmpDir());
private String charset;
public FtpSendingMessageHandler() {
}
@@ -58,14 +63,15 @@ public class FtpSendingMessageHandler implements MessageHandler, InitializingBea
public void afterPropertiesSet() throws Exception {
Assert.notNull(ftpClientPool, "'ftpClientPool' must not be null");
Assert.notNull(temporaryBufferFolder, "'temporaryBufferFolder' must not be null");
Assert.notNull(temporaryBufferFolder,
"'temporaryBufferFolder' must not be null");
temporaryBufferFolderFile = this.temporaryBufferFolder.getFile();
}
/* Ugh this needs to be put in a convenient place accessible for all the file:, sftp:, and ftp:* adapters */
private File handleFileMessage(File sourceFile, File tempFile, File resultFile)
throws IOException {
private File handleFileMessage(File sourceFile, File tempFile,
File resultFile) throws IOException {
if (sourceFile.renameTo(resultFile)) {
return resultFile;
}
@@ -76,28 +82,24 @@ public class FtpSendingMessageHandler implements MessageHandler, InitializingBea
return resultFile;
}
private File handleByteArrayMessage(byte[] bytes, File tempFile, File resultFile)
throws IOException {
private File handleByteArrayMessage(byte[] bytes, File tempFile,
File resultFile) throws IOException {
FileCopyUtils.copy(bytes, tempFile);
tempFile.renameTo(resultFile);
return resultFile;
}
private File handleStringMessage(String content, File tempFile, File resultFile, String charset)
throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile), charset);
private File handleStringMessage(String content, File tempFile,
File resultFile, String charset) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(
tempFile), charset);
FileCopyUtils.copy(content, writer);
tempFile.renameTo(resultFile);
return resultFile;
}
private static final String TEMPORARY_FILE_SUFFIX = ".writing";
private FileNameGenerator fileNameGenerator = new DefaultFileNameGenerator();
private File temporaryBufferFolderFile;
private Resource temporaryBufferFolder = new FileSystemResource(SystemUtils.getJavaIoTmpDir());
public void setTemporaryBufferFolder(Resource temporaryBufferFolder) {
this.temporaryBufferFolder = temporaryBufferFolder;
}
@@ -106,39 +108,45 @@ public class FtpSendingMessageHandler implements MessageHandler, InitializingBea
this.fileNameGenerator = fileNameGenerator;
}
private File redeemForStorableFile(Message<?> msg) throws MessageDeliveryException {
private File redeemForStorableFile(Message<?> msg)
throws MessageDeliveryException {
try {
Object payload = msg.getPayload();
String generateFileName = this.fileNameGenerator.generateFileName(msg);
File tempFile = new File(temporaryBufferFolderFile, generateFileName + TEMPORARY_FILE_SUFFIX);
File resultFile = new File(temporaryBufferFolderFile, generateFileName);
File tempFile = new File(temporaryBufferFolderFile,
generateFileName + TEMPORARY_FILE_SUFFIX);
File resultFile = new File(temporaryBufferFolderFile,
generateFileName);
File sendableFile;
if (payload instanceof String)
sendableFile = this.handleStringMessage((String) payload, tempFile, resultFile, this.charset);
else if (payload instanceof File)
sendableFile = this.handleFileMessage((File) payload, tempFile, resultFile);
else if (payload instanceof byte[])
sendableFile = this.handleByteArrayMessage((byte[]) payload, tempFile, resultFile);
else sendableFile = null;
if (payload instanceof String) {
sendableFile = this.handleStringMessage((String) payload,
tempFile, resultFile, this.charset);
} else if (payload instanceof File) {
sendableFile = this.handleFileMessage((File) payload, tempFile,
resultFile);
} else if (payload instanceof byte[]) {
sendableFile = this.handleByteArrayMessage((byte[]) payload,
tempFile, resultFile);
} else {
sendableFile = null;
}
return sendableFile;
} catch (Throwable th) {
throw new MessageDeliveryException(msg);
}
}
private String charset;
public void setCharset(String charset) {
this.charset = charset;
}
/* Ugh this needs to be put in a convenient place accessible for all the file:, sftp:, and ftp:* adapters */
public void handleMessage(Message<?> message) throws MessageRejectedException,
MessageHandlingException, MessageDeliveryException {
public void handleMessage(Message<?> message)
throws MessageRejectedException, MessageHandlingException,
MessageDeliveryException {
Assert.notNull(message, "'message' must not be null");
Object payload = message.getPayload();
@@ -155,29 +163,36 @@ public class FtpSendingMessageHandler implements MessageHandler, InitializingBea
client = getFtpClient();
sentSuccesfully = sendFile(file, client);
} catch (FileNotFoundException e) {
throw new MessageDeliveryException(message, "File [" + file + "] not found in local working directory; it was moved or deleted unexpectedly", e);
throw new MessageDeliveryException(message,
"File [" + file +
"] not found in local working directory; it was moved or deleted unexpectedly",
e);
} catch (IOException e) {
throw new MessageDeliveryException(message, "Error transferring file [" + file + "] from local working directory to remote FTP directory", e);
throw new MessageDeliveryException(message,
"Error transferring file [" + file +
"] from local working directory to remote FTP directory", e);
} catch (Exception e) {
throw new MessageDeliveryException(message, "Error handling message for file [" + file + "]", e);
throw new MessageDeliveryException(message,
"Error handling message for file [" + file + "]", e);
} finally {
if (file.exists())
if (file.exists()) {
try {
file.delete();
} catch (Throwable th) {
/// noop
}
}
if (client != null) {
ftpClientPool.releaseClient(client);
}
}
if (!sentSuccesfully) {
throw new MessageDeliveryException(message, "Failed to store file '" + file + "'");
throw new MessageDeliveryException(message,
"Failed to store file '" + file + "'");
}
}
}
private boolean sendFile(File file, FTPClient client)
@@ -192,7 +207,9 @@ public class FtpSendingMessageHandler implements MessageHandler, InitializingBea
private FTPClient getFtpClient() throws SocketException, IOException {
FTPClient client;
client = this.ftpClientPool.getClient();
Assert.state(client != null, FtpClientPool.class.getSimpleName() + " returned 'null' client this most likely a bug in the pool implementation.");
Assert.state(client != null,
FtpClientPool.class.getSimpleName() +
" returned 'null' client this most likely a bug in the pool implementation.");
return client;
}

View File

@@ -15,24 +15,27 @@ import org.springframework.core.io.ResourceLoader;
*
* @author Josh Long
*/
public class FtpSendingMessageHandlerFactoryBean extends AbstractFactoryBean<FtpSendingMessageHandler> implements ResourceLoaderAware, ApplicationContextAware {
public class FtpSendingMessageHandlerFactoryBean extends AbstractFactoryBean<FtpSendingMessageHandler>
implements ResourceLoaderAware, ApplicationContextAware {
protected int port;
protected String username;
protected String password;
protected String host;
protected String remoteDirectory;
private String charset;
protected int clientMode;
public void setFileType(int fileType) {
this.fileType = fileType;
}
private int fileType ;
// private vars
private ResourceLoader resourceLoader;
private int fileType;
private ResourceLoader resourceLoader;
private ApplicationContext applicationContext;
public void setCharset(String charset) {
this.charset = charset;
}
public void setFileType(int fileType) {
this.fileType = fileType;
}
public void setClientMode(int clientMode) {
this.clientMode = clientMode;
}
@@ -52,7 +55,9 @@ public class FtpSendingMessageHandlerFactoryBean extends AbstractFactoryBean<Ftp
}
protected AbstractFtpClientFactory clientFactory() {
return ClientFactorySupport.ftpClientFactory( this.host, this.port , this.remoteDirectory , this.username , this.password , this.clientMode, this.fileType );
return ClientFactorySupport.ftpClientFactory(this.host, this.port,
this.remoteDirectory, this.username, this.password,
this.clientMode, this.fileType);
}
@Override
@@ -62,10 +67,11 @@ public class FtpSendingMessageHandlerFactoryBean extends AbstractFactoryBean<Ftp
// they only require an instance of the pool
AbstractFtpClientFactory defaultFtpClientFactory = clientFactory();
QueuedFtpClientPool queuedFtpClientPool = new QueuedFtpClientPool(15, defaultFtpClientFactory);
QueuedFtpClientPool queuedFtpClientPool = new QueuedFtpClientPool(15,
defaultFtpClientFactory);
FtpSendingMessageHandler ftpSendingMessageHandler = new FtpSendingMessageHandler(queuedFtpClientPool);
ftpSendingMessageHandler.setCharset( this.charset);
ftpSendingMessageHandler.afterPropertiesSet();
return ftpSendingMessageHandler;

View File

@@ -0,0 +1,100 @@
package org.springframework.integration.ftp;
import org.apache.commons.net.ftp.FTPClient;
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
/**
* Factory to make building the namespace easier
*
* @author Josh Long
*/
public class FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean
extends FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean {
/**
* Sets whether the connection is implicit. Local testing reveals this to be a good choice.
*/
protected volatile Boolean implicit = Boolean.FALSE;
/**
* "TLS" or "SSL"
*/
protected volatile String protocol;
/**
* "P"
*/
protected volatile String prot;
private KeyManager keyManager;
private TrustManager trustManager;
protected volatile String authValue;
private Boolean sessionCreation;
private Boolean useClientMode;
private Boolean needClientAuth;
private Boolean wantsClientAuth;
private String[] cipherSuites;
public FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean() {
this.defaultFtpInboundFolderName = "ftpsInbound";
this.clientMode = FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE;
}
public void setKeyManager(KeyManager keyManager) {
this.keyManager = keyManager;
}
public void setTrustManager(TrustManager trustManager) {
this.trustManager = trustManager;
}
public void setImplicit(Boolean implicit) {
this.implicit = implicit;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public void setProt(String prot) {
this.prot = prot;
}
public void setAuthValue(String authValue) {
this.authValue = authValue;
}
public void setSessionCreation(Boolean sessionCreation) {
this.sessionCreation = sessionCreation;
}
public void setUseClientMode(Boolean useClientMode) {
this.useClientMode = useClientMode;
}
public void setNeedClientAuth(Boolean needClientAuth) {
this.needClientAuth = needClientAuth;
}
public void setWantsClientAuth(Boolean wantsClientAuth) {
this.wantsClientAuth = wantsClientAuth;
}
protected AbstractFtpClientFactory defaultClientFactory()
throws Exception {
DefaultFtpsClientFactory factory = ClientFactorySupport.ftpsClientFactory(this.host,
Integer.parseInt(this.port), this.remoteDirectory,
this.username, this.password, this.fileType, this.clientMode,
this.prot, this.protocol, this.authValue, this.implicit,
this.trustManager, this.keyManager, this.sessionCreation,
this.useClientMode, this.wantsClientAuth, this.needClientAuth,
this.cipherSuites);
return factory;
}
public void setCipherSuites(String[] cipherSuites) {
this.cipherSuites = cipherSuites;
}
}

View File

@@ -3,32 +3,32 @@ package org.springframework.integration.ftp;
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
public class FtpsSendingMessageHandlerFactoryBean extends FtpSendingMessageHandlerFactoryBean {
public class FtpsSendingMessageHandlerFactoryBean
extends FtpSendingMessageHandlerFactoryBean {
/**
* Sets whether the connection is implicit. Local testing reveals this to be a good choice.
*/
protected volatile Boolean implicit = Boolean.FALSE;
* Sets whether the connection is implicit. Local testing reveals this to be a good choice.
*/
protected volatile Boolean implicit = Boolean.FALSE;
/**
* "TLS" or "SSL"
*/
protected volatile String protocol;
/**
* "TLS" or "SSL"
*/
protected volatile String protocol;
/**
* "P"
*/
protected volatile String prot;
private KeyManager keyManager;
private TrustManager trustManager;
protected volatile String authValue;
private Boolean sessionCreation;
private Boolean useClientMode;
private Boolean needClientAuth;
private Boolean wantsClientAuth;
private String[] cipherSuites;
/**
* "P"
*/
protected volatile String prot;
private KeyManager keyManager;
private TrustManager trustManager;
protected volatile String authValue;
private Boolean sessionCreation;
private Boolean useClientMode;
private Boolean needClientAuth;
private Boolean wantsClientAuth;
private String[] cipherSuites;
private int fileType;
public void setImplicit(Boolean implicit) {
this.implicit = implicit;
@@ -74,18 +74,19 @@ public class FtpsSendingMessageHandlerFactoryBean extends FtpSendingMessageHandl
this.cipherSuites = cipherSuites;
}
private int fileType ;
public void setFileType(int fileType) {
this.fileType = fileType;
}
@Override
protected AbstractFtpClientFactory clientFactory() {
DefaultFtpsClientFactory factory = ClientFactorySupport.ftpsClientFactory(
this.host, (this.port), this.remoteDirectory, this.username, this.password, this.fileType,
this.clientMode, this.prot, this.protocol, this.authValue, this.implicit, this.trustManager, this.keyManager, this.sessionCreation, this.useClientMode, this.wantsClientAuth,
this.needClientAuth, this.cipherSuites);
DefaultFtpsClientFactory factory = ClientFactorySupport.ftpsClientFactory(this.host,
(this.port), this.remoteDirectory, this.username,
this.password, this.fileType, this.clientMode, this.prot,
this.protocol, this.authValue, this.implicit,
this.trustManager, this.keyManager, this.sessionCreation,
this.useClientMode, this.wantsClientAuth, this.needClientAuth,
this.cipherSuites);
return factory;
}

View File

@@ -4,6 +4,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.ftp.FtpSendingMessageHandlerFactoryBean;
import org.w3c.dom.Element;
@@ -13,13 +14,18 @@ import org.w3c.dom.Element;
*
* @author Josh Long
*/
public class FtpMessageSendingConsumerBeanDefinitionParser extends AbstractOutboundChannelAdapterParser {
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FtpSendingMessageHandlerFactoryBean.class.getName());
public class FtpMessageSendingConsumerBeanDefinitionParser
extends AbstractOutboundChannelAdapterParser {
@Override
protected AbstractBeanDefinition parseConsumer(Element element,
ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
FtpSendingMessageHandlerFactoryBean.class.getName());
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder,element,"charset");
FtpNamespaceParserSupport.configureCoreFtpClient(builder, element, parserContext);
FtpNamespaceParserSupport.configureCoreFtpClient(builder, element,
parserContext);
return builder.getBeanDefinition();
}
return builder.getBeanDefinition();
}
}

View File

@@ -3,11 +3,9 @@ package org.springframework.integration.ftp.config;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.ftp.impl.FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean;
import org.springframework.integration.ftp.FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean;
import org.w3c.dom.Element;
import java.util.Arrays;
@@ -20,21 +18,28 @@ import java.util.Set;
*
* @author Josh Long
*/
public class FtpMessageSourceBeanDefinitionParser extends AbstractPollingInboundChannelAdapterParser {
private Set<String> receiveAttrs = new HashSet<String>(Arrays.asList("auto-delete-remote-files-on-sync,filename-pattern,local-working-directory".split(",")));
public class FtpMessageSourceBeanDefinitionParser
extends AbstractPollingInboundChannelAdapterParser {
private Set<String> receiveAttrs = new HashSet<String>(Arrays.asList(
"auto-delete-remote-files-on-sync,filename-pattern,local-working-directory".split(
",")));
@Override
@SuppressWarnings("unused")
protected String parseSource(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.class.getName());
@Override
@SuppressWarnings("unused")
protected String parseSource(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.class.getName());
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "filter");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder,
element, "filter");
for (String a : receiveAttrs)
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, a);
for (String a : receiveAttrs)
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder,
element, a);
FtpNamespaceParserSupport.configureCoreFtpClient(builder, element, parserContext);
FtpNamespaceParserSupport.configureCoreFtpClient(builder, element,
parserContext);
return BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
}
return BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(),
parserContext.getRegistry());
}
}

View File

@@ -36,9 +36,9 @@ public class FtpNamespaceHandler extends NamespaceHandlerSupport {
static {
// file types
FILE_TYPES.put("ebcdic-file-type" , FTP.EBCDIC_FILE_TYPE);
FILE_TYPES.put("ascii-file-type" , FTP.ASCII_FILE_TYPE);
FILE_TYPES.put("binary-file-type" , FTP.BINARY_FILE_TYPE);
FILE_TYPES.put("ebcdic-file-type", FTP.EBCDIC_FILE_TYPE);
FILE_TYPES.put("ascii-file-type", FTP.ASCII_FILE_TYPE);
FILE_TYPES.put("binary-file-type", FTP.BINARY_FILE_TYPE);
// client modes
CLIENT_MODES.put("active-local-data-connection-mode", 0);
@@ -48,7 +48,9 @@ public class FtpNamespaceHandler extends NamespaceHandlerSupport {
}
public void init() {
registerBeanDefinitionParser("inbound-channel-adapter", new FtpMessageSourceBeanDefinitionParser());
registerBeanDefinitionParser("outbound-channel-adapter", new FtpMessageSendingConsumerBeanDefinitionParser());
registerBeanDefinitionParser("inbound-channel-adapter",
new FtpMessageSourceBeanDefinitionParser());
registerBeanDefinitionParser("outbound-channel-adapter",
new FtpMessageSendingConsumerBeanDefinitionParser());
}
}

View File

@@ -10,29 +10,33 @@ import org.w3c.dom.Element;
* A lot of parsers need to support the same set of core attributes, so I'm hiding that logic here
*
* @author Josh Long
*
*/
public class FtpNamespaceParserSupport {
/**
* lots of values are supported across all adapters, let this code handle it initially
*
* @param builder a builder
* @param element an element
* @param parserContext a parser context
*/
public static void configureCoreFtpClient(BeanDefinitionBuilder builder, Element element, ParserContext parserContext) {
for (String p : "auto-create-directories,username,port,password,host,remote-directory".split(",")) {
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, p);
}
/**
* lots of values are supported across all adapters, let this code handle it initially
*
* @param builder a builder
* @param element an element
* @param parserContext a parser context
*/
public static void configureCoreFtpClient(BeanDefinitionBuilder builder,
Element element, ParserContext parserContext) {
for (String p : "auto-create-directories,username,port,password,host,remote-directory".split(
",")) {
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder,
element, p);
}
if (element.hasAttribute("file-type")) {
int fileType = FtpNamespaceHandler.FILE_TYPES.get(element.getAttribute("file-type"));
builder.addPropertyValue("fileType", fileType);
}
if (element.hasAttribute("file-type")) {
int fileType = FtpNamespaceHandler.FILE_TYPES.get(element.getAttribute(
"file-type"));
builder.addPropertyValue("fileType", fileType);
}
if (element.hasAttribute("client-mode")) {
int clientMode = FtpNamespaceHandler.CLIENT_MODES.get(element.getAttribute("client-mode"));
builder.addPropertyValue("clientMode", clientMode);
}
}
if (element.hasAttribute("client-mode")) {
int clientMode = FtpNamespaceHandler.CLIENT_MODES.get(element.getAttribute(
"client-mode"));
builder.addPropertyValue("clientMode", clientMode);
}
}
}

View File

@@ -4,7 +4,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
import org.springframework.integration.ftp.FtpSendingMessageHandlerFactoryBean;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.ftp.FtpsSendingMessageHandlerFactoryBean;
import org.w3c.dom.Element;
@@ -14,13 +14,20 @@ import org.w3c.dom.Element;
*
* @author Josh Long
*/
public class FtpsMessageSendingConsumerBeanDefinitionParser extends AbstractOutboundChannelAdapterParser {
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FtpsSendingMessageHandlerFactoryBean.class.getName());
public class FtpsMessageSendingConsumerBeanDefinitionParser
extends AbstractOutboundChannelAdapterParser {
@Override
protected AbstractBeanDefinition parseConsumer(Element element,
ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
FtpsSendingMessageHandlerFactoryBean.class.getName());
FtpNamespaceParserSupport.configureCoreFtpClient(builder, element, parserContext);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder,element,"charset");
return builder.getBeanDefinition();
}
FtpNamespaceParserSupport.configureCoreFtpClient(builder, element,
parserContext);
return builder.getBeanDefinition();
}
}

View File

@@ -5,8 +5,7 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.ftp.impl.FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean;
import org.springframework.integration.ftp.impl.FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean;
import org.springframework.integration.ftp.FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean;
import org.w3c.dom.Element;
import java.util.Arrays;
@@ -19,21 +18,28 @@ import java.util.Set;
*
* @author Josh Long
*/
public class FtpsMessageSourceBeanDefinitionParser extends AbstractPollingInboundChannelAdapterParser {
private Set<String> receiveAttrs = new HashSet<String>(Arrays.asList("auto-delete-remote-files-on-sync,filename-pattern,local-working-directory".split(",")));
public class FtpsMessageSourceBeanDefinitionParser
extends AbstractPollingInboundChannelAdapterParser {
private Set<String> receiveAttrs = new HashSet<String>(Arrays.asList(
"auto-delete-remote-files-on-sync,filename-pattern,local-working-directory".split(
",")));
@Override
@SuppressWarnings("unused")
protected String parseSource(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean.class.getName());
@Override
@SuppressWarnings("unused")
protected String parseSource(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean.class.getName());
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "filter");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder,
element, "filter");
for (String a : receiveAttrs)
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, a);
for (String a : receiveAttrs)
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder,
element, a);
FtpNamespaceParserSupport.configureCoreFtpClient(builder, element, parserContext);
FtpNamespaceParserSupport.configureCoreFtpClient(builder, element,
parserContext);
return BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
}
return BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(),
parserContext.getRegistry());
}
}

View File

@@ -15,22 +15,23 @@
*/
package org.springframework.integration.ftp.config;
/**
* Provides namespace support for using FTP
* <p/>
* This is *heavily* influenced by the good work done by Iwein before.
*
*
* @author Josh Long
*/
@SuppressWarnings("unused")
public class FtpsNamespaceHandler extends FtpNamespaceHandler {
@Override
public void init() {
this.registerBeanDefinitionParser( "inbound-channel-adapter", new FtpsMessageSourceBeanDefinitionParser());
this.registerBeanDefinitionParser("inbound-channel-adapter",
new FtpsMessageSourceBeanDefinitionParser());
// todo test this
this.registerBeanDefinitionParser( "outbound-channel-adapter", new FtpsMessageSendingConsumerBeanDefinitionParser());
this.registerBeanDefinitionParser("outbound-channel-adapter",
new FtpsMessageSendingConsumerBeanDefinitionParser());
}
}

View File

@@ -1,116 +0,0 @@
package org.springframework.integration.ftp.impl;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor;
import org.springframework.core.io.ResourceLoader;
import org.springframework.integration.file.entries.CompositeEntryListFilter;
import org.springframework.integration.file.entries.EntryListFilter;
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
import org.springframework.integration.ftp.*;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.IOException;
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
/**
* Factory to make building the namespace easier
*
* @author Josh Long
*/
public class FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean extends FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean {
/**
* Sets whether the connection is implicit. Local testing reveals this to be a good choice.
*/
protected volatile Boolean implicit = Boolean.FALSE;
/**
* "TLS" or "SSL"
*/
protected volatile String protocol;
/**
* "P"
*/
protected volatile String prot;
private KeyManager keyManager;
private TrustManager trustManager;
protected volatile String authValue;
private Boolean sessionCreation;
private Boolean useClientMode;
private Boolean needClientAuth;
private Boolean wantsClientAuth;
private String[] cipherSuites;
public FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean() {
this.defaultFtpInboundFolderName = "ftpsInbound";
this.clientMode = FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE;
}
public void setKeyManager(KeyManager keyManager) {
this.keyManager = keyManager;
}
public void setTrustManager(TrustManager trustManager) {
this.trustManager = trustManager;
}
public void setImplicit(Boolean implicit) {
this.implicit = implicit;
}
public void setProtocol(String protocol) {
this.protocol = protocol;
}
public void setProt(String prot) {
this.prot = prot;
}
public void setAuthValue(String authValue) {
this.authValue = authValue;
}
public void setSessionCreation(Boolean sessionCreation) {
this.sessionCreation = sessionCreation;
}
public void setUseClientMode(Boolean useClientMode) {
this.useClientMode = useClientMode;
}
public void setNeedClientAuth(Boolean needClientAuth) {
this.needClientAuth = needClientAuth;
}
public void setWantsClientAuth(Boolean wantsClientAuth) {
this.wantsClientAuth = wantsClientAuth;
}
protected AbstractFtpClientFactory defaultClientFactory()
throws Exception {
DefaultFtpsClientFactory factory = ClientFactorySupport.ftpsClientFactory(this.host, Integer.parseInt(this.port), this.remoteDirectory, this.username, this.password, this.fileType,
this.clientMode, this.prot, this.protocol, this.authValue, this.implicit, this.trustManager, this.keyManager, this.sessionCreation, this.useClientMode, this.wantsClientAuth,
this.needClientAuth, this.cipherSuites);
return factory;
}
public void setCipherSuites(String[] cipherSuites) {
this.cipherSuites = cipherSuites;
}
}