INT-1792 added support for sub-types of an array type to the PayloadTypeRouter

This commit is contained in:
Oleg Zhurakousky
2011-03-08 07:39:24 -05:00
parent c0ea0ef882
commit 3a1bd0fdcd
3 changed files with 16 additions and 4 deletions

View File

@@ -51,11 +51,15 @@ public class PayloadTypeRouter extends AbstractMessageRouter {
private String getChannelName(Message<?> message) {
Class<?> type = message.getPayload().getClass();
boolean array = type.isArray();
if (array){
type = type.getComponentType();
}
while (type != null && !CollectionUtils.isEmpty(this.channelIdentifierMap)) {
String mappingName = null;
if (type.isArray()){
mappingName = type.getComponentType().getName()+"[]";
if (array){
mappingName = type.getName()+"[]";
}
else {
mappingName = type.getName();

View File

@@ -16,12 +16,16 @@
<channel id="channel3">
<queue capacity="1" />
</channel>
<channel id="channel4">
<queue capacity="1" />
</channel>
<channel id="routingChannel" />
<payload-type-router input-channel="routingChannel">
<mapping type="java.lang.String" channel="channel1" />
<mapping type="java.lang.Integer" channel="channel2" />
<mapping type="java.lang.Integer[]" channel="channel3" />
<mapping type="java.lang.Number[]" channel="channel3" />
<mapping type="java.lang.Long[]" channel="channel4" />
</payload-type-router>
<gateway id="testService"

View File

@@ -54,15 +54,19 @@ public class PayloadTypeRouterParserTests {
Message<?> message1 = MessageBuilder.withPayload("Hello").build();
Message<?> message2 = MessageBuilder.withPayload(25).build();
Message<?> message3 = MessageBuilder.withPayload(new Integer[]{23, 24, 34}).build();
Message<?> message4 = MessageBuilder.withPayload(new Long[]{23L, 24L, 34L}).build();
testService.foo(message1);
testService.foo(message2);
testService.foo(message3);
testService.foo(message4);
PollableChannel chanel1 = (PollableChannel) context.getBean("channel1");
PollableChannel chanel2 = (PollableChannel) context.getBean("channel2");
PollableChannel chanel3 = (PollableChannel) context.getBean("channel3");
PollableChannel chanel4 = (PollableChannel) context.getBean("channel4");
assertTrue(chanel1.receive(0).getPayload() instanceof String);
assertTrue(chanel2.receive(0).getPayload() instanceof Integer);
System.out.println(chanel3.receive(0).getPayload());
assertTrue(chanel3.receive(0).getPayload().getClass().isArray());
assertTrue(chanel4.receive(0).getPayload().getClass().isArray());
}
@Test(expected=BeanDefinitionStoreException.class)