INT-3884: Outbound Gateway replyChannel in Chain

JIRA: https://jira.spring.io/browse/INT-3884

Previously, an outbound gateway within a chain allowed a `reply-channel` attribute
but it was ignored. The gateway's output channel is set to send the message to
the next element in the chain, or the chain's output channel if the gateway is
the last element.

Tighten the parser logic to detect and disallow a reply channel within a chain.

Polishing
This commit is contained in:
Gary Russell
2015-11-17 15:37:31 -05:00
committed by Artem Bilan
parent 051b393ed0
commit 33a40f6cae
6 changed files with 93 additions and 20 deletions

View File

@@ -16,10 +16,13 @@
package org.springframework.integration.jms.config;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
@@ -249,6 +252,12 @@ public class JmsOutboundGatewayParserTests {
String result = gateway.echo("hello");
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
assertEquals("hello", result);
JmsOutboundGateway gw1 = context.getBean("chain1$child.gateway.handler", JmsOutboundGateway.class);
MessageChannel out = TestUtils.getPropertyValue(gw1, "outputChannel", MessageChannel.class);
assertThat(out.getClass().getSimpleName(), equalTo("ReplyForwardingMessageChannel"));
JmsOutboundGateway gw2 = context.getBean("chain2$child.gateway.handler", JmsOutboundGateway.class);
out = TestUtils.getPropertyValue(gw2, "outputChannel", MessageChannel.class);
assertThat(out.getClass().getName(), containsString("MessageHandlerChain$"));
context.close();
}

View File

@@ -6,7 +6,7 @@
http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-jms="http://www.springframework.org/schema/integration/jms">
<int:message-history/>
<int:gateway id="gateway"
@@ -19,17 +19,47 @@
<int:header name="foo" value="bar"/>
</int:method>
</int:gateway>
<int:chain input-channel="requests">
<int-jms:outbound-gateway request-destination="requestQueueA"
reply-destination="replyQueueB"
<int-jms:outbound-gateway request-destination="requestQueueA"
reply-destination="replyQueueB"
connection-factory="connectionFactory"
receive-timeout="100000"
reply-timeout="200000"/>
</int:chain>
<int:chain id="chain1" input-channel="chainWithGatewayAtEnd">
<int-jms:outbound-gateway id="gateway"
request-destination="requestQueueA"
reply-destination="replyQueueB"
connection-factory="connectionFactory"
receive-timeout="100000"
reply-timeout="200000"/>
</int:chain>
<int:chain id="chain2" input-channel="chainWithGatewayInMiddle">
<int-jms:outbound-gateway id="gateway"
request-destination="requestQueueA"
reply-destination="replyQueueB"
connection-factory="connectionFactory"
receive-timeout="100000"
reply-timeout="200000"/>
<int:transformer expression="payload"/>
</int:chain>
<!-- INT-3884
<int:chain id="invalidChain" input-channel="chainWithInvalidGatewayReplyChannel">
<int-jms:outbound-gateway id="badChainGateway"
request-destination="requestQueueA"
reply-destination="replyQueueB"
connection-factory="connectionFactory"
receive-timeout="100000"
reply-channel="badOutputChannel"
reply-timeout="200000"/>
</int:chain>
<int:channel id="badOutputChannel"/>
-->
<bean id="requestQueueA" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="request.queueA"/>
</bean>
@@ -37,7 +67,7 @@
<bean id="replyQueueB" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="reply.queueB"/>
</bean>
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
@@ -48,11 +78,11 @@
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<int-jms:inbound-gateway id="inboundGateway" request-channel="jmsInput" request-destination="requestQueueA"/>
<int:channel id="jmsInput"/>
<!-- <int:service-activator input-channel="jmsInput">-->
<!-- <bean class="org.springframework.integration.jms.config.JmsOutboundGatewayParserTests$SampleService"/>-->
<!-- </int:service-activator>-->