diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/DefaultFtpClientFactory.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/DefaultFtpClientFactory.java deleted file mode 100644 index 1a477925df..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/DefaultFtpClientFactory.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.integration.ftp; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.commons.net.ftp.FTP; -import org.apache.commons.net.ftp.FTPClient; -import org.apache.commons.net.ftp.FTPClientConfig; -import org.apache.commons.net.ftp.FTPReply; -import org.springframework.integration.MessagingException; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -import java.io.IOException; -import java.net.SocketException; - - -/** - * Default implementation of FtpClientFactory. - * - * @author iwein - */ -public class DefaultFtpClientFactory implements FtpClientFactory { - private static final Log logger = LogFactory.getLog(FtpClientFactory.class); - private static final String DEFAULT_REMOTE_WORKING_DIRECTORY = "/"; - private FTPClientConfig config; - private String username; - private String host; - private int port = FTP.DEFAULT_PORT; - private String password; - private String remoteWorkingDirectory = DEFAULT_REMOTE_WORKING_DIRECTORY; - private int clientMode = FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE; - - public void setConfig(FTPClientConfig config) { - Assert.notNull(config); - this.config = config; - } - - public void setHost(String host) { - Assert.hasText(host); - this.host = host; - } - - public void setPort(int port) { - Assert.isTrue(port > 0, "Port number should be > 0"); - this.port = port; - } - - public void setUsername(String user) { - Assert.hasText(user, "'user' should be a nonempty string"); - this.username = user; - } - - public void setPassword(String pass) { - Assert.notNull(pass, "password should not be null"); - this.password = pass; - } - - public void setRemoteWorkingDirectory(String remoteWorkingDirectory) { - Assert.notNull(remoteWorkingDirectory, "remote directory should not be null"); - this.remoteWorkingDirectory = remoteWorkingDirectory.replaceAll("^$", "/"); - } - - /** - * Set client mode for example - * FTPClient.ACTIVE_LOCAL_CONNECTION_MODE (default) Only local - * modes are supported. - */ - public void setClientMode(int clientMode) { - this.clientMode = clientMode; - } - - public FTPClient getClient() throws SocketException, IOException { - FTPClient client = new FTPClient(); - client.configure(config); - - if (!StringUtils.hasText(username)) { - throw new MessagingException("username is required"); - } - - client.connect(host, port); - setClientMode(client); - - if (!FTPReply.isPositiveCompletion(client.getReplyCode())) { - throw new MessagingException("Connecting to server [" + host + ":" + port + "] failed, please check the connection"); - } - - if (logger.isDebugEnabled()) { - logger.debug("Connected to server [" + host + ":" + port + "]"); - } - - if (!client.login(username, password)) { - throw new MessagingException("Login failed. Please check the username and password."); - } - - if (logger.isDebugEnabled()) { - logger.debug("login successful"); - } - - client.setFileType(FTP.BINARY_FILE_TYPE); - - 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()); - } - - return client; - } - - /** - * Sets the mode of the connection. Only local modes are supported. - */ - private void setClientMode(FTPClient client) { - switch (clientMode) { - case FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE: - client.enterLocalActiveMode(); - - break; - - case FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE: - client.enterLocalPassiveMode(); - - break; - - default: - break; - } - } -} 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 deleted file mode 100644 index afceb56ce2..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpClientFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.integration.ftp; - -import org.apache.commons.net.ftp.FTPClient; - -import java.io.IOException; - - -/** - * Factory for {@link FTPClient}. - * - * @author Iwein Fuld - */ -public interface FtpClientFactory { - /** - * @return Fully configured and connected FTPClient. Never null. - * @throws IOException thrown when a networking IO subsystem error occurs - */ - FTPClient getClient() throws IOException; -} diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpClientPool.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpClientPool.java deleted file mode 100644 index e8d540c6f2..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpClientPool.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.integration.ftp; - -import org.apache.commons.net.ftp.FTPClient; - - -/** - * A pool of {@link FTPClient} instances. The pool can be used to control the - * number of open FTP connections and reuse these connections efficiently. - * - * @author Iwein Fuld - */ -public interface FtpClientPool extends FtpClientFactory { - /** - * Releases the client back to the pool. When calling this method the caller - * is no longer responsible for the connection. The pool is free to do with - * it as it sees fit, which means either recycling or disconnecting it most - * probably. - *

- * The caller should NOT disconnect the client before calling this method. - *

- * The caller is NOT expected to use the client after calling this method. - * Doing so can lead to unexpected behavior. - * - * @param client the {@link FTPClient} to release. Implementations of this - * method are recommended to deal gracefully with a null - * argument, although the endpoint implementations in - * org.springframework.integration.ftp will never pass in - * null. - */ - void releaseClient(FTPClient client); -} diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpFileEntryNamer.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpFileEntryNamer.java deleted file mode 100644 index e511efac4d..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpFileEntryNamer.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.springframework.integration.ftp; - -import org.apache.commons.net.ftp.FTPFile; - -import org.springframework.integration.file.entries.EntryNamer; - - -/** - * A {@link org.springframework.integration.file.entries.EntryNamer} for {@link org.apache.commons.net.ftp.FTPFile} objects - * - * @author Josh Long - */ -public class FtpFileEntryNamer implements EntryNamer { - public String nameOf(FTPFile entry) { - return entry.getName(); - } -} 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 deleted file mode 100644 index b2b9ad0dc4..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandler.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.integration.ftp; - -import org.apache.commons.lang.SystemUtils; -import org.apache.commons.net.ftp.FTPClient; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.core.io.FileSystemResource; -import org.springframework.core.io.Resource; -import org.springframework.integration.Message; -import org.springframework.integration.MessageDeliveryException; -import org.springframework.integration.MessageHandlingException; -import org.springframework.integration.MessageRejectedException; -import org.springframework.integration.core.MessageHandler; -import org.springframework.integration.file.DefaultFileNameGenerator; -import org.springframework.integration.file.FileNameGenerator; -import org.springframework.util.Assert; -import org.springframework.util.FileCopyUtils; - -import java.io.*; -import java.net.SocketException; - - -/** - * A {@link org.springframework.integration.core.MessageHandler} implementation that sends files to an FTP server. - * - * @author Iwein Fuld - * @author Mark Fisher - */ -public class FtpSendingMessageHandler implements MessageHandler, InitializingBean { - private FtpClientPool ftpClientPool; - - public FtpSendingMessageHandler() { - } - - public FtpSendingMessageHandler(FtpClientPool ftpClientPool) { - this.ftpClientPool = ftpClientPool; - } - - public void setFtpClientPool(FtpClientPool ftpClientPool) { - this.ftpClientPool = ftpClientPool; - } - - public void afterPropertiesSet() throws Exception { - Assert.notNull(ftpClientPool, "'ftpClientPool' 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 { - if (sourceFile.renameTo(resultFile)) { - return resultFile; - } - - FileCopyUtils.copy(sourceFile, tempFile); - tempFile.renameTo(resultFile); - - return resultFile; - } - - 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); - 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; - } - - public void setFileNameGenerator(FileNameGenerator fileNameGenerator) { - this.fileNameGenerator = fileNameGenerator; - } - - 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 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; - 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 { - - - Assert.notNull(message, "'message' must not be null"); - - Object payload = message.getPayload(); - - Assert.notNull(payload, "Message payload must not be null"); - - File file = this.redeemForStorableFile(message); - - if ((file != null) && file.exists()) { - FTPClient client = null; - boolean sentSuccesfully; - - try { - 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); - } catch (IOException 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); - } finally { - 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 + "'"); - } - - } - - } - - private boolean sendFile(File file, FTPClient client) - throws FileNotFoundException, IOException { - FileInputStream fileInputStream = new FileInputStream(file); - boolean sent = client.storeFile(file.getName(), fileInputStream); - fileInputStream.close(); - - return sent; - } - - 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."); - - 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 deleted file mode 100644 index bebbff17dc..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageHandlerFactoryBean.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.springframework.integration.ftp; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ResourceLoaderAware; -import org.springframework.core.io.ResourceLoader; - - -/** - * A factory bean implementation that handles constructing an outbound FTP adapter. - * - * @author Josh Long - */ -public class FtpSendingMessageHandlerFactoryBean extends AbstractFactoryBean implements ResourceLoaderAware, ApplicationContextAware { - private int port; - private String username; - private String password; - private String host; - private String remoteDirectory; - private int clientMode; - - // private vars - private ResourceLoader resourceLoader; - private ApplicationContext applicationContext; - - public void setClientMode(int clientMode) { - this.clientMode = clientMode; - } - - public void setResourceLoader(ResourceLoader resourceLoader) { - this.resourceLoader = resourceLoader; - } - - public void setApplicationContext(ApplicationContext applicationContext) - throws BeansException { - this.applicationContext = applicationContext; - } - - @Override - public Class getObjectType() { - return FtpSendingMessageHandler.class; - } - - @Override - protected FtpSendingMessageHandler createInstance() - throws Exception { - // the dependencies for the outbound-adapter are much simpler - // they only require an instance of the pool - DefaultFtpClientFactory defaultFtpClientFactory = new DefaultFtpClientFactory(); - defaultFtpClientFactory.setHost(this.host); - defaultFtpClientFactory.setPassword(this.password); - defaultFtpClientFactory.setPort(this.port); - defaultFtpClientFactory.setRemoteWorkingDirectory(this.remoteDirectory); - defaultFtpClientFactory.setUsername(this.username); - defaultFtpClientFactory.setClientMode(this.clientMode); - - QueuedFtpClientPool queuedFtpClientPool = new QueuedFtpClientPool(15, defaultFtpClientFactory); - - FtpSendingMessageHandler ftpSendingMessageHandler = new FtpSendingMessageHandler(queuedFtpClientPool); - ftpSendingMessageHandler.afterPropertiesSet(); - - return ftpSendingMessageHandler; - } - - public void setPort(int port) { - this.port = port; - } - - public void setUsername(String username) { - this.username = username; - } - - public void setPassword(String password) { - this.password = password; - } - - public void setHost(String host) { - this.host = host; - } - - public void setRemoteDirectory(String remoteDirectory) { - this.remoteDirectory = remoteDirectory; - } -} diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/QueuedFtpClientPool.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/QueuedFtpClientPool.java deleted file mode 100644 index c0b3dab35f..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/QueuedFtpClientPool.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.integration.ftp; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.commons.net.ftp.FTPClient; -import org.springframework.util.Assert; - -import java.io.IOException; -import java.net.SocketException; -import java.util.Queue; -import java.util.concurrent.ArrayBlockingQueue; - - -/** - * FtpClientPool implementation based on a Queue. This implementation has a - * default pool size of 5, but this is configurable with a constructor argument. - *

- * This implementation pools released clients, but gives no guarantee to the - * number of clients open at the same time. - * - * @author Iwein Fuld - */ -public class QueuedFtpClientPool implements FtpClientPool { - private static final Log log = LogFactory.getLog(QueuedFtpClientPool.class); - private static final int DEFAULT_POOL_SIZE = 5; - private final Queue pool; - private final FtpClientFactory factory; - - public QueuedFtpClientPool(FtpClientFactory factory) { - this(DEFAULT_POOL_SIZE, factory); - } - - /** - * @param maxPoolSize the maximum size of the pool - * - */ - public QueuedFtpClientPool(int maxPoolSize, FtpClientFactory factory) { - Assert.notNull(factory); - this.factory = factory; - pool = new ArrayBlockingQueue(maxPoolSize); - } - - /** - * Returns an active FTPClient connected to the configured server. When no - * clients are available in the queue a new client is created with the - * factory. - *

- * It is possible that released clients are disconnected by the remote - * server (@see {@link FTPClient#sendNoOp()}. In this case getClient is - * called recursively to obtain a client that is still alive. For this - * reason large pools are not recommended in poor networking conditions. - */ - public FTPClient getClient() throws SocketException, IOException { - FTPClient client = pool.poll(); - - if (client == null) { - client = factory.getClient(); - } - - return prepareClient(client); - } - - /** - * Prepares the client before it is returned through - * getClient(). The default implementation will check the - * connection using a noOp and replace the client with a new one if it - * encounters a problem. - *

- * In more exotic environments subclasses can override this method to - * implement their own preparation strategy. - * @param client the unprepared client - * @return - * @throws SocketException - * @throws IOException - */ - protected FTPClient prepareClient(FTPClient client) - throws SocketException, IOException { - return isClientAlive(client) ? client : getClient(); - } - - private boolean isClientAlive(FTPClient client) { - try { - if (client.sendNoOp()) { - return true; - } - } catch (IOException e) { - log.warn("Client [" + client + "] discarded: ", e); - } - - return false; - } - - public void releaseClient(FTPClient client) { - if ((client != null) && !pool.offer(client)) { - try { - client.disconnect(); - } catch (IOException e) { - log.warn("Error disconnecting ftpclient", e); - } - } - } -} 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 deleted file mode 100644 index 9ca93523b0..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2010 the original author or authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.integration.ftp.config; - -import org.springframework.beans.factory.support.AbstractBeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; -import org.springframework.beans.factory.xml.NamespaceHandlerSupport; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser; -import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser; -import org.springframework.integration.config.xml.IntegrationNamespaceUtils; -import org.springframework.integration.ftp.FtpSendingMessageHandlerFactoryBean; -import org.springframework.integration.ftp.impl.FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean; -import org.w3c.dom.Element; - -import java.util.HashMap; -import java.util.Map; - - -/** - * Provides namespace support for using FTP - * - * @author Josh Long (*heavily* influenced by the good done by iwein before) - */ -@SuppressWarnings("unused") -public class FtpNamespaceHandler extends NamespaceHandlerSupport { - private static final String PACKAGE_NAME = "org.springframework.integration.ftp"; - static private Map CLIENT_MODES = new HashMap(); - - static { - CLIENT_MODES.put("active-local-data-connection-mode", 0); - CLIENT_MODES.put("active-remote-data-connection-mode", 1); - CLIENT_MODES.put("passive-local-data-connection-mode", 2); - CLIENT_MODES.put("passive-remote-data-connection-mode", 3); - } - - public void init() { - registerBeanDefinitionParser("inbound-channel-adapter", new FTPMessageSourceBeanDefinitionParser()); - registerBeanDefinitionParser("outbound-channel-adapter", new FTPMessageSendingConsumerBeanDefinitionParser()); - } - - /** - * Configures an object that can take inbound messages and send them. - */ - private static class FTPMessageSendingConsumerBeanDefinitionParser extends AbstractOutboundChannelAdapterParser { - @Override - protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FtpSendingMessageHandlerFactoryBean.class.getName()); - - for (String p : "auto-create-directories,username,port,password,host,key-file,key-file-password,remote-directory".split(",")) { - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, p); - } - - int clientMode = CLIENT_MODES.get(element.getAttribute("client-mode")); - - builder.addPropertyValue("clientMode", clientMode); - - return builder.getBeanDefinition(); - } - } - - /** - * Configures an object that can recieve files from a remote SFTP endpoint and broadcast their arrival to the - * consumer - */ - private static class FTPMessageSourceBeanDefinitionParser extends AbstractPollingInboundChannelAdapterParser { - @Override - @SuppressWarnings("unused") - protected String parseSource(Element element, ParserContext parserContext) { - - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( - FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.class.getName()); - - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element,"filter"); - - for (String p : ("auto-delete-remote-files-on-sync,filename-pattern,auto-create-directories,username,password,host,port," + - "remote-directory,local-working-directory").split(",")) { - IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, p); - } - - int clientMode = CLIENT_MODES.get(element.getAttribute("client-mode")); - builder.addPropertyValue("clientMode", clientMode); - - return BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry()); - } - } -} 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/impl/FtpInboundRemoteFileSystemSynchronizer.java deleted file mode 100644 index 00f2129885..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpInboundRemoteFileSystemSynchronizer.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.springframework.integration.ftp.impl; - -import org.apache.commons.net.ftp.FTPClient; -import org.apache.commons.net.ftp.FTPFile; -import org.springframework.core.io.Resource; -import org.springframework.integration.MessagingException; -import org.springframework.integration.file.AbstractInboundRemoteFileSystemSychronizer; -import org.springframework.integration.file.AbstractInboundRemoteFileSystemSynchronizingMessageSource; -import org.springframework.integration.ftp.FtpClientPool; -import org.springframework.scheduling.Trigger; -import org.springframework.scheduling.support.PeriodicTrigger; -import org.springframework.util.Assert; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Collection; - - -/** - * An FTP-adapter implementation of {@link org.springframework.integration.file.AbstractInboundRemoteFileSystemSychronizer} - * - * @author Josh Long - */ -public class FtpInboundRemoteFileSystemSynchronizer extends AbstractInboundRemoteFileSystemSychronizer { - protected FtpClientPool clientPool; - - @Override - protected void onInit() throws Exception { - Assert.notNull(this.clientPool, "clientPool can't be null"); - - if (this.shouldDeleteSourceFile) { - this.entryAcknowledgmentStrategy = new DeletionEntryAcknowledgmentStrategy(); - } - } - - /** - * The {@link org.springframework.integration.ftp.FtpClientPool} that holds references to {@link org.apache.commons.net.ftp.FTPClient} instances - * - * @param clientPool the {@link org.springframework.integration.ftp.FtpClientPool} - */ - public void setClientPool(FtpClientPool clientPool) { - this.clientPool = clientPool; - } - - protected boolean copyFileToLocalDirectory(FTPClient client, FTPFile ftpFile, Resource localDirectory) - throws IOException, FileNotFoundException { - String remoteFileName = ftpFile.getName(); - String localFileName = localDirectory.getFile().getPath() + "/" + remoteFileName; - File localFile = new File(localFileName); - - if (!localFile.exists()) { - String tempFileName = localFileName + AbstractInboundRemoteFileSystemSynchronizingMessageSource.INCOMPLETE_EXTENSION; - File file = new File(tempFileName); - FileOutputStream fos = new FileOutputStream(file); - - try { - client.retrieveFile(remoteFileName, fos); - - // Perhaps we have some dispatch of hte source file to do? - acknowledge(client, ftpFile); - } catch (Throwable th) { - throw new RuntimeException(th); - } finally { - fos.close(); - } - - file.renameTo(localFile); - - return true; - } else { - return false; - } - } - - @Override - 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."); - - Collection fileList = this.filter.filterEntries(client.listFiles()); - - try { - for (FTPFile ftpFile : fileList) { - if ((ftpFile != null) && ftpFile.isFile()) { - 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); - } - } - - @Override - protected Trigger getTrigger() { - return new PeriodicTrigger(10 * 1000); - } - - /** - * An ackowledgment strategy that deletes - */ - class DeletionEntryAcknowledgmentStrategy implements AbstractInboundRemoteFileSystemSychronizer.EntryAcknowledgmentStrategy { - 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/impl/FtpInboundRemoteFileSystemSynchronizingMessageSource.java deleted file mode 100644 index 3861a57342..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpInboundRemoteFileSystemSynchronizingMessageSource.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.springframework.integration.ftp.impl; - -import org.apache.commons.net.ftp.FTPFile; -import org.springframework.integration.file.AbstractInboundRemoteFileSystemSynchronizingMessageSource; -import org.springframework.integration.ftp.FtpClientPool; - - -/** - * a {@link org.springframework.integration.core.MessageSource} implementation for FTP - * - * @author Josh Long - */ -public class FtpInboundRemoteFileSystemSynchronizingMessageSource extends AbstractInboundRemoteFileSystemSynchronizingMessageSource { - private volatile FtpClientPool clientPool; - - public void setClientPool(FtpClientPool clientPool) { - this.clientPool = clientPool; - } - - @Override - protected void doStart() { - this.synchronizer.start(); - } - - @Override - protected void doStop() { - this.synchronizer.stop(); - } - - @Override - protected void onInit() throws Exception { - super.onInit(); - this.synchronizer.setClientPool(this.clientPool); - } -} 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/impl/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java deleted file mode 100644 index b5a187ce23..0000000000 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/impl/FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean.java +++ /dev/null @@ -1,174 +0,0 @@ -package org.springframework.integration.ftp.impl; - -import org.apache.commons.lang.SystemUtils; -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.DefaultFtpClientFactory; -import org.springframework.integration.ftp.FtpFileEntryNamer; -import org.springframework.integration.ftp.QueuedFtpClientPool; -import org.springframework.util.StringUtils; - -import java.io.File; - - -/** - * Factory to make building the namespace easier - * - * @author Josh Long - */ -public class FtpRemoteFileSystemSynchronizingMessageSourceFactoryBean extends AbstractFactoryBean implements ResourceLoaderAware { - private volatile String port; - private volatile String autoCreateDirectories; - private volatile String filenamePattern; - private volatile String username; - private volatile String password; - private volatile String host; - private volatile String remoteDirectory; - private volatile String localWorkingDirectory; - private volatile ResourceLoader resourceLoader; - private volatile Resource localDirectoryResource; - private volatile EntryListFilter filter; - private volatile int clientMode = FTPClient.ACTIVE_LOCAL_DATA_CONNECTION_MODE; - private volatile String autoDeleteRemoteFilesOnSync; - - @SuppressWarnings("unused") - public void setAutoDeleteRemoteFilesOnSync(String autoDeleteRemoteFilesOnSync) { - this.autoDeleteRemoteFilesOnSync = autoDeleteRemoteFilesOnSync; - } - - @Override - public Class getObjectType() { - return FtpInboundRemoteFileSystemSynchronizingMessageSource.class; - } - - private Resource fromText(String path) { - ResourceEditor resourceEditor = new ResourceEditor(this.resourceLoader); - resourceEditor.setAsText(path); - return (Resource) resourceEditor.getValue(); - } - - private DefaultFtpClientFactory defaultFtpClientFactory() { - DefaultFtpClientFactory defaultFtpClientFactory = new DefaultFtpClientFactory(); - defaultFtpClientFactory.setHost(this.host); - defaultFtpClientFactory.setPassword(this.password); - defaultFtpClientFactory.setPort(Integer.parseInt(this.port)); - defaultFtpClientFactory.setRemoteWorkingDirectory(this.remoteDirectory); - defaultFtpClientFactory.setUsername(this.username); - defaultFtpClientFactory.setClientMode(this.clientMode); - - return defaultFtpClientFactory; - } - - @Override - protected FtpInboundRemoteFileSystemSynchronizingMessageSource createInstance() - throws Exception { - boolean autoCreatDirs = Boolean.parseBoolean(this.autoCreateDirectories); - boolean ackRemoteDir = Boolean.parseBoolean(this.autoDeleteRemoteFilesOnSync); - - FtpInboundRemoteFileSystemSynchronizingMessageSource ftpRemoteFileSystemSynchronizingMessageSource = new FtpInboundRemoteFileSystemSynchronizingMessageSource(); - ftpRemoteFileSystemSynchronizingMessageSource.setAutoCreateDirectories(autoCreatDirs); - - if (!StringUtils.hasText(this.localWorkingDirectory)) { - File tmp = new File(SystemUtils.getJavaIoTmpDir(), "ftpInbound"); - this.localWorkingDirectory = "file://" + tmp.getAbsolutePath(); - } - - this.localDirectoryResource = this.fromText(this.localWorkingDirectory); - - FtpFileEntryNamer ftpFileEntryNamer = new FtpFileEntryNamer(); - CompositeEntryListFilter compositeFtpFileListFilter = new CompositeEntryListFilter(); - - if (StringUtils.hasText(this.filenamePattern)) { - PatternMatchingEntryListFilter ftpFilePatternMatchingEntryListFilter = new PatternMatchingEntryListFilter(ftpFileEntryNamer, filenamePattern); - compositeFtpFileListFilter.addFilter(ftpFilePatternMatchingEntryListFilter); - } - - if (this.filter != null) { - compositeFtpFileListFilter.addFilter(this.filter); - } - - QueuedFtpClientPool queuedFtpClientPool = new QueuedFtpClientPool(15, defaultFtpClientFactory()); - - FtpInboundRemoteFileSystemSynchronizer ftpRemoteFileSystemSynchronizer = new FtpInboundRemoteFileSystemSynchronizer(); - ftpRemoteFileSystemSynchronizer.setClientPool(queuedFtpClientPool); - ftpRemoteFileSystemSynchronizer.setLocalDirectory(this.localDirectoryResource); - ftpRemoteFileSystemSynchronizer.setShouldDeleteSourceFile(ackRemoteDir); - - ftpRemoteFileSystemSynchronizer.setFilter(compositeFtpFileListFilter); - ftpRemoteFileSystemSynchronizingMessageSource.setRemotePredicate(compositeFtpFileListFilter); - - ftpRemoteFileSystemSynchronizingMessageSource.setSynchronizer(ftpRemoteFileSystemSynchronizer); - ftpRemoteFileSystemSynchronizingMessageSource.setClientPool(queuedFtpClientPool); - - ftpRemoteFileSystemSynchronizingMessageSource.setLocalDirectory(this.localDirectoryResource); - ftpRemoteFileSystemSynchronizingMessageSource.setBeanFactory(this.getBeanFactory()); - ftpRemoteFileSystemSynchronizingMessageSource.setAutoStartup(true); - ftpRemoteFileSystemSynchronizingMessageSource.afterPropertiesSet(); - ftpRemoteFileSystemSynchronizingMessageSource.start(); - - return ftpRemoteFileSystemSynchronizingMessageSource; - } - - @SuppressWarnings("unused") - public void setPort(String port) { - this.port = port; - } - - @SuppressWarnings("unused") - public void setAutoCreateDirectories(String autoCreateDirectories) { - this.autoCreateDirectories = autoCreateDirectories; - } - - @SuppressWarnings("unused") - public void setFilenamePattern(String filenamePattern) { - this.filenamePattern = filenamePattern; - } - - @SuppressWarnings("unused") - public void setUsername(String username) { - this.username = username; - } - - @SuppressWarnings("unused") - public void setPassword(String password) { - this.password = password; - } - - @SuppressWarnings("unused") - public void setHost(String host) { - this.host = host; - } - - @SuppressWarnings("unused") - public void setRemoteDirectory(String remoteDirectory) { - this.remoteDirectory = remoteDirectory; - } - - @SuppressWarnings("unused") - public void setLocalWorkingDirectory(String localWorkingDirectory) { - this.localWorkingDirectory = localWorkingDirectory; - } - - @SuppressWarnings("unused") - public void setFilter(EntryListFilter filter) { - this.filter = filter; - } - - @SuppressWarnings("unused") - public void setClientMode(int clientMode) { - this.clientMode = clientMode; - } - - @SuppressWarnings("unused") - public void setResourceLoader(ResourceLoader resourceLoader) { - this.resourceLoader = resourceLoader; - } -} diff --git a/spring-integration-ftp/src/main/resources/META-INF/MANIFEST.MF b/spring-integration-ftp/src/main/resources/META-INF/MANIFEST.MF deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-integration-ftp/src/main/resources/META-INF/spring.handlers b/spring-integration-ftp/src/main/resources/META-INF/spring.handlers deleted file mode 100644 index db0a408e2a..0000000000 --- a/spring-integration-ftp/src/main/resources/META-INF/spring.handlers +++ /dev/null @@ -1 +0,0 @@ -http\://www.springframework.org/schema/integration/ftp=org.springframework.integration.ftp.config.FtpNamespaceHandler diff --git a/spring-integration-ftp/src/main/resources/META-INF/spring.schemas b/spring-integration-ftp/src/main/resources/META-INF/spring.schemas deleted file mode 100644 index 6442125fe9..0000000000 --- a/spring-integration-ftp/src/main/resources/META-INF/spring.schemas +++ /dev/null @@ -1,2 +0,0 @@ -http\://www.springframework.org/schema/integration/ftp/spring-integration-ftp-2.0.xsd=org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd -http\://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd=org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd diff --git a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd b/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd deleted file mode 100644 index 391b4d7522..0000000000 --- a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.0.xsd +++ /dev/null @@ -1,216 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/InboundFtpFileServiceActivator.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/InboundFtpFileServiceActivator.java deleted file mode 100644 index 48544076e1..0000000000 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/InboundFtpFileServiceActivator.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.springframework.integration.ftp; - -import org.apache.commons.lang.StringUtils; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.Message; -import org.springframework.integration.annotation.ServiceActivator; - -import java.io.File; - - -/** - * Simple component to test the inbound integration - * - * @author Josh Long - */ - -public class InboundFtpFileServiceActivator { - - @ServiceActivator - public void onNewRemoteFTPFile(Message file) - throws Throwable { - System.out.println(StringUtils.repeat("=", 100)); - System.out.println("A new file has appeared: " + file.getPayload().getAbsolutePath()); - - for (String h : file.getHeaders().keySet()) - System.out.println(String.format("%s = %s", h, file.getHeaders().get(h))); - } - - public static void main(String[] args) throws Throwable { - ClassPathXmlApplicationContext classPathXmlApplicationContext = - new ClassPathXmlApplicationContext("inbound-ftp-context.xml"); - classPathXmlApplicationContext.start(); - } -} diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/OutboundFtpExample.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/OutboundFtpExample.java deleted file mode 100644 index bd8d7cf939..0000000000 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/OutboundFtpExample.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.springframework.integration.ftp; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -/** - * This simple example demonstrates sending a file to a remote FTP server using the ftp:outbound-channel-adapter - * - * It reads files from a directory on your computer and systematically puts them on the remote FTP server, - * - * @author Josh Long - */ -public class OutboundFtpExample { - public static void main(String [] args ) throws Throwable { - ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("outbound-ftp-context.xml"); - } -} diff --git a/spring-integration-ftp/src/test/resources/inbound-ftp-context.xml b/spring-integration-ftp/src/test/resources/inbound-ftp-context.xml deleted file mode 100644 index aa937e6a32..0000000000 --- a/spring-integration-ftp/src/test/resources/inbound-ftp-context.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-ftp/src/test/resources/outbound-ftp-context.xml b/spring-integration-ftp/src/test/resources/outbound-ftp-context.xml deleted file mode 100644 index d80b6073b0..0000000000 --- a/spring-integration-ftp/src/test/resources/outbound-ftp-context.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file