diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd index b24d0508b1..24291ee736 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd @@ -16,55 +16,6 @@ ]]> - - - - - Defines a file-based source channel adapter. - - - - - - - - - - - - - - - - - Defines a file-based target. - - - - - - - - - - - - - Defines an ftp-receiving target channel adapter. - - - - - - - - - - - - - - @@ -108,12 +59,4 @@ - - - - - - - - \ No newline at end of file diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/AbstractDirectorySourceParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/AbstractDirectorySourceParser.java deleted file mode 100644 index 14932564bf..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/AbstractDirectorySourceParser.java +++ /dev/null @@ -1,45 +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.adapter.ftp.config; - -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; -import org.springframework.util.StringUtils; -import org.w3c.dom.Element; - -/** - * Base class for directory-based sources. - * - * @author Marius Bogoevici - */ -public abstract class AbstractDirectorySourceParser extends AbstractSimpleBeanDefinitionParser { - - public static final String MESSAGE_CREATOR_REFERENCE_ATTRIBUTE = "message-creator"; - - @Override - protected boolean isEligibleAttribute(String attributeName) { - return !MESSAGE_CREATOR_REFERENCE_ATTRIBUTE.equals(attributeName) && super.isEligibleAttribute(attributeName); - } - - @Override - protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) { - String messageCreatorReference = element.getAttribute(MESSAGE_CREATOR_REFERENCE_ATTRIBUTE); - if (StringUtils.hasText(messageCreatorReference)) { - beanDefinition.addConstructorArgReference(messageCreatorReference); - } - } -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpSourceParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpSourceParser.java deleted file mode 100644 index f6d6e12df7..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpSourceParser.java +++ /dev/null @@ -1,77 +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.adapter.ftp.config; - -import org.w3c.dom.Element; - -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.integration.adapter.ftp.FtpSource; -import org.springframework.integration.adapter.ftp.QueuedFTPClientPool; - -/** - * Parser for the <ftp-source/> element. - * - * @author Mark Fisher - * @author Marius Bogoevici - * @author Iwein Fuld - */ -public class FtpSourceParser extends AbstractDirectorySourceParser { - - private static final String POOL_ATTRIBUTE_USER = "username"; - - private static final String POOL_ATTRIBUTE_PASS = "password"; - - private static final String POOL_ATTRIBUTE_HOST = "host"; - - private static final String POOL_ATTRIBUTE_PORT = "port"; - - private static final String POOL_ATTRIBUTE_REMOTEDIR = "remote-working-directory"; - - - @Override - protected Class getBeanClass(Element element) { - return FtpSource.class; - } - - @Override - protected boolean isEligibleAttribute(String attributeName) { - return !POOL_ATTRIBUTE_HOST.equals(attributeName) - && !POOL_ATTRIBUTE_PASS.equals(attributeName) - && !POOL_ATTRIBUTE_PORT.equals(attributeName) - && !POOL_ATTRIBUTE_USER.equals(attributeName) - && !POOL_ATTRIBUTE_REMOTEDIR.equals(attributeName) - && super.isEligibleAttribute(attributeName); - } - - @Override - protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) { - super.postProcess(beanDefinition, element); - String user = element.getAttribute(POOL_ATTRIBUTE_USER); - String pass = element.getAttribute(POOL_ATTRIBUTE_PASS); - String host = element.getAttribute(POOL_ATTRIBUTE_HOST); - String port = element.getAttribute(POOL_ATTRIBUTE_PORT); - String remoteWorkingDirectory = element.getAttribute(POOL_ATTRIBUTE_REMOTEDIR); - QueuedFTPClientPool queuedFTPClientPool = new QueuedFTPClientPool(); - queuedFTPClientPool.setUsername(user); - queuedFTPClientPool.setPassword(pass); - queuedFTPClientPool.setHost(host); - queuedFTPClientPool.setPort(Integer.parseInt(port)); - queuedFTPClientPool.setRemoteWorkingDirectory(remoteWorkingDirectory); - beanDefinition.addConstructorArgValue(queuedFTPClientPool); - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpTargetParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpTargetParser.java deleted file mode 100644 index 36611d8719..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/config/FtpTargetParser.java +++ /dev/null @@ -1,73 +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.adapter.ftp.config; - -import java.io.File; - -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; -import org.springframework.integration.adapter.ftp.FtpTarget; -import org.springframework.integration.adapter.ftp.QueuedFTPClientPool; -import org.springframework.integration.message.DefaultMessageMapper; -import org.w3c.dom.Element; - -public class FtpTargetParser extends AbstractSimpleBeanDefinitionParser { - private static final String POOL_ATTRIBUTE_USER = "username"; - - private static final String POOL_ATTRIBUTE_PASS = "password"; - - private static final String POOL_ATTRIBUTE_HOST = "host"; - - private static final String POOL_ATTRIBUTE_PORT = "port"; - - private static final String POOL_ATTRIBUTE_REMOTEDIR = "remote-working-directory"; - - @Override - protected Class getBeanClass(Element element) { - return FtpTarget.class; - } - - @Override - protected boolean isEligibleAttribute(String attributeName) { - return !POOL_ATTRIBUTE_HOST.equals(attributeName) && !POOL_ATTRIBUTE_PASS.equals(attributeName) - && !POOL_ATTRIBUTE_PORT.equals(attributeName) && !POOL_ATTRIBUTE_USER.equals(attributeName) - && !POOL_ATTRIBUTE_REMOTEDIR.equals(attributeName) && super.isEligibleAttribute(attributeName); - } - - @Override - protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) { - super.postProcess(beanDefinition, element); - QueuedFTPClientPool queuedFTPClientPool = constructFTPClientPool(element); - beanDefinition.addConstructorArgValue(queuedFTPClientPool); - beanDefinition.addConstructorArgValue(new DefaultMessageMapper()); - } - - private QueuedFTPClientPool constructFTPClientPool(Element element) { - String user = element.getAttribute(POOL_ATTRIBUTE_USER); - String pass = element.getAttribute(POOL_ATTRIBUTE_PASS); - String host = element.getAttribute(POOL_ATTRIBUTE_HOST); - String port = element.getAttribute(POOL_ATTRIBUTE_PORT); - String remoteWorkingDirectory = element.getAttribute(POOL_ATTRIBUTE_REMOTEDIR); - QueuedFTPClientPool queuedFTPClientPool = new QueuedFTPClientPool(); - queuedFTPClientPool.setUsername(user); - queuedFTPClientPool.setPassword(pass); - queuedFTPClientPool.setHost(host); - queuedFTPClientPool.setPort(Integer.parseInt(port)); - queuedFTPClientPool.setRemoteWorkingDirectory(remoteWorkingDirectory); - return queuedFTPClientPool; - } -} diff --git a/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers b/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers index a1baa7fd88..b8dc6a597a 100644 --- a/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers +++ b/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers @@ -1,4 +1,3 @@ -ftp-source=org.springframework.integration.adapter.ftp.config.FtpSourceParser mail-target=org.springframework.integration.adapter.mail.config.MailTargetParser polling-mail-source=org.springframework.integration.adapter.mail.config.PollingMailSourceParser imap-idle-mail-source=org.springframework.integration.adapter.mail.config.SubscribableImapIdleMailSourceParser diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/ftpSourceParserTests.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/ftpSourceParserTests.xml deleted file mode 100644 index c8f2bcdb58..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/ftpSourceParserTests.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/ftpSourceWithChannelAdapter.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/ftpSourceWithChannelAdapter.xml deleted file mode 100644 index 8c37b148c5..0000000000 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/ftpSourceWithChannelAdapter.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/org.springframework.integration.ftp/ivy.xml b/org.springframework.integration.ftp/ivy.xml index 223fc74f08..0d6feaf06f 100644 --- a/org.springframework.integration.ftp/ivy.xml +++ b/org.springframework.integration.ftp/ivy.xml @@ -26,9 +26,7 @@ - - diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/AbstractDirectorySource.java b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/AbstractDirectorySource.java similarity index 96% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/AbstractDirectorySource.java rename to org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/AbstractDirectorySource.java index 740c467d0e..8513f7857a 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/AbstractDirectorySource.java +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/AbstractDirectorySource.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp; +package org.springframework.integration.ftp; import java.io.IOException; import java.util.ArrayList; @@ -48,6 +48,7 @@ public abstract class AbstractDirectorySource implements PollableSource, M private final MessageCreator messageCreator; + public AbstractDirectorySource(MessageCreator messageCreator) { this(messageCreator, null); } @@ -58,6 +59,7 @@ public abstract class AbstractDirectorySource implements PollableSource, M this.messageCreator = messageCreator; } + protected Backlog getBacklog() { return this.backlog; } @@ -117,21 +119,16 @@ public abstract class AbstractDirectorySource implements PollableSource, M /** * Constructs the snapshot by iterating files. - * - * @param snapshot - * @throws IOException */ protected abstract void populateSnapshot(List snapshot) throws IOException; /** * Returns the next file, based on the backlog data. - * - * @return - * @throws IOException */ protected abstract T retrieveNextPayload() throws IOException; protected final void filesProcessed() { this.backlog.processed(); } + } diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/Backlog.java b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/Backlog.java similarity index 99% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/Backlog.java rename to org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/Backlog.java index 640cc617c4..c1a0050339 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/Backlog.java +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/Backlog.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp; +package org.springframework.integration.ftp; import java.util.ArrayList; import java.util.Collection; @@ -33,7 +33,6 @@ import org.springframework.util.Assert; * Keeps track of a backlog in a threadsafe, stateful manner. * * @author Marius Bogoevici - * @author Mark Fisher * @author Iwein Fuld */ public class Backlog> { diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FTPClientFactory.java b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FTPClientFactory.java similarity index 94% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FTPClientFactory.java rename to org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FTPClientFactory.java index 3da3e42273..430caa88a7 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FTPClientFactory.java +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FTPClientFactory.java @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.integration.adapter.ftp; + +package org.springframework.integration.ftp; import java.io.IOException; import java.net.SocketException; import org.apache.commons.net.ftp.FTPClient; + /** * Factory for {@link FTPClient}. + * * @author Iwein Fuld - * */ public interface FTPClientFactory { diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FTPClientPool.java b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FTPClientPool.java similarity index 91% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FTPClientPool.java rename to org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FTPClientPool.java index c6ba4aa79a..fc351afd7b 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FTPClientPool.java +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FTPClientPool.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.integration.adapter.ftp; + +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 + * number of open FTP connections and reuse these connections efficiently. * + * @author Iwein Fuld */ public interface FTPClientPool extends FTPClientFactory { @@ -30,9 +31,9 @@ public interface FTPClientPool extends FTPClientFactory { * 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. * @@ -40,4 +41,4 @@ public interface FTPClientPool extends FTPClientFactory { */ void releaseClient(FTPClient client); -} \ No newline at end of file +} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FileSnapshot.java b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FileSnapshot.java similarity index 97% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FileSnapshot.java rename to org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FileSnapshot.java index ae63a7a75d..fb227ce229 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FileSnapshot.java +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FileSnapshot.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp; +package org.springframework.integration.ftp; import java.io.File; @@ -22,7 +22,7 @@ import org.springframework.util.Assert; /** * Information about a file. - * + *

* The FileSnapshot takes a snapshot of certain mutable properties of a file and * stores them in an immutable way. This can be useful to determine if files * have been changed. diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpTarget.java b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageConsumer.java similarity index 67% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpTarget.java rename to org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageConsumer.java index 7d27b52559..b16074995d 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpTarget.java +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FtpSendingMessageConsumer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp; +package org.springframework.integration.ftp; import java.io.File; import java.io.FileInputStream; @@ -24,40 +24,43 @@ import java.io.IOException; import org.apache.commons.net.ftp.FTPClient; import org.springframework.integration.message.Message; +import org.springframework.integration.message.MessageConsumer; import org.springframework.integration.message.MessageDeliveryException; -import org.springframework.integration.message.MessageMapper; -import org.springframework.integration.message.MessageTarget; import org.springframework.util.Assert; /** - * Target adapter for sending files to an FTP server. + * A {@link MessageConsumer} implementation that sends files to an FTP server. * * @author Iwein Fuld + * @author Mark Fisher */ -public class FtpTarget implements MessageTarget { - - private final MessageMapper messageMapper; +public class FtpSendingMessageConsumer implements MessageConsumer { private final FTPClientPool ftpClientPool; - public FtpTarget(MessageMapper messageMapper, FTPClientPool ftpClientPool) { - Assert.notNull(messageMapper, "messageMapper must not be null"); + public FtpSendingMessageConsumer(FTPClientPool ftpClientPool) { Assert.notNull(ftpClientPool, "ftpClientPool must not be null"); this.ftpClientPool = ftpClientPool; - this.messageMapper = messageMapper; } - public boolean send(Message message) { - boolean sent = false; - File file = this.messageMapper.mapMessage(message); + + public void onMessage(Message message) { + Assert.notNull(message, "message must not be null"); + Object payload = message.getPayload(); + Assert.notNull(payload, "message payload must not be null"); + Assert.isInstanceOf(File.class, payload, "Message payload must be an instance of [java.io.File]"); + File file = (File) payload; if (file != null && file.exists()) { FTPClient client = null; try { FileInputStream fileInputStream = new FileInputStream(file); client = this.ftpClientPool.getClient(); - sent = client.storeFile(file.getName(), fileInputStream); + boolean sent = client.storeFile(file.getName(), fileInputStream); fileInputStream.close(); + if (!sent) { + throw new MessageDeliveryException(message, "Failed to store file '" + file + "'"); + } } catch (FileNotFoundException e) { throw new MessageDeliveryException(message, "File [" + file + "] lost from local working directory", e); @@ -70,7 +73,6 @@ public class FtpTarget implements MessageTarget { ftpClientPool.releaseClient(client); } } - return sent; } } diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpSource.java b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FtpSource.java similarity index 98% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpSource.java rename to org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FtpSource.java index 830e314d9b..2313568b0c 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/FtpSource.java +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/FtpSource.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp; +package org.springframework.integration.ftp; import java.io.File; import java.io.FileOutputStream; diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPool.java b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/QueuedFTPClientPool.java similarity index 99% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPool.java rename to org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/QueuedFTPClientPool.java index 8212f1a37f..03a2b1a04b 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPool.java +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/QueuedFTPClientPool.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp; +package org.springframework.integration.ftp; import java.io.IOException; import java.net.SocketException; @@ -35,7 +35,7 @@ import org.springframework.util.StringUtils; /** * 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. * diff --git a/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParser.java b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParser.java new file mode 100644 index 0000000000..4110acc34a --- /dev/null +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParser.java @@ -0,0 +1,63 @@ +/* + * 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.config; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.AbstractPollingInboundChannelAdapterParser; +import org.springframework.integration.config.IntegrationNamespaceUtils; +import org.springframework.integration.ftp.FtpSource; +import org.springframework.integration.ftp.QueuedFTPClientPool; +import org.springframework.util.StringUtils; + +/** + * Parser for the <inbound-channel-adapter/> element of the 'ftp' namespace. + * + * @author Mark Fisher + * @author Marius Bogoevici + * @author Iwein Fuld + */ +public class FtpInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser { + + @Override + protected String parseSource(Element element, ParserContext parserContext) { + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FtpSource.class); + String messageCreatorReference = element.getAttribute("message-creator"); + if (StringUtils.hasText(messageCreatorReference)) { + builder.addConstructorArgReference(messageCreatorReference); + } + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "local-working-directory"); + String username = element.getAttribute("username"); + String password = element.getAttribute("password"); + String host = element.getAttribute("host"); + String port = element.getAttribute("port"); + String remoteWorkingDirectory = element.getAttribute("remote-working-directory"); + QueuedFTPClientPool queuedFTPClientPool = new QueuedFTPClientPool(); + queuedFTPClientPool.setUsername(username); + queuedFTPClientPool.setPassword(password); + queuedFTPClientPool.setHost(host); + queuedFTPClientPool.setPort(Integer.parseInt(port)); + queuedFTPClientPool.setRemoteWorkingDirectory(remoteWorkingDirectory); + builder.addConstructorArgValue(queuedFTPClientPool); + return BeanDefinitionReaderUtils.registerWithGeneratedName( + builder.getBeanDefinition(), parserContext.getRegistry()); + } + +} diff --git a/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java new file mode 100644 index 0000000000..37c7f8ad49 --- /dev/null +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/FtpNamespaceHandler.java @@ -0,0 +1,32 @@ +/* + * 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.config; + +import org.springframework.beans.factory.xml.NamespaceHandlerSupport; + +/** + * Namespace handler for the 'ftp' namespace. + * + * @author Mark Fisher + */ +public class FtpNamespaceHandler extends NamespaceHandlerSupport { + + public void init() { + this.registerBeanDefinitionParser("inbound-channel-adapter", new FtpInboundChannelAdapterParser()); + } + +} diff --git a/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java new file mode 100644 index 0000000000..6ac3993d0b --- /dev/null +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/FtpOutboundChannelAdapterParser.java @@ -0,0 +1,55 @@ +/* + * 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.config; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.AbstractOutboundChannelAdapterParser; +import org.springframework.integration.ftp.FtpSendingMessageConsumer; +import org.springframework.integration.ftp.QueuedFTPClientPool; + +/** + * Parser for the <outbound-channel-adapter/> element of the 'ftp' namespace. + * + * @author Iwein Fuld + * @author Mark Fisher + */ +public class FtpOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser { + + @Override + protected String parseConsumer(Element element, ParserContext parserContext) { + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FtpSendingMessageConsumer.class); + String username = element.getAttribute("username"); + String password = element.getAttribute("password"); + String host = element.getAttribute("host"); + String port = element.getAttribute("port"); + String remoteWorkingDirectory = element.getAttribute("remote-working-directory"); + QueuedFTPClientPool queuedFTPClientPool = new QueuedFTPClientPool(); + queuedFTPClientPool.setUsername(username); + queuedFTPClientPool.setPassword(password); + queuedFTPClientPool.setHost(host); + queuedFTPClientPool.setPort(Integer.parseInt(port)); + queuedFTPClientPool.setRemoteWorkingDirectory(remoteWorkingDirectory); + builder.addConstructorArgValue(queuedFTPClientPool); + return BeanDefinitionReaderUtils.registerWithGeneratedName( + builder.getBeanDefinition(), parserContext.getRegistry()); + } + +} diff --git a/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/spring-integration-ftp-1.0.xsd b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/spring-integration-ftp-1.0.xsd new file mode 100644 index 0000000000..b0ecddf4ec --- /dev/null +++ b/org.springframework.integration.ftp/src/main/java/org/springframework/integration/ftp/config/spring-integration-ftp-1.0.xsd @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + Defines an inbound FTP-polling Channel Adapter. + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.springframework.integration.ftp/src/main/resources/META-INF/spring.handlers b/org.springframework.integration.ftp/src/main/resources/META-INF/spring.handlers new file mode 100644 index 0000000000..4c588412b9 --- /dev/null +++ b/org.springframework.integration.ftp/src/main/resources/META-INF/spring.handlers @@ -0,0 +1 @@ +http\://www.springframework.org/schema/integration/ftp=org.springframework.integration.ftp.config.FtpNamespaceHandler \ No newline at end of file diff --git a/org.springframework.integration.ftp/src/main/resources/META-INF/spring.schemas b/org.springframework.integration.ftp/src/main/resources/META-INF/spring.schemas new file mode 100644 index 0000000000..150f391de3 --- /dev/null +++ b/org.springframework.integration.ftp/src/main/resources/META-INF/spring.schemas @@ -0,0 +1 @@ +http\://www.springframework.org/schema/integration/ftp/spring-integration-ftp-1.0.xsd=org/springframework/integration/ftp/config/spring-integration-ftp-1.0.xsd \ No newline at end of file diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/BacklogTests.java b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/BacklogTests.java similarity index 96% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/BacklogTests.java rename to org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/BacklogTests.java index fbbdf2b5f7..da8b5993c7 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/BacklogTests.java +++ b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/BacklogTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp; +package org.springframework.integration.ftp; import java.util.ArrayList; import java.util.concurrent.PriorityBlockingQueue; @@ -24,8 +24,8 @@ import org.junit.Before; import org.junit.Test; import org.springframework.beans.DirectFieldAccessor; -import org.springframework.integration.adapter.ftp.Backlog; -import org.springframework.integration.adapter.ftp.FileSnapshot; +import org.springframework.integration.ftp.Backlog; +import org.springframework.integration.ftp.FileSnapshot; /** * @author Marius Bogoevici diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/ConcurrentBacklogTests.java b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/ConcurrentBacklogTests.java similarity index 97% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/ConcurrentBacklogTests.java rename to org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/ConcurrentBacklogTests.java index a5d8c2895d..4cce730c17 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/ConcurrentBacklogTests.java +++ b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/ConcurrentBacklogTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp; +package org.springframework.integration.ftp; import static org.junit.Assert.assertTrue; @@ -27,12 +27,13 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; import org.springframework.beans.DirectFieldAccessor; +import org.springframework.integration.ftp.Backlog; @SuppressWarnings("unchecked") public class ConcurrentBacklogTests { @Test(timeout = 1000) - public void simultaniousPreparation() throws Exception { + public void simultaneousPreparation() throws Exception { final Backlog backlog = new Backlog(); backlog.processSnapshot(Arrays.asList(new String[] { "bert", "ernie", "pino", "whatsherface" })); Runnable todo = new Runnable() { diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/FtpTargetTest.java b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/FtpSendingMessageConsumerTests.java similarity index 64% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/FtpTargetTest.java rename to org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/FtpSendingMessageConsumerTests.java index 3dff09942f..5992410717 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/FtpTargetTest.java +++ b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/FtpSendingMessageConsumerTests.java @@ -13,10 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.integration.adapter.ftp; -import static org.easymock.classextension.EasyMock.*; -import static org.junit.Assert.*; +package org.springframework.integration.ftp; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.isA; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.createNiceMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; import java.io.File; import java.io.FileInputStream; @@ -24,23 +29,19 @@ import java.io.FileInputStream; import org.apache.commons.net.ftp.FTPClient; import org.junit.Before; import org.junit.Test; + +import org.springframework.integration.message.GenericMessage; import org.springframework.integration.message.Message; -import org.springframework.integration.message.MessageMapper; +import org.springframework.integration.message.MessageDeliveryException; /** - * * @author Iwein Fuld - * + * @author Mark Fisher */ @SuppressWarnings("unchecked") -public class FtpTargetTest { +public class FtpSendingMessageConsumerTests { - private FtpTarget ftpTarget; - - // Mocks and initialization - private MessageMapper messageMapper = createMock(MessageMapper.class); - - private Message message = createMock(Message.class); + private FtpSendingMessageConsumer consumer; private FTPClient ftpClient = createMock(FTPClient.class); @@ -51,45 +52,42 @@ public class FtpTargetTest { */ private FTPClientPool ftpClientPool = createNiceMock(FTPClientPool.class); + /* + * Handle to all mocks in this test so you can't forget to include one in a + * replay, verify or reset call. + */ + private Object[] allMocks = new Object[] { ftpClient, ftpClientPool }; + + @Before public void liberalPool() throws Exception { expect(ftpClientPool.getClient()).andReturn(ftpClient).anyTimes(); } - /* - * Handle to all mocks in this test so you can't forget to include one in a - * replay, verify or reset call. - */ - private Object[] allMocks = new Object[] { messageMapper, message, ftpClient, ftpClientPool }; - @Before public void intitializeSubject() { - this.ftpTarget = new FtpTarget(messageMapper, ftpClientPool); + this.consumer = new FtpSendingMessageConsumer(ftpClientPool); } + // Tests + @Test public void send() throws Exception { - expect(messageMapper.mapMessage(message)).andReturn(File.createTempFile("test", ".tmp")); + Message message = new GenericMessage(File.createTempFile("test", ".tmp")); expect(ftpClient.storeFile(isA(String.class), isA(FileInputStream.class))).andReturn(true); replay(allMocks); - boolean sent = ftpTarget.send(message); - assertTrue(sent); + consumer.onMessage(message); verify(allMocks); } - @Test + @Test(expected = MessageDeliveryException.class) public void sendFailed_negative() throws Exception { - expect(messageMapper.mapMessage(message)).andReturn(File.createTempFile("test", ".tmp")); + Message message = new GenericMessage(File.createTempFile("test", ".tmp")); expect(ftpClient.storeFile(isA(String.class), isA(FileInputStream.class))).andReturn(false); replay(allMocks); - boolean sent = ftpTarget.send(message); - assertFalse(sent); + consumer.onMessage(message); verify(allMocks); } - @Test - public void sendFailed_() throws Exception { - - } } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/FtpSourceTests.java b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/FtpSourceTests.java similarity index 98% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/FtpSourceTests.java rename to org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/FtpSourceTests.java index 7d1be84c37..e87a4e5b4a 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/FtpSourceTests.java +++ b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/FtpSourceTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp; +package org.springframework.integration.ftp; import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.expect; @@ -46,6 +46,9 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; + +import org.springframework.integration.ftp.FTPClientPool; +import org.springframework.integration.ftp.FtpSource; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageCreator; diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPoolTest.java b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/QueuedFTPClientPoolTests.java similarity index 93% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPoolTest.java rename to org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/QueuedFTPClientPoolTests.java index e7fe9096af..a21f297a01 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/QueuedFTPClientPoolTest.java +++ b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/QueuedFTPClientPoolTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp; +package org.springframework.integration.ftp; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertSame; @@ -32,10 +32,13 @@ import org.apache.commons.net.ftp.FTPClient; import org.junit.Before; import org.junit.Test; +import org.springframework.integration.ftp.FTPClientFactory; +import org.springframework.integration.ftp.QueuedFTPClientPool; + /** * @author Iwein Fuld */ -public class QueuedFTPClientPoolTest { +public class QueuedFTPClientPoolTests { private QueuedFTPClientPool pool; diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/CustomMessageCreator.java b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/CustomMessageCreator.java similarity index 87% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/CustomMessageCreator.java rename to org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/CustomMessageCreator.java index 9648cdb809..829fa52267 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/CustomMessageCreator.java +++ b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/CustomMessageCreator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp.config; +package org.springframework.integration.ftp.config; import java.io.File; @@ -25,10 +25,10 @@ import org.springframework.integration.message.MessageCreator; /** * @author Marius Bogoevici */ -public class CustomMessageCreator implements MessageCreator{ +public class CustomMessageCreator implements MessageCreator { public Message createMessage(File object) { - return new GenericMessage (object.getAbsolutePath()); + return new GenericMessage(object.getAbsolutePath()); } } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceParserTests.java b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java similarity index 51% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceParserTests.java rename to org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java index d5aab2e68a..add55c2506 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceParserTests.java +++ b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.adapter.ftp.config; +package org.springframework.integration.ftp.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -26,7 +26,6 @@ import org.junit.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.adapter.ftp.FtpSource; import org.springframework.integration.message.DefaultMessageCreator; /** @@ -34,36 +33,42 @@ import org.springframework.integration.message.DefaultMessageCreator; * @author Marius Bogoevici * @author Iwein Fuld */ -public class FtpSourceParserTests { +public class FtpInboundChannelAdapterParserTests { @Test - public void testFtpSourceAdapterParser() { - ApplicationContext context = new ClassPathXmlApplicationContext("ftpSourceParserTests.xml", this.getClass()); - FtpSource ftpSource = (FtpSource) context.getBean("ftpSourceDefault"); - DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(ftpSource); - DirectFieldAccessor accessor = new DirectFieldAccessor(sourceAccessor.getPropertyValue("clientPool")); - assertEquals("testHost", accessor.getPropertyValue("host")); - assertEquals(2121, accessor.getPropertyValue("port")); + public void ftpSourceWithDefaultMessageCreator() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "ftpInboundChannelAdapterParserTests.xml", this.getClass()); + Object adapter = context.getBean("default.adapter"); + DirectFieldAccessor sourceAccessor = new DirectFieldAccessor( + new DirectFieldAccessor(adapter).getPropertyValue("source")); + DirectFieldAccessor poolAccessor = new DirectFieldAccessor( + sourceAccessor.getPropertyValue("clientPool")); + assertEquals("testHost", poolAccessor.getPropertyValue("host")); + assertEquals(2121, poolAccessor.getPropertyValue("port")); assertEquals(new File("/local"), sourceAccessor.getPropertyValue("localWorkingDirectory")); - assertEquals("/remote", accessor.getPropertyValue("remoteWorkingDirectory")); - assertEquals("testUser", accessor.getPropertyValue("username")); - assertEquals("testPassword", accessor.getPropertyValue("password")); + assertEquals("/remote", poolAccessor.getPropertyValue("remoteWorkingDirectory")); + assertEquals("testUser", poolAccessor.getPropertyValue("username")); + assertEquals("testPassword", poolAccessor.getPropertyValue("password")); Object messageCreator = sourceAccessor.getPropertyValue("messageCreator"); assertTrue(messageCreator instanceof DefaultMessageCreator); } @Test - public void testFtpSourceCustomType() { - ApplicationContext context = new ClassPathXmlApplicationContext("ftpSourceParserTests.xml", this.getClass()); - FtpSource ftpSource = (FtpSource) context.getBean("ftpSourceCustom"); - DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(ftpSource); - DirectFieldAccessor accessor = new DirectFieldAccessor(sourceAccessor.getPropertyValue("clientPool")); - assertEquals("testHost", accessor.getPropertyValue("host")); - assertEquals(2121, accessor.getPropertyValue("port")); + public void ftpSourceWithCustomMessageCreator() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "ftpInboundChannelAdapterParserTests.xml", this.getClass()); + Object adapter = context.getBean("custom.adapter"); + DirectFieldAccessor sourceAccessor = new DirectFieldAccessor( + new DirectFieldAccessor(adapter).getPropertyValue("source")); + DirectFieldAccessor poolAccessor = new DirectFieldAccessor( + sourceAccessor.getPropertyValue("clientPool")); + assertEquals("testHost", poolAccessor.getPropertyValue("host")); + assertEquals(2121, poolAccessor.getPropertyValue("port")); assertEquals(new File("/local"), sourceAccessor.getPropertyValue("localWorkingDirectory")); - assertEquals("/remote", accessor.getPropertyValue("remoteWorkingDirectory")); - assertEquals("testUser", accessor.getPropertyValue("username")); - assertEquals("testPassword", accessor.getPropertyValue("password")); + assertEquals("/remote", poolAccessor.getPropertyValue("remoteWorkingDirectory")); + assertEquals("testUser", poolAccessor.getPropertyValue("username")); + assertEquals("testPassword", poolAccessor.getPropertyValue("password")); Object messageCreator = sourceAccessor.getPropertyValue("messageCreator"); assertTrue(messageCreator instanceof CustomMessageCreator); } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpTargetIntegrationTest.java b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/FtpSendingMessageConsumerIntegrationTests.java similarity index 75% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpTargetIntegrationTest.java rename to org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/FtpSendingMessageConsumerIntegrationTests.java index 39bbe9226f..c52b1308ea 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpTargetIntegrationTest.java +++ b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/FtpSendingMessageConsumerIntegrationTests.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.integration.adapter.ftp.config; -import static org.junit.Assert.assertTrue; +package org.springframework.integration.ftp.config; import java.io.File; import java.io.FilenameFilter; @@ -25,18 +24,18 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -import org.springframework.integration.adapter.ftp.FtpTarget; -import org.springframework.integration.adapter.ftp.QueuedFTPClientPool; -import org.springframework.integration.message.DefaultMessageMapper; + +import org.springframework.integration.ftp.FtpSendingMessageConsumer; +import org.springframework.integration.ftp.QueuedFTPClientPool; import org.springframework.integration.message.GenericMessage; /** * @author Iwein Fuld */ @Ignore -public class FtpTargetIntegrationTest { +public class FtpSendingMessageConsumerIntegrationTests { - private FtpTarget ftpTarget; + private FtpSendingMessageConsumer consumer; @Before public void initFtpTarget() { @@ -45,13 +44,13 @@ public class FtpTargetIntegrationTest { clientPool.setUsername("ftp-user"); clientPool.setPassword("kaas"); clientPool.setRemoteWorkingDirectory("ftp-test"); - ftpTarget = new FtpTarget(new DefaultMessageMapper(), clientPool); + consumer = new FtpSendingMessageConsumer(clientPool); } @Test public void send() throws Exception { File file = File.createTempFile("test", ""); - assertTrue(ftpTarget.send(new GenericMessage(file))); + consumer.onMessage(new GenericMessage(file)); } @AfterClass @@ -62,4 +61,5 @@ public class FtpTargetIntegrationTest { file.delete(); } } + } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceIntegrationTests.java b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/FtpSourceIntegrationTests.java similarity index 64% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceIntegrationTests.java rename to org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/FtpSourceIntegrationTests.java index ef0a5c9ca7..5ac23e872d 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/ftp/config/FtpSourceIntegrationTests.java +++ b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/FtpSourceIntegrationTests.java @@ -1,23 +1,33 @@ -package org.springframework.integration.adapter.ftp.config; +/* + * 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.config; import static org.junit.Assert.assertTrue; import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.adapter.ftp.FtpSource; -import org.springframework.integration.adapter.ftp.QueuedFTPClientPool; -import org.springframework.integration.channel.ChannelRegistry; -import org.springframework.integration.channel.PollableChannel; -import org.springframework.integration.config.MessageBusParser; + +import org.springframework.integration.ftp.FtpSource; +import org.springframework.integration.ftp.QueuedFTPClientPool; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageCreator; @@ -39,16 +49,16 @@ import org.springframework.integration.message.MessageCreator; @Ignore public class FtpSourceIntegrationTests { + private static File localWorkDir; + private FtpSource ftpSource; private MessageCreator, List> messageCreator = new MessageCreator, List>() { - public Message> createMessage(List object) { return new GenericMessage>(object); } }; - private static File localWorkDir; @BeforeClass public static void initializeEnvironment() { @@ -72,15 +82,5 @@ public class FtpSourceIntegrationTests { Message> received = ftpSource.receive(); assertTrue(received.getPayload().iterator().next().exists()); } - - @Test public void withChannelAdapter() { - ApplicationContext context = new ClassPathXmlApplicationContext("ftpSourceWithChannelAdapter.xml", this.getClass()); - ChannelRegistry channelRegistry = (ChannelRegistry) context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME); - PollableChannel input = (PollableChannel) channelRegistry.lookupChannel("output"); - List files = new ArrayList(); - files.add((File) input.receive().getPayload()); - files.add((File) input.receive().getPayload()); - assertTrue(files.containsAll(Arrays.asList(new File("file1"), new File("file2")))); - } } diff --git a/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/ftpInboundChannelAdapterParserTests.xml b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/ftpInboundChannelAdapterParserTests.xml new file mode 100644 index 0000000000..8bfbcadd9d --- /dev/null +++ b/org.springframework.integration.ftp/src/test/java/org/springframework/integration/ftp/config/ftpInboundChannelAdapterParserTests.xml @@ -0,0 +1,30 @@ + + + + + + + + + + diff --git a/org.springframework.integration.ftp/template.mf b/org.springframework.integration.ftp/template.mf index 8d3975d96d..c1ed5c3c4b 100644 --- a/org.springframework.integration.ftp/template.mf +++ b/org.springframework.integration.ftp/template.mf @@ -5,8 +5,6 @@ Bundle-ManifestVersion: 2 Import-Template: org.springframework.integration.*;version="[1.0.0, 1.0.1)", org.springframework.beans.*;version="[2.5.5.A, 3.0.0)", - org.springframework.context;version="[2.5.5.A, 3.0.0)", - org.springframework.core.*;version="[2.5.5.A, 3.0.0)", org.springframework.util;version="[2.5.5.A, 3.0.0)", org.apache.commons.logging;version="[1.1.1, 2.0.0)", org.apache.commons.net.ftp;version="[1.4.1, 2.0.0)";resolution:=optional