INT-2299
put back 'channel-resolver' attribute with deprecation warnings INT-2299 polishing INT-2299 added XPATH test
This commit is contained in:
committed by
Mark Fisher
parent
052c325dfa
commit
0a8b348c98
@@ -15,12 +15,16 @@ package org.springframework.integration.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
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.ExpressionEvaluatingRouter;
|
||||
import org.springframework.integration.router.MethodInvokingRouter;
|
||||
import org.springframework.integration.support.channel.ChannelResolver;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -33,6 +37,8 @@ import org.springframework.util.StringUtils;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private volatile Map<String, String> channelMappings;
|
||||
|
||||
@@ -45,8 +51,14 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
|
||||
private volatile Boolean applySequence;
|
||||
|
||||
private volatile Boolean ignoreSendFailures;
|
||||
|
||||
private volatile ChannelResolver channelResolver;
|
||||
|
||||
|
||||
public void setChannelResolver(ChannelResolver channelResolver) {
|
||||
this.channelResolver = channelResolver;
|
||||
}
|
||||
|
||||
public void setDefaultOutputChannel(MessageChannel defaultOutputChannel) {
|
||||
this.defaultOutputChannel = defaultOutputChannel;
|
||||
}
|
||||
@@ -75,6 +87,10 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
|
||||
MessageHandler createMethodInvokingHandler(Object targetObject, String targetMethodName) {
|
||||
Assert.notNull(targetObject, "target object must not be null");
|
||||
AbstractMappingMessageRouter router = this.extractTypeIfPossible(targetObject, AbstractMappingMessageRouter.class);
|
||||
if (this.channelResolver != null){
|
||||
logger.warn("'channel-resolver' attribute has been deprecated in favor of using SpEL via 'expression' attribute");
|
||||
router.setChannelResolver(this.channelResolver);
|
||||
}
|
||||
if (router == null) {
|
||||
router = this.createMethodInvokingRouter(targetObject, targetMethodName);
|
||||
this.configureRouter(router);
|
||||
|
||||
@@ -43,6 +43,7 @@ public abstract class AbstractRouterParser extends AbstractConsumerEndpointParse
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "resolution-required");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "apply-sequence");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-send-failures");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "channel-resolver");
|
||||
BeanDefinition targetRouterBeanDefinition = this.parseRouter(element, parserContext);
|
||||
builder.addPropertyValue("targetObject", targetRouterBeanDefinition);
|
||||
return builder;
|
||||
|
||||
@@ -68,9 +68,12 @@ public abstract class AbstractMappingMessageRouter extends AbstractMessageRouter
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - since 2.1 in favor of using SpEL via 'expression' attribute
|
||||
*
|
||||
* Specify the {@link ChannelResolver} strategy to use.
|
||||
* The default is a BeanFactoryChannelResolver.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setChannelResolver(ChannelResolver channelResolver) {
|
||||
Assert.notNull(channelResolver, "'channelResolver' must not be null");
|
||||
this.channelResolver = channelResolver;
|
||||
|
||||
@@ -2869,6 +2869,20 @@ endpoint itself is a Polling Consumer for a channel with a queue.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="channel-resolver" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
[DEPRECATED]Provides a reference to a ChannelResolver that resolves the return value
|
||||
to the name of a MessageChannel within the application context. If none
|
||||
is provided, the return value is expected to match a channel name exactly.
|
||||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.core.ChannelResolver" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="ignore-send-failures" default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</channel>
|
||||
|
||||
<channel id="routingChannel" />
|
||||
<payload-type-router input-channel="routingChannel">
|
||||
<payload-type-router id="routerWithChannelResolver" input-channel="routingChannel" channel-resolver="cr">
|
||||
<mapping type="java.lang.String" channel="channel1" />
|
||||
<mapping type="java.lang.Integer" channel="channel2" />
|
||||
<mapping type="java.lang.Number[]" channel="channel3" />
|
||||
@@ -32,4 +32,5 @@
|
||||
service-interface="org.springframework.integration.router.config.PayloadTypeRouterParserTests$TestService"
|
||||
default-request-channel="routingChannel" />
|
||||
|
||||
<beans:bean id="cr" class="org.springframework.integration.router.config.PayloadTypeRouterParserTests.MyChannelResolver"/>
|
||||
</beans:beans>
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.integration.router.config;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -31,10 +29,16 @@ import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
@@ -67,6 +71,9 @@ public class PayloadTypeRouterParserTests {
|
||||
assertTrue(chanel2.receive(100).getPayload() instanceof Integer);
|
||||
assertTrue(chanel3.receive(100).getPayload().getClass().isArray());
|
||||
assertTrue(chanel4.receive(100).getPayload().getClass().isArray());
|
||||
|
||||
EventDrivenConsumer edc = context.getBean("routerWithChannelResolver", EventDrivenConsumer.class);
|
||||
assertEquals(context.getBean("cr"), TestUtils.getPropertyValue(edc, "handler.channelResolver"));
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
@@ -110,4 +117,5 @@ public class PayloadTypeRouterParserTests {
|
||||
public void foo(Message<?> message);
|
||||
}
|
||||
|
||||
public static class MyChannelResolver extends BeanFactoryChannelResolver{}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.router.AbstractMappingMessageRouter;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.xml.DefaultXmlPayloadConverter;
|
||||
import org.springframework.integration.xml.util.XmlTestUtil;
|
||||
@@ -265,5 +266,7 @@ public class XPathRouterParserTests {
|
||||
return super.convertToDocument(object);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyChannelResolver extends BeanFactoryChannelResolver{}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@
|
||||
<int-xml:mapping value="channelB" channel="channelA"/>
|
||||
</int-xml:xpath-router>
|
||||
|
||||
<int-xml:xpath-router id="xpathRouterWithCustomConverter" input-channel="customConverterChannel" evaluate-as-string="true" converter="testConverter">
|
||||
<int-xml:xpath-router id="xpathRouterWithCustomConverter"
|
||||
input-channel="customConverterChannel" evaluate-as-string="true"
|
||||
converter="testConverter" channel-resolver="cr">
|
||||
<int-xml:xpath-expression expression="/name"/>
|
||||
</int-xml:xpath-router>
|
||||
|
||||
@@ -44,4 +46,5 @@
|
||||
|
||||
<bean id="testConverter" class="org.springframework.integration.xml.config.XPathRouterParserTests$TestXmlPayloadConverter"/>
|
||||
|
||||
<bean id="cr" class="org.springframework.integration.xml.config.XPathRouterParserTests.MyChannelResolver"/>
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user