fixed RouterFactoryBean

This commit is contained in:
Mark Fisher
2011-12-20 17:05:25 -05:00
parent 03754b917a
commit 5fae7d2a1f
4 changed files with 65 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ import org.springframework.expression.Expression;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.router.AbstractMappingMessageRouter;
import org.springframework.integration.router.AbstractMessageRouter;
import org.springframework.integration.router.ExpressionEvaluatingRouter;
import org.springframework.integration.router.MethodInvokingRouter;
import org.springframework.integration.support.channel.ChannelResolver;
@@ -86,7 +87,7 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
@Override
MessageHandler createMethodInvokingHandler(Object targetObject, String targetMethodName) {
Assert.notNull(targetObject, "target object must not be null");
AbstractMappingMessageRouter router = this.extractTypeIfPossible(targetObject, AbstractMappingMessageRouter.class);
AbstractMessageRouter router = this.extractTypeIfPossible(targetObject, AbstractMessageRouter.class);
if (router == null) {
router = this.createMethodInvokingRouter(targetObject, targetMethodName);
this.configureRouter(router);
@@ -114,10 +115,7 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
return router;
}
private AbstractMappingMessageRouter configureRouter(AbstractMappingMessageRouter router) {
if (this.channelMappings != null) {
router.setChannelMappings(this.channelMappings);
}
private AbstractMessageRouter configureRouter(AbstractMessageRouter router) {
if (this.defaultOutputChannel != null) {
router.setDefaultOutputChannel(this.defaultOutputChannel);
}
@@ -130,6 +128,16 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
if (this.ignoreSendFailures != null) {
router.setIgnoreSendFailures(this.ignoreSendFailures);
}
if (router instanceof AbstractMappingMessageRouter) {
this.configureMappingRouter((AbstractMappingMessageRouter) router);
}
return router;
}
private void configureMappingRouter(AbstractMappingMessageRouter router) {
if (this.channelMappings != null) {
router.setChannelMappings(this.channelMappings);
}
if (this.resolutionRequired != null) {
router.setResolutionRequired(this.resolutionRequired);
}
@@ -137,7 +145,6 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
logger.warn("'channel-resolver' attribute has been deprecated in favor of using SpEL via 'expression' attribute");
router.setChannelResolver(this.channelResolver);
}
return router;
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2002-2011 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 java.util.Collection;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.router.AbstractMessageRouter;
/**
* @author Oleg Zhurakousky
*/
public class RfbFixRouter extends AbstractMessageRouter {
@Override
protected Collection<MessageChannel> determineTargetChannels(Message<?> message) {
return null;
}
}

View File

@@ -178,6 +178,11 @@ public class RouterParserTests {
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
}
@Test // should not fail
public void routerFactoryBeanTest(){
new ClassPathXmlApplicationContext("rfb-fix-config.xml", this.getClass());
}
public static class NonExistingChannelRouter{
public String route(String payload){
return "foo";

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<int:router input-channel="input-channel" default-output-channel="discard-channel" ref="errorRouter"/>
<int:channel id="discard-channel"/>
<bean id="errorRouter" class="org.springframework.integration.router.config.RfbFixRouter"/>
</beans>