Merge remote-tracking branch 'upstream/master' into 4.0.0-WIP
Conflicts: build.gradle gradle.properties spring-integration-core/src/main/java/org/springframework/integration/config/RouterFactoryBean.java spring-integration-core/src/test/java/org/springframework/integration/channel/config/DispatchingChannelParserTests.java spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayProxyFactoryBeanTests.java spring-integration-core/src/test/java/org/springframework/integration/router/config/PayloadTypeRouterParserTests.java spring-integration-core/src/test/java/org/springframework/integration/transformer/MessageTransformingChannelInterceptorTests.java spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryShutDownTests.java spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionReadTests.java spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/DatagramPacketSendingHandlerTests.java spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/MultiClientTests.java spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/UdpChannelAdapterTests.java spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcMessageHandler.java spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcOutboundGateway.java spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/StoredProcPollingChannelAdapter.java spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/core/AbstractXmppConnectionAwareEndpoint.java Resolved.
This commit is contained in:
@@ -15,9 +15,6 @@ 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.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.router.AbstractMappingMessageRouter;
|
||||
@@ -26,7 +23,6 @@ import org.springframework.integration.router.ExpressionEvaluatingRouter;
|
||||
import org.springframework.integration.router.MethodInvokingRouter;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.core.DestinationResolver;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -41,8 +37,6 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private volatile Map<String, String> channelMappings;
|
||||
|
||||
private volatile MessageChannel defaultOutputChannel;
|
||||
@@ -55,12 +49,6 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
|
||||
|
||||
private volatile Boolean ignoreSendFailures;
|
||||
|
||||
private volatile DestinationResolver<MessageChannel> channelResolver;
|
||||
|
||||
public void setChannelResolver(DestinationResolver<MessageChannel> channelResolver) {
|
||||
this.channelResolver = channelResolver;
|
||||
}
|
||||
|
||||
public void setDefaultOutputChannel(MessageChannel defaultOutputChannel) {
|
||||
this.defaultOutputChannel = defaultOutputChannel;
|
||||
}
|
||||
@@ -146,10 +134,6 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
|
||||
if (this.resolutionRequired != null) {
|
||||
router.setResolutionRequired(this.resolutionRequired);
|
||||
}
|
||||
if (this.channelResolver != null) {
|
||||
logger.warn("'channel-resolver' attribute has been deprecated in favor of using SpEL via 'expression' attribute");
|
||||
router.setChannelResolver(this.channelResolver);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,7 +144,7 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
|
||||
private boolean noRouterAttributesProvided() {
|
||||
return this.channelMappings == null && this.defaultOutputChannel == null
|
||||
&& this.timeout == null && this.resolutionRequired == null && this.applySequence == null
|
||||
&& this.ignoreSendFailures == null && this.channelResolver == null;
|
||||
&& this.ignoreSendFailures == null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -119,17 +119,6 @@ public abstract class AbstractOutboundChannelAdapterParser extends AbstractChann
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to control the registration process and return the bean name.
|
||||
* If parsing a bean definition whose name can be auto-generated, consider using
|
||||
* {@link #parseConsumer(Element, ParserContext)} instead.
|
||||
* @deprecated Use {@link #doParseAndRegisterConsumer(Element, ParserContext)}
|
||||
*/
|
||||
@Deprecated
|
||||
protected String parseAndRegisterConsumer(Element element, ParserContext parserContext) {
|
||||
return doParseAndRegisterConsumer(element, parserContext).getBeanName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to control the registration process and return the bean name.
|
||||
* If parsing a bean definition whose name can be auto-generated, consider using
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -30,7 +30,7 @@ import org.springframework.util.xml.DomUtils;
|
||||
|
||||
/**
|
||||
* Base parser for routers.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractRouterParser extends AbstractConsumerEndpointParser {
|
||||
@@ -43,7 +43,6 @@ 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;
|
||||
|
||||
@@ -27,6 +27,9 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.integration.config.ExpressionFactoryBean;
|
||||
import org.springframework.integration.gateway.GatewayMethodMetadata;
|
||||
import org.springframework.integration.gateway.GatewayProxyFactoryBean;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -105,7 +108,7 @@ public class GatewayParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
if (hasDefaultHeaders || hasDefaultPayloadExpression) {
|
||||
BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
"org.springframework.integration.gateway.GatewayMethodMetadata");
|
||||
GatewayMethodMetadata.class);
|
||||
this.setMethodInvocationHeaders(methodMetadataBuilder, invocationHeaders);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(methodMetadataBuilder, element,
|
||||
"default-payload-expression", "payloadExpression");
|
||||
@@ -120,7 +123,7 @@ public class GatewayParser extends AbstractSimpleBeanDefinitionParser {
|
||||
for (Element methodElement : elements) {
|
||||
String methodName = methodElement.getAttribute("name");
|
||||
BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
"org.springframework.integration.gateway.GatewayMethodMetadata");
|
||||
GatewayMethodMetadata.class);
|
||||
methodMetadataBuilder.addPropertyValue("requestChannelName", methodElement.getAttribute("request-channel"));
|
||||
methodMetadataBuilder.addPropertyValue("replyChannelName", methodElement.getAttribute("reply-channel"));
|
||||
methodMetadataBuilder.addPropertyValue("requestTimeout", methodElement.getAttribute("request-timeout"));
|
||||
@@ -151,11 +154,11 @@ public class GatewayParser extends AbstractSimpleBeanDefinitionParser {
|
||||
}
|
||||
RootBeanDefinition expressionDef = null;
|
||||
if (hasValue) {
|
||||
expressionDef = new RootBeanDefinition("org.springframework.expression.common.LiteralExpression");
|
||||
expressionDef = new RootBeanDefinition(LiteralExpression.class);
|
||||
expressionDef.getConstructorArgumentValues().addGenericArgumentValue(headerValue);
|
||||
}
|
||||
else if (hasExpression) {
|
||||
expressionDef = new RootBeanDefinition("org.springframework.integration.config.ExpressionFactoryBean");
|
||||
expressionDef = new RootBeanDefinition(ExpressionFactoryBean.class);
|
||||
expressionDef.getConstructorArgumentValues().addGenericArgumentValue(headerExpression);
|
||||
}
|
||||
if (expressionDef != null) {
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.config.TypedStringValue;
|
||||
@@ -43,8 +41,6 @@ import org.springframework.util.xml.DomUtils;
|
||||
*/
|
||||
public class PointToPointChannelParser extends AbstractChannelParser {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@Override
|
||||
protected BeanDefinitionBuilder buildBeanDefinition(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = null;
|
||||
@@ -83,19 +79,10 @@ public class PointToPointChannelParser extends AbstractChannelParser {
|
||||
|
||||
Element dispatcherElement = DomUtils.getChildElementByTagName(element, "dispatcher");
|
||||
|
||||
// check for the dispatcher attribute (deprecated)
|
||||
String dispatcherAttribute = element.getAttribute("dispatcher");
|
||||
boolean hasDispatcherAttribute = StringUtils.hasText(dispatcherAttribute);
|
||||
if (hasDispatcherAttribute && logger.isWarnEnabled()) {
|
||||
logger.warn("The 'dispatcher' attribute on the 'channel' element is deprecated. "
|
||||
+ "Please use the 'dispatcher' sub-element instead.");
|
||||
}
|
||||
|
||||
// verify that a dispatcher is not provided if a queue sub-element exists
|
||||
if (queueElement != null && (dispatcherElement != null || hasDispatcherAttribute)) {
|
||||
if (queueElement != null && dispatcherElement != null) {
|
||||
parserContext.getReaderContext().error(
|
||||
"The 'dispatcher' attribute or sub-element " + "and any queue sub-element are mutually exclusive.",
|
||||
element);
|
||||
"The 'dispatcher' sub-element and any queue sub-element are mutually exclusive.", element);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -103,24 +90,7 @@ public class PointToPointChannelParser extends AbstractChannelParser {
|
||||
return builder;
|
||||
}
|
||||
|
||||
if (dispatcherElement != null && hasDispatcherAttribute) {
|
||||
parserContext.getReaderContext().error(
|
||||
"The 'dispatcher' attribute and 'dispatcher' "
|
||||
+ "sub-element are mutually exclusive. NOTE: the attribute is DEPRECATED. "
|
||||
+ "Please use the dispatcher sub-element instead.", element);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (hasDispatcherAttribute) {
|
||||
// this attribute is deprecated, but if set, we need to create a DirectChannel
|
||||
// without any LoadBalancerStrategy and the failover flag set to true (default).
|
||||
builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class);
|
||||
if ("failover".equals(dispatcherAttribute)) {
|
||||
// round-robin dispatcher is used by default, the "failover" value simply disables it
|
||||
builder.addConstructorArgValue(null);
|
||||
}
|
||||
}
|
||||
else if (dispatcherElement == null) {
|
||||
if (dispatcherElement == null) {
|
||||
// configure the default DirectChannel with a RoundRobinLoadBalancingStrategy
|
||||
builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class);
|
||||
}
|
||||
@@ -134,12 +104,22 @@ public class PointToPointChannelParser extends AbstractChannelParser {
|
||||
else {
|
||||
builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class);
|
||||
}
|
||||
// unless the 'load-balancer' attribute is explicitly set to 'none',
|
||||
// unless the 'load-balancer' attribute is explicitly set to 'none' or 'load-balancer-ref' is explicitly configured,
|
||||
// configure the default RoundRobinLoadBalancingStrategy
|
||||
String loadBalancer = dispatcherElement.getAttribute("load-balancer");
|
||||
if ("none".equals(loadBalancer)) {
|
||||
builder.addConstructorArgValue(null);
|
||||
String loadBalancerRef = dispatcherElement.getAttribute("load-balancer-ref");
|
||||
if (StringUtils.hasText(loadBalancer) && StringUtils.hasText(loadBalancerRef)){
|
||||
parserContext.getReaderContext().error("'load-balancer' and 'load-balancer-ref' are mutually exclusive", element);
|
||||
}
|
||||
if (StringUtils.hasText(loadBalancerRef)){
|
||||
builder.addConstructorArgReference(loadBalancerRef);
|
||||
}
|
||||
else {
|
||||
if ("none".equals(loadBalancer)) {
|
||||
builder.addConstructorArgValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, dispatcherElement, "failover");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, dispatcherElement, "max-subscribers");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -27,11 +27,12 @@ import org.springframework.expression.Expression;
|
||||
* <p>
|
||||
* The sub-element of a <gateway> element would look like this:
|
||||
* <method name="echo" request-channel="inputA" reply-timeout="2" request-timeout="200"/>
|
||||
*
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*/
|
||||
class GatewayMethodMetadata {
|
||||
public class GatewayMethodMetadata {
|
||||
|
||||
private volatile String payloadExpression;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class JsonPropertyAccessor implements PropertyAccessor {
|
||||
/**
|
||||
* The kind of types this can work with.
|
||||
*/
|
||||
private static final Class<?>[] SUPPORTED_CLASSES = new Class[] { String.class, ToStringFriendlyJsonNode.class,
|
||||
private static final Class<?>[] SUPPORTED_CLASSES = new Class<?>[] { String.class, ToStringFriendlyJsonNode.class,
|
||||
ObjectNode.class, ArrayNode.class };
|
||||
|
||||
// Note: ObjectMapper is thread-safe
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -24,9 +24,13 @@ import org.springframework.integration.channel.interceptor.ChannelInterceptorAda
|
||||
/**
|
||||
* A {@link ChannelInterceptor} which invokes a {@link Transformer}
|
||||
* when either sending-to or receiving-from a channel.
|
||||
*
|
||||
*
|
||||
* @deprecated It is not generally recommended to perform functions
|
||||
* such as transformation in a channel interceptor.
|
||||
*
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
@Deprecated
|
||||
public class MessageTransformingChannelInterceptor extends ChannelInterceptorAdapter {
|
||||
|
||||
private final Transformer transformer;
|
||||
|
||||
@@ -286,12 +286,25 @@
|
||||
(i.e. one without a queue).
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="load-balancer-ref" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.integration.dispatcher.LoadBalancingStrategy" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
<xsd:documentation>
|
||||
A reference to a bean that implements the 'org.springframework.integration.dispatcher.LoadBalancingStrategy'.
|
||||
This attribute is mutually exclusive with 'load-balancer'.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="load-balancer">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a load-balancing strategy for the channel's dispatcher.
|
||||
The default is a round-robin load
|
||||
balancer.
|
||||
The default is a round-robin load balancer.
|
||||
This attribute is mutually exclusive with 'load-balancer-ref'.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
@@ -485,27 +498,6 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="dispatcher">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
This attribute is DEPRECATED. Please use the dispatcher sub-element
|
||||
instead.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="failover">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Enables failover, but disables load-balancing.
|
||||
See the dispatcher sub-element for more
|
||||
information.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:enumeration>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="gateway">
|
||||
@@ -3195,20 +3187,6 @@
|
||||
</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.support.channel.ChannelResolver" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="ignore-send-failures">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
|
||||
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -36,6 +37,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.PublishSubscribeChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter;
|
||||
import org.springframework.integration.config.TestChannelInterceptor;
|
||||
import org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy;
|
||||
import org.springframework.integration.dispatcher.UnicastingDispatcher;
|
||||
@@ -90,7 +92,7 @@ public class ChannelParserTests {
|
||||
public void channelWithFailoverDispatcherAttribute() throws Exception {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("channelParserTests.xml", this
|
||||
.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("channelWithFailoverAttribute");
|
||||
MessageChannel channel = (MessageChannel) context.getBean("channelWithFailover");
|
||||
assertEquals(DirectChannel.class, channel.getClass());
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
|
||||
Object dispatcher = accessor.getPropertyValue("dispatcher");
|
||||
@@ -259,4 +261,13 @@ public class ChannelParserTests {
|
||||
assertTrue(threwException);
|
||||
}
|
||||
|
||||
public static class TestInterceptor extends ChannelInterceptorAdapter {
|
||||
|
||||
@Override
|
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
return MessageBuilder.withPayload(message.getPayload().toString().toUpperCase()).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?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/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<int:channel id="myChannel">
|
||||
<int:dispatcher load-balancer-ref="lb2" load-balancer="round-robin"/>
|
||||
</int:channel>
|
||||
|
||||
<bean id="lb"
|
||||
class="org.springframework.integration.channel.config.DispatchingChannelParserTests.SampleLoadBalancingStrategy"/>
|
||||
</beans>
|
||||
@@ -1,13 +1,12 @@
|
||||
<?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
|
||||
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.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<channel id="dispatcherAttribute" dispatcher="failover"/>
|
||||
|
||||
<channel id="taskExecutorOnly">
|
||||
<dispatcher task-executor="taskExecutor"/>
|
||||
</channel>
|
||||
@@ -32,7 +31,13 @@
|
||||
<dispatcher load-balancer="round-robin" task-executor="taskExecutor"/>
|
||||
</channel>
|
||||
|
||||
<beans:bean id="taskExecutor"
|
||||
class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
|
||||
<channel id="lbRefChannel">
|
||||
<dispatcher load-balancer-ref="lb"/>
|
||||
</channel>
|
||||
|
||||
<beans:bean id="taskExecutor"
|
||||
class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
|
||||
|
||||
<beans:bean id="lb"
|
||||
class="org.springframework.integration.channel.config.DispatchingChannelParserTests.SampleLoadBalancingStrategy"/>
|
||||
</beans:beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -20,28 +20,37 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.ExecutorChannel;
|
||||
import org.springframework.integration.dispatcher.LoadBalancingStrategy;
|
||||
import org.springframework.integration.dispatcher.RoundRobinLoadBalancingStrategy;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.util.ErrorHandlingTaskExecutor;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 1.0.3
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -54,20 +63,6 @@ public class DispatchingChannelParserTests {
|
||||
@Autowired
|
||||
private Map<String, MessageChannel> channels;
|
||||
|
||||
|
||||
@Test(expected = FatalBeanException.class)
|
||||
public void dispatcherAttributeAndSubElement() {
|
||||
new ClassPathXmlApplicationContext("dispatcherAttributeAndSubElement.xml", this.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dispatcherAttribute() {
|
||||
MessageChannel channel = channels.get("dispatcherAttribute");
|
||||
assertEquals(DirectChannel.class, channel.getClass());
|
||||
assertTrue((Boolean) getDispatcherProperty("failover", channel));
|
||||
assertNull(getDispatcherProperty("loadBalancingStrategy", channel));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskExecutorOnly() {
|
||||
MessageChannel channel = channels.get("taskExecutorOnly");
|
||||
@@ -132,6 +127,24 @@ public class DispatchingChannelParserTests {
|
||||
new DirectFieldAccessor(executor).getPropertyValue("executor"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadBalancerRef() {
|
||||
MessageChannel channel = channels.get("lbRefChannel");
|
||||
LoadBalancingStrategy lbStrategy = TestUtils.getPropertyValue(channel, "dispatcher.loadBalancingStrategy", LoadBalancingStrategy.class);
|
||||
assertTrue(lbStrategy instanceof SampleLoadBalancingStrategy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadBalancerRefFailWithLoadBalancer() {
|
||||
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("ChannelWithLoadBalancerRef-fail-config.xml", this.getClass());
|
||||
}
|
||||
catch (BeanDefinitionParsingException e) {
|
||||
assertThat(e.getMessage(), Matchers.containsString("'load-balancer' and 'load-balancer-ref' are mutually exclusive"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Object getDispatcherProperty(String propertyName, MessageChannel channel) {
|
||||
return new DirectFieldAccessor(
|
||||
@@ -139,4 +152,11 @@ public class DispatchingChannelParserTests {
|
||||
.getPropertyValue(propertyName);
|
||||
}
|
||||
|
||||
public static class SampleLoadBalancingStrategy implements LoadBalancingStrategy {
|
||||
|
||||
@Override
|
||||
public Iterator<MessageHandler> getHandlerIterator(Message<?> message, Collection<MessageHandler> handlers) {
|
||||
return handlers.iterator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,7 @@
|
||||
<channel id="channelWithInterceptorInnerBean">
|
||||
<queue capacity="5"/>
|
||||
<interceptors>
|
||||
<beans:bean class="org.springframework.integration.transformer.MessageTransformingChannelInterceptor">
|
||||
<beans:constructor-arg>
|
||||
<beans:bean class="org.springframework.integration.channel.config.TestTransformer"/>
|
||||
</beans:constructor-arg>
|
||||
</beans:bean>
|
||||
<beans:bean class="org.springframework.integration.channel.config.ChannelParserTests$TestInterceptor"/>
|
||||
</interceptors>
|
||||
</channel>
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@
|
||||
</channel>
|
||||
|
||||
<channel id="defaultChannel" />
|
||||
|
||||
<channel id="channelWithFailoverAttribute" dispatcher="failover"/>
|
||||
|
||||
<channel id="channelWithFailover">
|
||||
<dispatcher failover="true" load-balancer="none"/>
|
||||
</channel>
|
||||
|
||||
<channel id="channelWithCustomQueue">
|
||||
<queue ref="customQueue"/>
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
<?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.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<channel id="dispatcherAttributeAndSubElement" dispatcher="failover">
|
||||
<dispatcher/>
|
||||
</channel>
|
||||
|
||||
</beans:beans>
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
package org.springframework.integration.gateway;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -37,14 +40,16 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -77,6 +82,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
startResponder(requestChannel);
|
||||
GenericConversionService cs = new DefaultConversionService();
|
||||
Converter<String, byte[]> stringToByteConverter = new Converter<String, byte[]>() {
|
||||
@Override
|
||||
public byte[] convert(String source) {
|
||||
return source.getBytes();
|
||||
}
|
||||
@@ -134,6 +140,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
public void testRequestReplyWithTypeConversion() throws Exception {
|
||||
final QueueChannel requestChannel = new QueueChannel();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Message<?> input = requestChannel.receive();
|
||||
GenericMessage<String> reply = new GenericMessage<String>(input.getPayload() + "456");
|
||||
@@ -184,6 +191,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
for (int i = 0; i < numRequests; i++) {
|
||||
final int count = i;
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// add some randomness to the ordering of requests
|
||||
try {
|
||||
@@ -240,6 +248,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
public void testMessageAsReturnValue() throws Exception {
|
||||
final QueueChannel requestChannel = new QueueChannel();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Message<?> input = requestChannel.receive();
|
||||
GenericMessage<String> reply = new GenericMessage<String>(input.getPayload() + "bar");
|
||||
@@ -291,6 +300,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
DirectChannel channel = new DirectChannel();
|
||||
EventDrivenConsumer consumer = new EventDrivenConsumer(channel, new MessageHandler() {
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) {
|
||||
Method method = ReflectionUtils.findMethod(
|
||||
GatewayProxyFactoryBeanTests.class, "throwTestException");
|
||||
@@ -310,6 +320,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
|
||||
private static void startResponder(final PollableChannel requestChannel) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Message<?> input = requestChannel.receive();
|
||||
GenericMessage<String> reply = new GenericMessage<String>(input.getPayload() + "bar");
|
||||
@@ -318,6 +329,26 @@ public class GatewayProxyFactoryBeanTests {
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProgrammaticWiring() throws Exception {
|
||||
GatewayProxyFactoryBean gpfb = new GatewayProxyFactoryBean();
|
||||
gpfb.setBeanFactory(mock(BeanFactory.class));
|
||||
gpfb.setServiceInterface(TestEchoService.class);
|
||||
QueueChannel drc = new QueueChannel();
|
||||
gpfb.setDefaultRequestChannel(drc);
|
||||
gpfb.setDefaultReplyTimeout(0);
|
||||
GatewayMethodMetadata meta = new GatewayMethodMetadata();
|
||||
meta.setHeaderExpressions(Collections. <String, Expression> singletonMap("foo", new LiteralExpression("bar")));
|
||||
gpfb.setGlobalMethodMetadata(meta);
|
||||
gpfb.afterPropertiesSet();
|
||||
((TestEchoService) gpfb.getObject()).echo("foo");
|
||||
Message<?> message = drc.receive(0);
|
||||
assertNotNull(message);
|
||||
String bar = (String) message.getHeaders().get("foo");
|
||||
assertNotNull(bar);
|
||||
assertThat(bar, equalTo("bar"));
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testHistory() throws Exception {
|
||||
// GenericApplicationContext context = new GenericApplicationContext();
|
||||
|
||||
@@ -19,9 +19,10 @@
|
||||
<channel id="channel4">
|
||||
<queue capacity="1" />
|
||||
</channel>
|
||||
|
||||
|
||||
<channel id="routingChannel" />
|
||||
<payload-type-router id="routerWithChannelResolver" input-channel="routingChannel" channel-resolver="cr">
|
||||
|
||||
<payload-type-router id="router" input-channel="routingChannel">
|
||||
<mapping type="java.lang.String" channel="channel1" />
|
||||
<mapping type="java.lang.Integer" channel="channel2" />
|
||||
<mapping type="java.lang.Number[]" channel="channel3" />
|
||||
@@ -32,5 +33,4 @@
|
||||
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,9 +16,7 @@
|
||||
|
||||
package org.springframework.integration.router.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
@@ -26,16 +24,12 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
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.messaging.Message;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -73,9 +67,6 @@ 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)
|
||||
@@ -119,10 +110,4 @@ public class PayloadTypeRouterParserTests {
|
||||
public void foo(Message<?> message);
|
||||
}
|
||||
|
||||
public static class MyChannelResolver extends BeanFactoryChannelResolver {
|
||||
|
||||
MyChannelResolver() {
|
||||
super(mock(BeanFactory.class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* 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.transformer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class MessageTransformingChannelInterceptorTests {
|
||||
|
||||
private QueueChannel channel;
|
||||
|
||||
private GenericMessage<String> message;
|
||||
|
||||
private TestTransformer transformer;
|
||||
|
||||
private MessageTransformingChannelInterceptor channelInterceptor;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
channel = new QueueChannel();
|
||||
message = new GenericMessage<String>("test");
|
||||
transformer = new TestTransformer();
|
||||
channelInterceptor = new MessageTransformingChannelInterceptor(transformer);
|
||||
channel.addInterceptor(channelInterceptor);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTransformOnReceive() {
|
||||
channelInterceptor.setTransformOnSend(false);
|
||||
channel.send(message);
|
||||
assertFalse("Transformer incorrectly invoked on send", transformer.invoked);
|
||||
Message<?> msg = channel.receive(1);
|
||||
assertEquals("Wrong message", message, msg);
|
||||
assertTrue("Transformer not invoked on receive", transformer.invoked);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransformOnSend() {
|
||||
channelInterceptor.setTransformOnSend(true);
|
||||
channel.send(message);
|
||||
assertTrue("Transformer not invoked on send", transformer.invoked);
|
||||
Message<?> msg = channel.receive(1);
|
||||
assertEquals("Wrong message", message, msg);
|
||||
assertEquals("Transformer invoked on receive", 1, transformer.invokedCount);
|
||||
}
|
||||
|
||||
|
||||
private static class TestTransformer implements Transformer {
|
||||
|
||||
boolean invoked = false;
|
||||
|
||||
int invokedCount = 0;
|
||||
|
||||
public Message<?> transform(Message<?> message) {
|
||||
invoked = true;
|
||||
invokedCount++;
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user