fixed 'apply-sequence' for DefaultRouterParser and now comma-delimited strings are converted to arrays
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -54,6 +54,8 @@ public class DefaultRouterParser extends AbstractDelegatingConsumerEndpointParse
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "timeout");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "resolution-required");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-channel-name-resolution-failures");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "apply-sequence");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-send-failures");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A base class for router implementations that return only the channel name(s)
|
||||
@@ -135,6 +136,12 @@ public abstract class AbstractChannelNameResolvingMessageRouter extends Abstract
|
||||
}
|
||||
|
||||
protected void addChannelFromString(Collection<MessageChannel> channels, String channelName, Message<?> message) {
|
||||
if (channelName.indexOf(',') != -1) {
|
||||
for (String name : StringUtils.commaDelimitedListToStringArray(channelName)) {
|
||||
addChannelFromString(channels, name, message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (this.prefix != null) {
|
||||
channelName = this.prefix + channelName;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -149,6 +149,29 @@ public class RouterParserTests {
|
||||
assertSame(channelResolverBean, channelResolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sequence() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"routerParserTests.xml", this.getClass());
|
||||
MessageChannel input = context.getBean("sequenceRouter", MessageChannel.class);
|
||||
PollableChannel out1 = context.getBean("sequenceOut1", PollableChannel.class);
|
||||
PollableChannel out2 = context.getBean("sequenceOut2", PollableChannel.class);
|
||||
PollableChannel out3 = context.getBean("sequenceOut3", PollableChannel.class);
|
||||
Message<?> originalMessage = new StringMessage("test");
|
||||
input.send(originalMessage);
|
||||
Message<?> message1 = out1.receive(0);
|
||||
Message<?> message2 = out2.receive(0);
|
||||
Message<?> message3 = out3.receive(0);
|
||||
assertEquals(originalMessage.getHeaders().getId(), message1.getHeaders().getCorrelationId());
|
||||
assertEquals(originalMessage.getHeaders().getId(), message2.getHeaders().getCorrelationId());
|
||||
assertEquals(originalMessage.getHeaders().getId(), message3.getHeaders().getCorrelationId());
|
||||
assertEquals(new Integer(1), message1.getHeaders().getSequenceNumber());
|
||||
assertEquals(new Integer(3), message1.getHeaders().getSequenceSize());
|
||||
assertEquals(new Integer(2), message2.getHeaders().getSequenceNumber());
|
||||
assertEquals(new Integer(3), message2.getHeaders().getSequenceSize());
|
||||
assertEquals(new Integer(3), message3.getHeaders().getSequenceNumber());
|
||||
assertEquals(new Integer(3), message3.getHeaders().getSequenceSize());
|
||||
}
|
||||
|
||||
public static class TestRouterImplementation extends AbstractMessageRouter {
|
||||
|
||||
|
||||
@@ -51,6 +51,20 @@
|
||||
|
||||
<router input-channel="inputForAnnotatedRouter" ref="annotated"/>
|
||||
|
||||
<router input-channel="sequenceRouter" apply-sequence="true" expression="'sequenceOut1,sequenceOut2,sequenceOut3'"/>
|
||||
|
||||
<channel id="sequenceOut1">
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<channel id="sequenceOut2">
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<channel id="sequenceOut3">
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<beans:bean id="annotated" class="org.springframework.integration.router.config.RouterParserTests$AnnotatedTestRouterBean">
|
||||
<beans:constructor-arg ref="output4"/>
|
||||
</beans:bean>
|
||||
|
||||
Reference in New Issue
Block a user