INT-1848 Add order Attribute to (s)ftp Outbound Adapters

This commit is contained in:
Gary Russell
2011-03-25 13:54:15 -04:00
parent 015c059cd9
commit 6eb31e7e09
6 changed files with 80 additions and 10 deletions

View File

@@ -72,6 +72,17 @@
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="order" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Specifies the order for invocation when this endpoint is connected as a
subscriber to a channel. This is particularly relevant when that channel
is using a "failover" dispatching strategy, or when a failure in the delivery to one subscriber should signal that
the message should not be sent to subscribers with a higher 'order' attribute. It has no effect when this
endpoint itself is a Polling Consumer for a channel with a queue.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

View File

@@ -23,9 +23,20 @@
charset="UTF-8"
remote-file-separator="."
temporary-file-suffix=".foo"
remote-filename-generator="fileNameGenerator"/>
remote-filename-generator="fileNameGenerator"
order="23"/>
<int:channel id="ftpChannel"/>
<int-ftp:outbound-channel-adapter id="ftpOutbound2"
channel="ftpChannel"
session-factory="ftpSessionFactory"
remote-directory="foo/bar"
charset="UTF-8"
remote-file-separator="."
temporary-file-suffix=".foo"
remote-filename-generator="fileNameGenerator"
order="12"/>
<int:publish-subscribe-channel id="ftpChannel"/>
<bean id="fileNameGenerator" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.integration.file.FileNameGenerator"/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
@@ -19,11 +19,16 @@ package org.springframework.integration.ftp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertSame;
import java.util.Iterator;
import java.util.Set;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.file.remote.handler.FileTransferringMessageHandler;
import org.springframework.integration.file.remote.session.CachingSessionFactory;
@@ -32,6 +37,7 @@ import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
* @author Gary Russell
* @since 2.0
*/
public class FtpOutboundChannelAdapterParserTests {
@@ -42,7 +48,8 @@ public class FtpOutboundChannelAdapterParserTests {
new ClassPathXmlApplicationContext("FtpOutboundChannelAdapterParserTests-context.xml", this.getClass());
Object consumer = ac.getBean("ftpOutbound");
assertTrue(consumer instanceof EventDrivenConsumer);
assertEquals(ac.getBean("ftpChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
PublishSubscribeChannel channel = ac.getBean("ftpChannel", PublishSubscribeChannel.class);
assertEquals(channel, TestUtils.getPropertyValue(consumer, "inputChannel"));
assertEquals("ftpOutbound", ((EventDrivenConsumer)consumer).getComponentName());
FileTransferringMessageHandler handler = (FileTransferringMessageHandler) TestUtils.getPropertyValue(consumer, "handler");
String remoteFileSeparator = (String) TestUtils.getPropertyValue(handler, "remoteFileSeparator");
@@ -56,5 +63,15 @@ public class FtpOutboundChannelAdapterParserTests {
DefaultFtpSessionFactory sf = (DefaultFtpSessionFactory) TestUtils.getPropertyValue(cacheSf, "sessionFactory");
assertEquals("localhost", TestUtils.getPropertyValue(sf, "host"));
assertEquals(22, TestUtils.getPropertyValue(sf, "port"));
assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
//verify subscription order
@SuppressWarnings("unchecked")
Set<MessageHandler> handlers = (Set<MessageHandler>) TestUtils
.getPropertyValue(
TestUtils.getPropertyValue(channel, "dispatcher"),
"handlers");
Iterator<MessageHandler> iterator = handlers.iterator();
assertSame(TestUtils.getPropertyValue(ac.getBean("ftpOutbound2"), "handler"), iterator.next());
assertSame(handler, iterator.next());
}
}

View File

@@ -113,6 +113,17 @@
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="order" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Specifies the order for invocation when this endpoint is connected as a
subscriber to a channel. This is particularly relevant when that channel
is using a "failover" dispatching strategy, or when a failure in the delivery to one subscriber should signal that
the message should not be sent to subscribers with a higher 'order' attribute. It has no effect when this
endpoint itself is a Polling Consumer for a channel with a queue.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>

View File

@@ -18,7 +18,7 @@
<property name="user" value="oleg"/>
</bean>
<int:channel id="inputChannel"/>
<int:publish-subscribe-channel id="inputChannel"/>
<int-sftp:outbound-channel-adapter id="sftpOutboundAdapter"
session-factory="sftpSessionFactory"
@@ -27,14 +27,16 @@
remote-filename-generator="fileNameGenerator"
remote-file-separator="."
temporary-file-suffix=".bar"
remote-directory="foo/bar"/>
remote-directory="foo/bar"
order="23"/>
<int-sftp:outbound-channel-adapter id="sftpOutboundAdapterWithExpression"
session-factory="sftpSessionFactory"
channel="inputChannel"
charset="UTF-8"
remote-directory-expression="'foo' + '/' + 'bar'"
remote-filename-generator-expression="payload.getName() + '-foo'"/>
remote-filename-generator-expression="payload.getName() + '-foo'"
order="12"/>
<int-sftp:outbound-channel-adapter
session-factory="sftpSessionFactory"

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
@@ -19,6 +19,10 @@ package org.springframework.integration.sftp.config;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertSame;
import java.util.Iterator;
import java.util.Set;
import org.junit.Test;
@@ -28,6 +32,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpression;
import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.file.FileNameGenerator;
import org.springframework.integration.file.remote.handler.FileTransferringMessageHandler;
@@ -37,6 +43,7 @@ import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
* @author Gary Russell
*
*/
public class OutboundChannelAdapterParserTests {
@@ -47,7 +54,8 @@ public class OutboundChannelAdapterParserTests {
new ClassPathXmlApplicationContext("OutboundChannelAdapterParserTests-context.xml", this.getClass());
Object consumer = context.getBean("sftpOutboundAdapter");
assertTrue(consumer instanceof EventDrivenConsumer);
assertEquals(context.getBean("inputChannel"), TestUtils.getPropertyValue(consumer, "inputChannel"));
PublishSubscribeChannel channel = context.getBean("inputChannel", PublishSubscribeChannel.class);
assertEquals(channel, TestUtils.getPropertyValue(consumer, "inputChannel"));
assertEquals("sftpOutboundAdapter", ((EventDrivenConsumer)consumer).getComponentName());
FileTransferringMessageHandler handler = (FileTransferringMessageHandler) TestUtils.getPropertyValue(consumer, "handler");
String remoteFileSeparator = (String) TestUtils.getPropertyValue(handler, "remoteFileSeparator");
@@ -64,6 +72,16 @@ public class OutboundChannelAdapterParserTests {
DefaultSftpSessionFactory clientFactory = (DefaultSftpSessionFactory) TestUtils.getPropertyValue(sessionFactory, "sessionFactory");
assertEquals("localhost", TestUtils.getPropertyValue(clientFactory, "host"));
assertEquals(2222, TestUtils.getPropertyValue(clientFactory, "port"));
assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
//verify subscription order
@SuppressWarnings("unchecked")
Set<MessageHandler> handlers = (Set<MessageHandler>) TestUtils
.getPropertyValue(
TestUtils.getPropertyValue(channel, "dispatcher"),
"handlers");
Iterator<MessageHandler> iterator = handlers.iterator();
assertSame(TestUtils.getPropertyValue(context.getBean("sftpOutboundAdapterWithExpression"), "handler"), iterator.next());
assertSame(handler, iterator.next());
}
@Test