Refactored MessageConsumer with onMessage to MessageHandler with handleMessage.
This commit is contained in:
@@ -24,28 +24,28 @@ import java.io.IOException;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageConsumer;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A {@link MessageConsumer} implementation that sends files to an FTP server.
|
||||
* A {@link MessageHandler} implementation that sends files to an FTP server.
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class FtpSendingMessageConsumer implements MessageConsumer {
|
||||
public class FtpSendingMessageHandler implements MessageHandler {
|
||||
|
||||
private final FTPClientPool ftpClientPool;
|
||||
|
||||
|
||||
public FtpSendingMessageConsumer(FTPClientPool ftpClientPool) {
|
||||
public FtpSendingMessageHandler(FTPClientPool ftpClientPool) {
|
||||
Assert.notNull(ftpClientPool, "ftpClientPool must not be null");
|
||||
this.ftpClientPool = ftpClientPool;
|
||||
}
|
||||
|
||||
|
||||
public void onMessage(Message<?> message) {
|
||||
public void handleMessage(Message<?> message) {
|
||||
Assert.notNull(message, "message must not be null");
|
||||
Object payload = message.getPayload();
|
||||
Assert.notNull(payload, "message payload must not be null");
|
||||
@@ -22,7 +22,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
|
||||
import org.springframework.integration.ftp.FtpSendingMessageConsumer;
|
||||
import org.springframework.integration.ftp.FtpSendingMessageHandler;
|
||||
import org.springframework.integration.ftp.QueuedFTPClientPool;
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ public class FtpOutboundChannelAdapterParser extends AbstractOutboundChannelAdap
|
||||
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FtpSendingMessageConsumer.class);
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(FtpSendingMessageHandler.class);
|
||||
String username = element.getAttribute("username");
|
||||
String password = element.getAttribute("password");
|
||||
String host = element.getAttribute("host");
|
||||
|
||||
@@ -38,10 +38,9 @@ import org.springframework.integration.message.MessageDeliveryException;
|
||||
* @author Iwein Fuld
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class FtpSendingMessageConsumerTests {
|
||||
public class FtpSendingMessageHandlerTests {
|
||||
|
||||
private FtpSendingMessageConsumer consumer;
|
||||
private FtpSendingMessageHandler handler;
|
||||
|
||||
private FTPClient ftpClient = createMock(FTPClient.class);
|
||||
|
||||
@@ -66,7 +65,7 @@ public class FtpSendingMessageConsumerTests {
|
||||
|
||||
@Before
|
||||
public void intitializeSubject() {
|
||||
this.consumer = new FtpSendingMessageConsumer(ftpClientPool);
|
||||
this.handler = new FtpSendingMessageHandler(ftpClientPool);
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +76,7 @@ public class FtpSendingMessageConsumerTests {
|
||||
Message<?> message = new GenericMessage<File>(File.createTempFile("test", ".tmp"));
|
||||
expect(ftpClient.storeFile(isA(String.class), isA(FileInputStream.class))).andReturn(true);
|
||||
replay(allMocks);
|
||||
consumer.onMessage(message);
|
||||
handler.handleMessage(message);
|
||||
verify(allMocks);
|
||||
}
|
||||
|
||||
@@ -86,7 +85,7 @@ public class FtpSendingMessageConsumerTests {
|
||||
Message<?> message = new GenericMessage<File>(File.createTempFile("test", ".tmp"));
|
||||
expect(ftpClient.storeFile(isA(String.class), isA(FileInputStream.class))).andReturn(false);
|
||||
replay(allMocks);
|
||||
consumer.onMessage(message);
|
||||
handler.handleMessage(message);
|
||||
verify(allMocks);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.ftp.FtpSendingMessageConsumer;
|
||||
import org.springframework.integration.ftp.FtpSendingMessageHandler;
|
||||
import org.springframework.integration.ftp.QueuedFTPClientPool;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.integration.message.GenericMessage;
|
||||
@Ignore
|
||||
public class FtpSendingMessageConsumerIntegrationTests {
|
||||
|
||||
private FtpSendingMessageConsumer consumer;
|
||||
private FtpSendingMessageHandler handler;
|
||||
|
||||
@Before
|
||||
public void initFtpTarget() {
|
||||
@@ -44,13 +44,13 @@ public class FtpSendingMessageConsumerIntegrationTests {
|
||||
clientPool.setUsername("ftp-user");
|
||||
clientPool.setPassword("kaas");
|
||||
clientPool.setRemoteWorkingDirectory("ftp-test");
|
||||
consumer = new FtpSendingMessageConsumer(clientPool);
|
||||
handler = new FtpSendingMessageHandler(clientPool);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void send() throws Exception {
|
||||
File file = File.createTempFile("test", "");
|
||||
consumer.onMessage(new GenericMessage<File>(file));
|
||||
handler.handleMessage(new GenericMessage<File>(file));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
||||
Reference in New Issue
Block a user