Added RouterFactoryBean. MethodInvokingRouter now provides a constructor to accept the 'targetObject' only (without a method or methodName). It will resolve a single method annotated with @Router or else fallback to a single public method (INT-433, INT-434).
This commit is contained in:
@@ -17,15 +17,21 @@
|
||||
package org.springframework.integration.router.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.annotation.Router;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.router.AbstractMessageRouter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -66,4 +72,60 @@ public class RouterParserTests {
|
||||
assertEquals("99", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refOnlyForAbstractMessageRouterImplementation() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"routerParserTests.xml", this.getClass());
|
||||
context.start();
|
||||
MessageChannel input = (MessageChannel) context.getBean("inputForAbstractMessageRouterImplementation");
|
||||
PollableChannel output = (PollableChannel) context.getBean("output3");
|
||||
input.send(new StringMessage("test-implementation"));
|
||||
Message<?> result = output.receive(0);
|
||||
assertNotNull(result);
|
||||
assertEquals("test-implementation", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refOnlyForAnnotatedObject() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"routerParserTests.xml", this.getClass());
|
||||
context.start();
|
||||
MessageChannel input = (MessageChannel) context.getBean("inputForAnnotatedRouter");
|
||||
PollableChannel output = (PollableChannel) context.getBean("output4");
|
||||
input.send(new StringMessage("test-annotation"));
|
||||
Message<?> result = output.receive(0);
|
||||
assertNotNull(result);
|
||||
assertEquals("test-annotation", result.getPayload());
|
||||
}
|
||||
|
||||
|
||||
public static class TestRouterImplementation extends AbstractMessageRouter {
|
||||
|
||||
private final MessageChannel channel;
|
||||
|
||||
public TestRouterImplementation(MessageChannel channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<MessageChannel> determineTargetChannels(Message<?> message) {
|
||||
return Collections.singletonList(this.channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class AnnotatedTestRouterBean {
|
||||
|
||||
private final MessageChannel channel;
|
||||
|
||||
public AnnotatedTestRouterBean(MessageChannel channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Router
|
||||
public MessageChannel test(String payload) {
|
||||
return this.channel;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,4 +33,28 @@
|
||||
|
||||
<beans:bean id="pojo" class="org.springframework.integration.router.config.TestRouter"/>
|
||||
|
||||
<channel id="output3">
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
|
||||
<channel id="inputForAbstractMessageRouterImplementation"/>
|
||||
|
||||
<router input-channel="inputForAbstractMessageRouterImplementation" ref="implementation"/>
|
||||
|
||||
<beans:bean id="implementation" class="org.springframework.integration.router.config.RouterParserTests$TestRouterImplementation">
|
||||
<beans:constructor-arg ref="output3"/>
|
||||
</beans:bean>
|
||||
|
||||
<channel id="output4">
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
|
||||
<channel id="inputForAnnotatedRouter"/>
|
||||
|
||||
<router input-channel="inputForAnnotatedRouter" ref="annotated"/>
|
||||
|
||||
<beans:bean id="annotated" class="org.springframework.integration.router.config.RouterParserTests$AnnotatedTestRouterBean">
|
||||
<beans:constructor-arg ref="output4"/>
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
Reference in New Issue
Block a user