renamed getChannelIndicatorList method to getChannelIdentifiers on AbstractMessageRouter
This commit is contained in:
@@ -54,7 +54,7 @@ class AbstractMessageProcessingRouter extends AbstractMessageRouter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
Object result = this.messageProcessor.processMessage(message);
|
||||
List<Object> asList = new ArrayList<Object>();
|
||||
asList.add(result);
|
||||
|
||||
@@ -190,7 +190,7 @@ public abstract class AbstractMessageRouter extends AbstractMessageHandler {
|
||||
private Collection<MessageChannel> determineTargetChannels(Message<?> message) {
|
||||
this.afterPropertiesSet();
|
||||
Collection<MessageChannel> channels = new ArrayList<MessageChannel>();
|
||||
Collection<Object> channelsReturned = this.getChannelIndicatorList(message);
|
||||
Collection<Object> channelsReturned = this.getChannelIdentifiers(message);
|
||||
addToCollection(channels, channelsReturned, message);
|
||||
return channels;
|
||||
}
|
||||
@@ -205,7 +205,7 @@ public abstract class AbstractMessageRouter extends AbstractMessageHandler {
|
||||
/**
|
||||
* Subclasses must implement this method to return the channel identifiers.
|
||||
*/
|
||||
protected abstract List<Object> getChannelIndicatorList(Message<?> message);
|
||||
protected abstract List<Object> getChannelIdentifiers(Message<?> message);
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.integration.Message;
|
||||
public abstract class AbstractSingleChannelNameRouter extends AbstractMessageRouter {
|
||||
|
||||
@Override
|
||||
protected final List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected final List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
List<Object> channelList = new ArrayList<Object>();
|
||||
String channelName = determineTargetChannelName(message);
|
||||
if(channelName != null){
|
||||
|
||||
@@ -33,21 +33,20 @@ import org.springframework.integration.MessageChannel;
|
||||
public class ErrorMessageExceptionTypeRouter extends AbstractMessageRouter {
|
||||
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
String channelName = null;
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
String channelIdentifier = null;
|
||||
Object payload = message.getPayload();
|
||||
if (payload != null && (payload instanceof Throwable)) {
|
||||
if (payload != null && (payload instanceof Throwable) && this.channelIdentifierMap != null) {
|
||||
Throwable mostSpecificCause = (Throwable) payload;
|
||||
while (mostSpecificCause != null) {
|
||||
channelIdentifier = mostSpecificCause.getClass().getName();
|
||||
if (channelIdentifierMap != null){
|
||||
String tempChannelName = channelIdentifierMap.get(channelIdentifier);
|
||||
channelName = tempChannelName == null ? channelName : tempChannelName;
|
||||
String mappedChannelIdentifier = this.channelIdentifierMap.get(mostSpecificCause.getClass().getName());
|
||||
if (mappedChannelIdentifier != null) {
|
||||
channelIdentifier = mappedChannelIdentifier;
|
||||
}
|
||||
mostSpecificCause = mostSpecificCause.getCause();
|
||||
}
|
||||
}
|
||||
return Collections.singletonList((Object)channelName);
|
||||
return Collections.singletonList((Object) channelIdentifier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class HeaderValueRouter extends AbstractMessageRouter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
Object value = message.getHeaders().get(this.headerName);
|
||||
if (value instanceof String && ((String) value).indexOf(',') != -1) {
|
||||
value = StringUtils.tokenizeToStringArray((String) value, ",", true, true);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class PayloadTypeRouter extends AbstractMessageRouter {
|
||||
* preferring direct interface over indirect subclass
|
||||
*/
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
Class<?> firstInterfaceMatch = null;
|
||||
Class<?> type = message.getPayload().getClass();
|
||||
while (type != null && !CollectionUtils.isEmpty(this.channelIdentifierMap)) {
|
||||
|
||||
@@ -91,7 +91,7 @@ public class RecipientListRouter extends AbstractMessageRouter implements Initia
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
List<Object> channels = new ArrayList<Object>();
|
||||
List<Recipient> recipientList = this.recipients;
|
||||
for (Recipient recipient : recipientList) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class MultiChannelRouterTests {
|
||||
public void routeWithChannelMapping() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
public List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] {"channel1", "channel2"});
|
||||
}
|
||||
};
|
||||
@@ -64,7 +64,7 @@ public class MultiChannelRouterTests {
|
||||
public void channelNameLookupFailure() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
public List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] {"noSuchChannel"} );
|
||||
}
|
||||
};
|
||||
@@ -78,7 +78,7 @@ public class MultiChannelRouterTests {
|
||||
public void channelMappingNotAvailable() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
public List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] {"noSuchChannel"});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -56,17 +56,17 @@ public class PayloadTypeRouterTests {
|
||||
|
||||
Message<String> message1 = new GenericMessage<String>("test");
|
||||
Message<Integer> message2 = new GenericMessage<Integer>(123);
|
||||
assertEquals(1, router.getChannelIndicatorList(message1).size());
|
||||
assertEquals("stringChannel", router.getChannelIndicatorList(message1).iterator().next());
|
||||
assertEquals(1, router.getChannelIndicatorList(message2).size());
|
||||
assertEquals("integerChannel", router.getChannelIndicatorList(message2).iterator().next());
|
||||
assertEquals(1, router.getChannelIdentifiers(message1).size());
|
||||
assertEquals("stringChannel", router.getChannelIdentifiers(message1).iterator().next());
|
||||
assertEquals(1, router.getChannelIdentifiers(message2).size());
|
||||
assertEquals("integerChannel", router.getChannelIdentifiers(message2).iterator().next());
|
||||
|
||||
// validate dynamics
|
||||
QueueChannel newChannel = new QueueChannel();
|
||||
beanFactory.registerSingleton("newChannel", newChannel);
|
||||
router.setChannelMapping(String.class.getName(), "newChannel");
|
||||
assertEquals(1, router.getChannelIndicatorList(message1).size());
|
||||
assertEquals("newChannel", router.getChannelIndicatorList(message1).iterator().next());
|
||||
assertEquals(1, router.getChannelIdentifiers(message1).size());
|
||||
assertEquals("newChannel", router.getChannelIdentifiers(message1).iterator().next());
|
||||
// validate nothing happens if mappings were removed and resolutionRequires = false
|
||||
router.removeChannelMapping(String.class.getName());
|
||||
router.removeChannelMapping(Integer.class.getName());
|
||||
@@ -108,7 +108,7 @@ public class PayloadTypeRouterTests {
|
||||
QueueChannel newChannel = new QueueChannel();
|
||||
beanFactory.registerSingleton("newChannel", newChannel);
|
||||
router.setChannelMapping(Integer.class.getName(), "newChannel");
|
||||
assertEquals(1, router.getChannelIndicatorList(message).size());
|
||||
assertEquals(1, router.getChannelIdentifiers(message).size());
|
||||
router.handleMessage(message);
|
||||
result = newChannel.receive(10);
|
||||
assertNotNull(result);
|
||||
@@ -208,7 +208,7 @@ public class PayloadTypeRouterTests {
|
||||
QueueChannel newChannel = new QueueChannel();
|
||||
beanFactory.registerSingleton("newChannel", newChannel);
|
||||
router.setChannelMapping(Integer.class.getName(), "newChannel");
|
||||
assertEquals(1, router.getChannelIndicatorList(message).size());
|
||||
assertEquals(1, router.getChannelIdentifiers(message).size());
|
||||
router.handleMessage(message);
|
||||
result = newChannel.receive(10);
|
||||
assertNotNull(result);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class RouterTests {
|
||||
public void nullChannelIgnoredByDefault() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -55,7 +55,7 @@ public class RouterTests {
|
||||
public void nullChannelThrowsExceptionWhenResolutionRequired() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -68,7 +68,7 @@ public class RouterTests {
|
||||
public void emptyChannelListIgnoredByDefault() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -80,7 +80,7 @@ public class RouterTests {
|
||||
public void emptyChannelListThrowsExceptionWhenResolutionRequired() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -93,7 +93,7 @@ public class RouterTests {
|
||||
public void nullChannelNameArrayIgnoredByDefault() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -106,7 +106,7 @@ public class RouterTests {
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
public void nullChannelNameArrayThrowsExceptionWhenResolutionRequired() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -121,7 +121,7 @@ public class RouterTests {
|
||||
@Test
|
||||
public void emptyChannelNameArrayIgnoredByDefault() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return new ArrayList<Object>();
|
||||
}
|
||||
};
|
||||
@@ -135,7 +135,7 @@ public class RouterTests {
|
||||
public void emptyChannelNameArrayThrowsExceptionWhenResolutionRequired() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] {});
|
||||
}
|
||||
};
|
||||
@@ -161,7 +161,7 @@ public class RouterTests {
|
||||
public void channelMappingIsRequiredWhenResolvingChannelNamesWithMultiChannelRouter() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message){
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message){
|
||||
return CollectionUtils.arrayToList(new String[] { "notImportant" });
|
||||
}
|
||||
};
|
||||
@@ -189,7 +189,7 @@ public class RouterTests {
|
||||
public void beanFactoryWithMultiChannelRouter() {
|
||||
AbstractMessageRouter router = new AbstractMessageRouter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return CollectionUtils.arrayToList(new String[] { "testChannel" });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -206,7 +206,7 @@ public class RouterParserTests {
|
||||
|
||||
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
protected List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
return Collections.singletonList((Object)this.channel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class XPathRouter extends AbstractMessageRouter {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
public List<Object> getChannelIdentifiers(Message<?> message) {
|
||||
Node node = getConverter().convertToNode(message.getPayload());
|
||||
return getXPathExpression().evaluate(node, this.nodeMapper);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class XPathRouterTests {
|
||||
Document doc = XmlTestUtil.getDocumentForString("<doc type=\"one\" />");
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
|
||||
XPathRouter router = new XPathRouter(expression);
|
||||
Object[] channelNames = router.getChannelIndicatorList(new GenericMessage(doc)).toArray();
|
||||
Object[] channelNames = router.getChannelIdentifiers(new GenericMessage(doc)).toArray();
|
||||
assertEquals("Wrong number of channels returned", 1, channelNames.length);
|
||||
assertEquals("Wrong channel name", "one", channelNames[0]);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class XPathRouterTests {
|
||||
Document doc = XmlTestUtil.getDocumentForString("<doc type=\"one\"><book>bOne</book><book>bTwo</book></doc>");
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/book");
|
||||
XPathRouter router = new XPathRouter(expression);
|
||||
Object[] channelNames = router.getChannelIndicatorList(new GenericMessage(doc)).toArray();
|
||||
Object[] channelNames = router.getChannelIdentifiers(new GenericMessage(doc)).toArray();
|
||||
assertEquals("Wrong number of channels returned", 2, channelNames.length);
|
||||
assertEquals("Wrong channel name", "bOne", channelNames[0]);
|
||||
assertEquals("Wrong channel name", "bTwo", channelNames[1]);
|
||||
@@ -63,7 +63,7 @@ public class XPathRouterTests {
|
||||
public void multipleNodeValuesAsString() throws Exception {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/book");
|
||||
XPathRouter router = new XPathRouter(expression);
|
||||
Object[] channelNames = router.getChannelIndicatorList(new GenericMessage("<doc type=\"one\"><book>bOne</book><book>bTwo</book></doc>")).toArray();
|
||||
Object[] channelNames = router.getChannelIdentifiers(new GenericMessage("<doc type=\"one\"><book>bOne</book><book>bTwo</book></doc>")).toArray();
|
||||
assertEquals("Wrong number of channels returned", 2, channelNames.length);
|
||||
assertEquals("Wrong channel name", "bOne", channelNames[0]);
|
||||
assertEquals("Wrong channel name", "bTwo", channelNames[1]);
|
||||
@@ -73,14 +73,14 @@ public class XPathRouterTests {
|
||||
public void nonNodePayload() throws Exception {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
|
||||
XPathRouter router = new XPathRouter(expression);
|
||||
router.getChannelIndicatorList(new GenericMessage<String>("test"));
|
||||
router.getChannelIdentifiers(new GenericMessage<String>("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nodePayload() throws Exception {
|
||||
XPathRouter router = new XPathRouter("./three/text()");
|
||||
Document testDocument = XmlTestUtil.getDocumentForString("<one><two><three>bob</three><three>dave</three></two></one>");
|
||||
Object[] channelNames = router.getChannelIndicatorList(new GenericMessage<Node>(testDocument.getElementsByTagName("two").item(0))).toArray();
|
||||
Object[] channelNames = router.getChannelIdentifiers(new GenericMessage<Node>(testDocument.getElementsByTagName("two").item(0))).toArray();
|
||||
assertEquals("bob",channelNames[0]);
|
||||
assertEquals("dave",channelNames[1]);
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class XPathRouterTests {
|
||||
Document doc = XmlTestUtil.getDocumentForString("<doc type='one' />");
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
|
||||
XPathRouter router = new XPathRouter(expression);
|
||||
Object channelName = router.getChannelIndicatorList(new GenericMessage<Document>(doc)).toArray()[0];
|
||||
Object channelName = router.getChannelIdentifiers(new GenericMessage<Document>(doc)).toArray()[0];
|
||||
assertEquals("Wrong channel name", "one", channelName);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class XPathRouterTests {
|
||||
public void testSimpleStringDoc() throws Exception {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
|
||||
XPathRouter router = new XPathRouter(expression);
|
||||
Object channelName = router.getChannelIndicatorList(new GenericMessage<String>("<doc type='one' />")).toArray()[0];
|
||||
Object channelName = router.getChannelIdentifiers(new GenericMessage<String>("<doc type='one' />")).toArray()[0];
|
||||
assertEquals("Wrong channel name", "one", channelName);
|
||||
}
|
||||
|
||||
@@ -106,14 +106,14 @@ public class XPathRouterTests {
|
||||
public void testNonNodePayload() throws Exception {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/doc/@type");
|
||||
XPathRouter router = new XPathRouter(expression);
|
||||
router.getChannelIndicatorList(new GenericMessage<String>("test"));
|
||||
router.getChannelIdentifiers(new GenericMessage<String>("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNodePayload() throws Exception {
|
||||
XPathRouter router = new XPathRouter("./three/text()");
|
||||
Document testDocument = XmlTestUtil.getDocumentForString("<one><two><three>bob</three></two></one>");
|
||||
Object[] channelNames = router.getChannelIndicatorList(new GenericMessage<Node>(testDocument
|
||||
Object[] channelNames = router.getChannelIdentifiers(new GenericMessage<Node>(testDocument
|
||||
.getElementsByTagName("two").item(0))).toArray();
|
||||
assertEquals("bob", channelNames[0]);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class XPathRouterTests {
|
||||
Document doc = XmlTestUtil.getDocumentForString("<doc type='one' />");
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/somethingelse/@type");
|
||||
XPathRouter router = new XPathRouter(expression);
|
||||
List<Object> channelNames = router.getChannelIndicatorList(new GenericMessage<Document>(doc));
|
||||
List<Object> channelNames = router.getChannelIdentifiers(new GenericMessage<Document>(doc));
|
||||
assertEquals(0, channelNames.size());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user