Added namespace support for the <router/> element (INT-168).

This commit is contained in:
Mark Fisher
2008-05-20 17:56:48 +00:00
parent 6f207bc2d7
commit d3c2fdc0a4
9 changed files with 346 additions and 46 deletions

View File

@@ -34,6 +34,7 @@ import org.springframework.integration.channel.config.PriorityChannelParser;
import org.springframework.integration.channel.config.QueueChannelParser;
import org.springframework.integration.channel.config.RendezvousChannelParser;
import org.springframework.integration.channel.config.ThreadLocalChannelParser;
import org.springframework.integration.router.config.RouterParser;
import org.springframework.integration.router.config.SplitterParser;
import org.springframework.util.ClassUtils;
@@ -67,6 +68,7 @@ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport {
registerBeanDefinitionParser("target-endpoint", new TargetEndpointParser());
registerBeanDefinitionParser("handler", new HandlerParser());
registerBeanDefinitionParser("handler-chain", new HandlerParser());
registerBeanDefinitionParser("router", new RouterParser());
registerBeanDefinitionParser("splitter", new SplitterParser());
registerBeanDefinitionParser("aggregator", new AggregatorParser());
Map<String, Class<? extends BeanDefinitionParser>> parserMappings = this.loadAdapterParserMappings();

View File

@@ -281,6 +281,19 @@
<xsd:attribute name="keep-alive" type="xsd:int"/>
</xsd:complexType>
<xsd:element name="router">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Defines a Router.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="id" type="xsd:ID"/>
<xsd:attribute name="ref" type="xsd:string" use="required"/>
<xsd:attribute name="method" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="splitter">
<xsd:complexType>
<xsd:annotation>

View File

@@ -49,6 +49,11 @@ public class RouterMessageHandlerAdapter extends AbstractMessageHandlerAdapter i
}
}
public RouterMessageHandlerAdapter(Object object, String methodName) {
this.setObject(object);
this.setMethodName(methodName);
}
public void setChannelRegistry(ChannelRegistry channelRegistry) {
this.channelRegistry = channelRegistry;
@@ -60,7 +65,10 @@ public class RouterMessageHandlerAdapter extends AbstractMessageHandlerAdapter i
if (target != null && this.channelRegistry != null && (target instanceof ChannelRegistryAware)) {
((ChannelRegistryAware) target).setChannelRegistry(this.channelRegistry);
}
this.setMessageMapper(new AnnotationMethodMessageMapper(this.getMethod()));
Method method = this.getMethod();
if (method != null) {
this.setMessageMapper(new AnnotationMethodMessageMapper(method));
}
}
@Override

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.router.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.router.RouterMessageHandlerAdapter;
import org.springframework.util.StringUtils;
/**
* Parser for the &lt;router/&gt; element.
*
* @author Mark Fisher
*/
public class RouterParser extends AbstractSingleBeanDefinitionParser {
@Override
protected Class<?> getBeanClass(Element element) {
return RouterMessageHandlerAdapter.class;
}
@Override
protected void doParse(Element element, BeanDefinitionBuilder builder) {
String ref = element.getAttribute("ref");
String methodName = element.getAttribute("method");
if (!StringUtils.hasText(ref) || !StringUtils.hasText(methodName)) {
throw new ConfigurationException(
"The 'ref' and 'method' attributes are both required.");
}
builder.addConstructorArgReference(ref);
builder.addConstructorArgValue(methodName);
}
}

View File

@@ -23,8 +23,6 @@ import static org.junit.Assert.assertNull;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.junit.Test;
@@ -46,10 +44,21 @@ import org.springframework.integration.message.StringMessage;
public class RouterMessageHandlerAdapterTests {
@Test
public void testChannelNameResolutionByPayload() throws Exception {
public void testChannelNameResolutionByPayloadConfiguredByMethodReference() throws Exception {
SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean();
Method routingMethod = testBean.getClass().getMethod("routePayload", String.class);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod);
this.doTestChannelNameResolutionByPayload(adapter);
}
@Test
public void testChannelNameResolutionByPayloadConfiguredByMethodName() {
SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean();
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routePayload");
this.doTestChannelNameResolutionByPayload(adapter);
}
private void doTestChannelNameResolutionByPayload(RouterMessageHandlerAdapter adapter) {
Message<String> message = new GenericMessage<String>("123", "bar");
QueueChannel barChannel = new QueueChannel();
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
@@ -121,10 +130,21 @@ public class RouterMessageHandlerAdapterTests {
}
@Test
public void testChannelNameResolutionByMessage() throws Exception {
public void testChannelNameResolutionByMessageConfiguredByMethodReference() throws Exception {
SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean();
Method routingMethod = testBean.getClass().getMethod("routeMessage", Message.class);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod);
this.doTestChannelNameResolutionByMessage(adapter);
}
@Test
public void testChannelNameResolutionByMessageConfiguredByMethodName() {
SingleChannelNameRoutingTestBean testBean = new SingleChannelNameRoutingTestBean();
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessage");
this.doTestChannelNameResolutionByMessage(adapter);
}
private void doTestChannelNameResolutionByMessage(RouterMessageHandlerAdapter adapter) {
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -151,15 +171,27 @@ public class RouterMessageHandlerAdapterTests {
}
@Test
public void testChannelInstanceResolutionByPayload() throws Exception {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
public void testChannelInstanceResolutionByPayloadConfiguredByMethodReference() throws Exception {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelRegistry);
Method routingMethod = testBean.getClass().getMethod("routePayload", String.class);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod);
this.doTestChannelInstanceResolutionByPayload(adapter, channelRegistry);
}
@Test
public void testChannelInstanceResolutionByPayloadConfiguredByMethodName() {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelRegistry);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routePayload");
this.doTestChannelInstanceResolutionByPayload(adapter, channelRegistry);
}
private void doTestChannelInstanceResolutionByPayload(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -181,15 +213,27 @@ public class RouterMessageHandlerAdapterTests {
}
@Test
public void testChannelInstanceResolutionByMessage() throws Exception {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
public void testChannelInstanceResolutionByMessageConfiguredByMethodReference() throws Exception {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelRegistry);
Method routingMethod = testBean.getClass().getMethod("routeMessage", Message.class);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod);
this.doTestChannelInstanceResolutionByMessage(adapter, channelRegistry);
}
@Test
public void testChannelInstanceResolutionByMessageConfiguredByMethodName() {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
SingleChannelInstanceRoutingTestBean testBean = new SingleChannelInstanceRoutingTestBean(channelRegistry);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessage");
this.doTestChannelInstanceResolutionByMessage(adapter, channelRegistry);
}
private void doTestChannelInstanceResolutionByMessage(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -211,15 +255,27 @@ public class RouterMessageHandlerAdapterTests {
}
@Test
public void testMultiChannelNameResolutionByPayload() throws Exception {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
public void testMultiChannelNameResolutionByPayloadConfiguredByMethodReference() throws Exception {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean();
Method routingMethod = testBean.getClass().getMethod("routePayload", String.class);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod);
this.doTestMultiChannelNameResolutionByPayload(adapter, channelRegistry);
}
@Test
public void testMultiChannelNameResolutionByPayloadConfiguredByMethodName() {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean();
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routePayload");
this.doTestMultiChannelNameResolutionByPayload(adapter, channelRegistry);
}
private void doTestMultiChannelNameResolutionByPayload(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -247,15 +303,27 @@ public class RouterMessageHandlerAdapterTests {
}
@Test
public void testMultiChannelNameResolutionByMessage() throws Exception {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
public void testMultiChannelNameResolutionByMessageConfiguredByMethodReference() throws Exception {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean();
Method routingMethod = testBean.getClass().getMethod("routeMessage", Message.class);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod);
this.doTestMultiChannelNameResolutionByMessage(adapter, channelRegistry);
}
@Test
public void testMultiChannelNameResolutionByMessageConfiguredByMethodName() throws Exception {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean();
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessage");
this.doTestMultiChannelNameResolutionByMessage(adapter, channelRegistry);
}
private void doTestMultiChannelNameResolutionByMessage(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -283,15 +351,27 @@ public class RouterMessageHandlerAdapterTests {
}
@Test
public void testMultiChannelNameArrayResolutionByMessage() throws Exception {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
public void testMultiChannelNameArrayResolutionByMessageConfiguredByMethodReference() throws Exception {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean();
Method routingMethod = testBean.getClass().getMethod("routeMessageToArray", Message.class);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod);
this.doTestMultiChannelNameArrayResolutionByMessage(adapter, channelRegistry);
}
@Test
public void testMultiChannelNameArrayResolutionByMessageConfiguredByMethodName() {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
MultiChannelNameRoutingTestBean testBean = new MultiChannelNameRoutingTestBean();
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessageToArray");
this.doTestMultiChannelNameArrayResolutionByMessage(adapter, channelRegistry);
}
private void doTestMultiChannelNameArrayResolutionByMessage(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -319,15 +399,27 @@ public class RouterMessageHandlerAdapterTests {
}
@Test
public void testMultiChannelListResolutionByPayload() throws Exception {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
public void testMultiChannelListResolutionByPayloadConfiguredByMethodReference() throws Exception {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry);
Method routingMethod = testBean.getClass().getMethod("routePayload", String.class);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod);
this.doTestMultiChannelListResolutionByPayload(adapter, channelRegistry);
}
@Test
public void testMultiChannelListResolutionByPayloadConfiguredByMethodName() {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routePayload");
this.doTestMultiChannelListResolutionByPayload(adapter, channelRegistry);
}
private void doTestMultiChannelListResolutionByPayload(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -355,15 +447,27 @@ public class RouterMessageHandlerAdapterTests {
}
@Test
public void testMultiChannelListResolutionByMessage() throws Exception {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
public void testMultiChannelListResolutionByMessageConfiguredByMethodReference() throws Exception {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry);
Method routingMethod = testBean.getClass().getMethod("routeMessage", Message.class);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod);
this.doTestMultiChannelListResolutionByMessage(adapter, channelRegistry);
}
@Test
public void testMultiChannelListResolutionByMessageConfiguredByMethodName() {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessage");
this.doTestMultiChannelListResolutionByMessage(adapter, channelRegistry);
}
private void doTestMultiChannelListResolutionByMessage(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");
@@ -391,15 +495,27 @@ public class RouterMessageHandlerAdapterTests {
}
@Test
public void testMultiChannelArrayResolutionByMessage() throws Exception {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
public void testMultiChannelArrayResolutionByMessageConfiguredByMethodReference() throws Exception {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry);
Method routingMethod = testBean.getClass().getMethod("routeMessageToArray", Message.class);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, routingMethod);
this.doTestMultiChannelArrayResolutionByMessage(adapter, channelRegistry);
}
@Test
public void testMultiChannelArrayResolutionByMessageConfiguredByMethodName() {
ChannelRegistry channelRegistry = new DefaultChannelRegistry();
MultiChannelInstanceRoutingTestBean testBean = new MultiChannelInstanceRoutingTestBean(channelRegistry);
RouterMessageHandlerAdapter adapter = new RouterMessageHandlerAdapter(testBean, "routeMessageToArray");
this.doTestMultiChannelArrayResolutionByMessage(adapter, channelRegistry);
}
private void doTestMultiChannelArrayResolutionByMessage(RouterMessageHandlerAdapter adapter, ChannelRegistry channelRegistry) {
QueueChannel fooChannel = new QueueChannel();
QueueChannel barChannel = new QueueChannel();
channelRegistry.registerChannel("foo-channel", fooChannel);
channelRegistry.registerChannel("bar-channel", barChannel);
Message<String> fooMessage = new StringMessage("foo");
Message<String> barMessage = new StringMessage("bar");
Message<String> badMessage = new StringMessage("bad");

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.router.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.StringMessage;
/**
* @author Mark Fisher
*/
public class RouterParserTests {
@Test
public void testRouter() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"routerParserTests.xml", this.getClass());
context.start();
MessageChannel input = (MessageChannel) context.getBean("input");
MessageChannel output1 = (MessageChannel) context.getBean("output1");
MessageChannel output2 = (MessageChannel) context.getBean("output2");
input.send(new StringMessage("1"));
Message<?> result1 = output1.receive(1000);
assertEquals("1", result1.getPayload());
assertNull(output2.receive(0));
input.send(new StringMessage("2"));
Message<?> result2 = output2.receive(1000);
assertEquals("2", result2.getPayload());
assertNull(output1.receive(0));
}
}

View File

@@ -32,7 +32,7 @@ import org.springframework.integration.message.StringMessage;
public class SplitterParserTests {
@Test
public void test() {
public void testSplitter() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"splitterParserTests.xml", this.getClass());
context.start();

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.router.config;
/**
* @author Mark Fisher
*/
public class TestRouter {
public String route(int input) {
if (input == 1) {
return "output1";
}
if (input == 2) {
return "output2";
}
return null;
}
}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
<message-bus/>
<channel id="input"/>
<channel id="output1"/>
<channel id="output2"/>
<handler-endpoint handler="router" input-channel="input"/>
<router id="router" ref="pojo" method="route"/>
<beans:bean id="pojo" class="org.springframework.integration.router.config.TestRouter"/>
</beans:beans>