From 8e6a1f2b29968bd43f602ca28f6ac62d93c7a10a Mon Sep 17 00:00:00 2001 From: Josh Long Date: Mon, 4 Oct 2010 01:17:58 -0700 Subject: [PATCH] fixing an issue with charsets in the FTP namespace parser support int-950 --- .../ftp/AbstractFtpClientFactory.java | 18 +- .../integration/ftp/ClientFactorySupport.java | 123 +++++---- .../ftp/DefaultFtpsClientFactory.java | 251 ++++++++---------- .../integration/ftp/FtpClientFactory.java | 2 +- ...tpInboundRemoteFileSystemSynchronizer.java | 26 +- ...eFileSystemSynchronizingMessageSource.java | 13 +- ...SynchronizingMessageSourceFactoryBean.java | 34 ++- .../ftp/FtpSendingMessageHandler.java | 101 ++++--- .../FtpSendingMessageHandlerFactoryBean.java | 32 ++- ...SynchronizingMessageSourceFactoryBean.java | 100 +++++++ .../FtpsSendingMessageHandlerFactoryBean.java | 59 ++-- ...geSendingConsumerBeanDefinitionParser.java | 20 +- .../FtpMessageSourceBeanDefinitionParser.java | 35 +-- .../ftp/config/FtpNamespaceHandler.java | 12 +- .../ftp/config/FtpNamespaceParserSupport.java | 46 ++-- ...geSendingConsumerBeanDefinitionParser.java | 23 +- ...FtpsMessageSourceBeanDefinitionParser.java | 34 ++- .../ftp/config/FtpsNamespaceHandler.java | 9 +- ...SynchronizingMessageSourceFactoryBean.java | 116 -------- 19 files changed, 542 insertions(+), 512 deletions(-) rename spring-integration-ftp/src/main/java/org/springframework/integration/ftp/{impl => }/FtpInboundRemoteFileSystemSynchronizer.java (81%) rename spring-integration-ftp/src/main/java/org/springframework/integration/ftp/{impl => }/FtpInboundRemoteFileSystemSynchronizingMessageSource.java (72%) rename spring-integration-ftp/src/main/java/org/springframework/integration/ftp/{impl => }/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java (88%) create mode 100644 spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean.java delete mode 100644 spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean.java diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/AbstractFtpClientFactory.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/AbstractFtpClientFactory.java index bbad3735fd..e994d3db2d 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/AbstractFtpClientFactory.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/AbstractFtpClientFactory.java @@ -14,7 +14,8 @@ import java.io.IOException; import java.net.SocketException; -abstract public class AbstractFtpClientFactory implements FtpClientFactory { +abstract public class AbstractFtpClientFactory + implements FtpClientFactory { 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 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 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 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; diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/ClientFactorySupport.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/ClientFactorySupport.java index 0140ded251..bebc257bde 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/ClientFactorySupport.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/ClientFactorySupport.java @@ -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; + } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/DefaultFtpsClientFactory.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/DefaultFtpsClientFactory.java index 9a7d539ce0..6156cf3c06 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/DefaultFtpsClientFactory.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/DefaultFtpsClientFactory.java @@ -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 { - 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); + } + } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpClientFactory.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpClientFactory.java index 472c25d12a..31a1ff00e7 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpClientFactory.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpClientFactory.java @@ -25,7 +25,7 @@ import java.io.IOException; * * @author Iwein Fuld */ -public interface FtpClientFactory { +public interface FtpClientFactory { /** * @return Fully configured and connected FTPClient. Never null. * @throws IOException thrown when a networking IO subsystem error occurs diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpInboundRemoteFileSystemSynchronizer.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpInboundRemoteFileSystemSynchronizer.java similarity index 81% rename from spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpInboundRemoteFileSystemSynchronizer.java rename to spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpInboundRemoteFileSystemSynchronizer.java index 2b9cfc1c19..eefa39bf0e 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpInboundRemoteFileSystemSynchronizer.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpInboundRemoteFileSystemSynchronizer.java @@ -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 { +public class FtpInboundRemoteFileSystemSynchronizer + extends AbstractInboundRemoteFileSystemSychronizer { 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 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()); diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpInboundRemoteFileSystemSynchronizingMessageSource.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpInboundRemoteFileSystemSynchronizingMessageSource.java similarity index 72% rename from spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpInboundRemoteFileSystemSynchronizingMessageSource.java rename to spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpInboundRemoteFileSystemSynchronizingMessageSource.java index 8367f92d8d..d42bac6770 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpInboundRemoteFileSystemSynchronizingMessageSource.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpInboundRemoteFileSystemSynchronizingMessageSource.java @@ -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 { +public class FtpInboundRemoteFileSystemSynchronizingMessageSource + extends AbstractInboundRemoteFileSystemSynchronizingMessageSource { 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"; } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java similarity index 88% rename from spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java rename to spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java index 91d8aee891..0767252fd9 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java @@ -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 implements ResourceLoaderAware { +public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean + extends AbstractFactoryBean + 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 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 compositeFtpFileListFilter = new CompositeEntryListFilter(); if (StringUtils.hasText(this.filenamePattern)) { - PatternMatchingEntryListFilter ftpFilePatternMatchingEntryListFilter = new PatternMatchingEntryListFilter(ftpFileEntryNamer, filenamePattern); + PatternMatchingEntryListFilter ftpFilePatternMatchingEntryListFilter = + new PatternMatchingEntryListFilter(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); diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandler.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandler.java index f6cd54ea07..fbd915bc00 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandler.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandler.java @@ -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; } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandlerFactoryBean.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandlerFactoryBean.java index 603175e8b3..017e9b490e 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandlerFactoryBean.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandlerFactoryBean.java @@ -15,24 +15,27 @@ import org.springframework.core.io.ResourceLoader; * * @author Josh Long */ -public class FtpSendingMessageHandlerFactoryBean extends AbstractFactoryBean implements ResourceLoaderAware, ApplicationContextAware { +public class FtpSendingMessageHandlerFactoryBean extends AbstractFactoryBean + 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 receiveAttrs = new HashSet(Arrays.asList("auto-delete-remote-files-on-sync,filename-pattern,local-working-directory".split(","))); +public class FtpMessageSourceBeanDefinitionParser + extends AbstractPollingInboundChannelAdapterParser { + private Set receiveAttrs = new HashSet(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()); + } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java index c44fade980..bfc455203d 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java @@ -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()); } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceParserSupport.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceParserSupport.java index 3564747110..9b1fb98640 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceParserSupport.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceParserSupport.java @@ -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); + } + } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsMessageSendingConsumerBeanDefinitionParser.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsMessageSendingConsumerBeanDefinitionParser.java index 9506fd0bd8..9b096ca8da 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsMessageSendingConsumerBeanDefinitionParser.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsMessageSendingConsumerBeanDefinitionParser.java @@ -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(); + } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsMessageSourceBeanDefinitionParser.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsMessageSourceBeanDefinitionParser.java index 1bf8481d7c..4a790a44d9 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsMessageSourceBeanDefinitionParser.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsMessageSourceBeanDefinitionParser.java @@ -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 receiveAttrs = new HashSet(Arrays.asList("auto-delete-remote-files-on-sync,filename-pattern,local-working-directory".split(","))); +public class FtpsMessageSourceBeanDefinitionParser + extends AbstractPollingInboundChannelAdapterParser { + private Set receiveAttrs = new HashSet(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()); + } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsNamespaceHandler.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsNamespaceHandler.java index cfa64598b5..5d98313cf8 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsNamespaceHandler.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpsNamespaceHandler.java @@ -15,22 +15,23 @@ */ package org.springframework.integration.ftp.config; + /** * Provides namespace support for using FTP *

* 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()); } } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean.java deleted file mode 100644 index 76dfa16115..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpsRemoteFileSystemSynchronizingMessageSourceFactoryBean.java +++ /dev/null @@ -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; - } -}