INT-4057: Router: don't use convert for Class key
JIRA: https://jira.spring.io/browse/INT-4057 When general router `channelKey` returns just a `Class<?>` result, we end up with the `unsupported return type for router [class java.lang.Class]` and forced to to call its `getName()` in the target application code before returning to router. * Change the `AbstractMappingMessageRouter` logic to treat `Class<?>` as a special String-aware case, use its `getName()` and don't go to the `ConversionService` * Increase receive timeout for replies in the `TcpInboundGatewayTests`
This commit is contained in:
committed by
Gary Russell
parent
e90d74aefa
commit
a7dc7c3912
@@ -281,6 +281,9 @@ public abstract class AbstractMappingMessageRouter extends AbstractMessageRouter
|
||||
else if (channelKey instanceof String) {
|
||||
addChannelFromString(channels, (String) channelKey, message);
|
||||
}
|
||||
else if (channelKey instanceof Class) {
|
||||
addChannelFromString(channels, ((Class<?>) channelKey).getName(), message);
|
||||
}
|
||||
else if (channelKey instanceof String[]) {
|
||||
for (String indicatorName : (String[]) channelKey) {
|
||||
addChannelFromString(channels, indicatorName, message);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -40,6 +40,7 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class MethodInvokingRouterTests {
|
||||
|
||||
@@ -548,6 +549,32 @@ public class MethodInvokingRouterTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassAsKeyResolution() {
|
||||
QueueChannel stringsChannel = new QueueChannel();
|
||||
QueueChannel numbersChannel = new QueueChannel();
|
||||
TestChannelResolver channelResolver = new TestChannelResolver();
|
||||
channelResolver.addChannel("stringsChannel", stringsChannel);
|
||||
channelResolver.addChannel("numbersChannel", numbersChannel);
|
||||
|
||||
MethodInvokingRouter router = new MethodInvokingRouter(new ClassAsKeyTestBean());
|
||||
router.setChannelResolver(channelResolver);
|
||||
router.setChannelMapping(String.class.getName(), "stringsChannel");
|
||||
router.setChannelMapping(Integer.class.getName(), "numbersChannel");
|
||||
|
||||
Message<?> message = new GenericMessage<>("bar");
|
||||
router.handleMessage(message);
|
||||
Message<?> replyMessage = stringsChannel.receive(10000);
|
||||
assertNotNull(replyMessage);
|
||||
assertEquals(message, replyMessage);
|
||||
|
||||
message = new GenericMessage<>(11);
|
||||
router.handleMessage(message);
|
||||
replyMessage = numbersChannel.receive(10000);
|
||||
assertNotNull(replyMessage);
|
||||
assertEquals(message, replyMessage);
|
||||
}
|
||||
|
||||
|
||||
public static class SingleChannelNameRoutingTestBean {
|
||||
|
||||
@@ -668,4 +695,12 @@ public class MethodInvokingRouterTests {
|
||||
|
||||
}
|
||||
|
||||
private static class ClassAsKeyTestBean {
|
||||
|
||||
public Class<?> routePayload(Object payload) {
|
||||
return payload.getClass();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user