INT-1223, INT-1226. The fix is temporary as we are considering refactoring of ARPMH and supporting classes (see INT-1227), however test cases are now in place to aid in refactoring efforts

This commit is contained in:
Oleg Zhurakousky
2010-07-03 12:56:42 +00:00
parent 5d154e11d7
commit 682e8166eb
9 changed files with 256 additions and 28 deletions

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.filter;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.core.MessageHeaders;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.message.MessageDeliveryException;
import org.springframework.integration.message.MessageRejectedException;
@@ -35,6 +36,7 @@ import org.springframework.util.Assert;
* provided, the rejected Messages will be sent to that channel.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
*/
public class MessageFilter extends AbstractReplyProducingMessageHandler {
@@ -115,4 +117,11 @@ public class MessageFilter extends AbstractReplyProducingMessageHandler {
return null;
}
protected void handleResult(Object replyMessage, MessageHeaders requestHeaders, MessageChannel replyChannel) {
if (!this.sendReplyMessage((Message<?>) replyMessage, replyChannel)) {
throw new MessageDeliveryException((Message<?>) replyMessage,
"failed to send reply Message to channel '" + replyChannel + "'. Consider increasing the " +
"send timeout of this endpoint.");
}
}
}

View File

@@ -32,6 +32,7 @@ import org.springframework.util.Assert;
*
* @author Mark Fisher
* @author Iwein Fuld
* @author Oleg Zhurakousky
*/
public abstract class AbstractReplyProducingMessageHandler extends AbstractMessageHandler
implements MessageProducer {
@@ -116,7 +117,7 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa
@SuppressWarnings("unchecked")
private Message<?> createReplyMessage(Object reply, MessageHeaders requestHeaders) {
if (reply instanceof Message) {
return (Message<?>) reply;
return MessageBuilder.fromMessage((Message<?>) reply).copyHeadersIfAbsent(requestHeaders).build();
}
MessageBuilder<?> builder = (reply instanceof MessageBuilder)
? (MessageBuilder<?>) reply : MessageBuilder.withPayload(reply);

View File

@@ -17,9 +17,11 @@
package org.springframework.integration.transformer;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.core.MessageHeaders;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.message.MessageDeliveryException;
import org.springframework.integration.message.MessageHandler;
import org.springframework.util.Assert;
@@ -29,6 +31,7 @@ import org.springframework.util.Assert;
* and sends the result to its output channel.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
*/
public class MessageTransformingHandler extends AbstractReplyProducingMessageHandler {
@@ -69,5 +72,12 @@ public class MessageTransformingHandler extends AbstractReplyProducingMessageHan
throw new MessageTransformationException(message, e);
}
}
protected void handleResult(Object replyMessage, MessageHeaders requestHeaders, MessageChannel replyChannel) {
if (!this.sendReplyMessage((Message<?>) replyMessage, replyChannel)) {
throw new MessageDeliveryException((Message<?>) replyMessage,
"failed to send reply Message to channel '" + replyChannel + "'. Consider increasing the " +
"send timeout of this endpoint.");
}
}
}

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"
xmlns:int="http://www.springframework.org/schema/integration">
<int:gateway id="gatewayA"
service-interface="org.springframework.integration.gateway.MultipleEndpointGatewayTests$SampleGateway"
default-request-channel="routingChannel"/>
<int:gateway id="gatewayB"
service-interface="org.springframework.integration.gateway.MultipleEndpointGatewayTests$SampleGateway"
default-request-channel="routingChannel"
default-reply-channel="outputChannel"/>
<int:publish-subscribe-channel id="outputChannel"/>
<int:router input-channel="routingChannel" expression="payload"/>
<!-- gatewayNoDefaultReplyChannel -->
<int:service-activator input-channel="echoAsMessageChannel" output-channel="echoAsMessageChannelA" ref="service" method="echoAsMessage"/>
<int:service-activator input-channel="echoAsMessageChannelA" ref="service" method="echoAsMessage"/>
<!-- gatewayWithDefaultReplyChannel -->
<int:service-activator input-channel="echoAsMessageChannelIgnoreDefOutChannel" output-channel="echoAsMessageChannelIgnoreDefOutChannelB" ref="service" method="echoAsMessage"/>
<int:service-activator input-channel="echoAsMessageChannelIgnoreDefOutChannelB" ref="service" method="echoAsMessage"/>
<!-- gatewayWithReplySentBackToDefaultReplyChannel -->
<int:service-activator input-channel="echoAsMessageChannelDefaultOutputChannel" output-channel="echoAsMessageChannelDefaultOutputChannelB" ref="service" method="echoAsMessage"/>
<int:service-activator input-channel="echoAsMessageChannelDefaultOutputChannelB" output-channel="outputChannel" ref="service" method="echoAsMessage"/>
<bean id="service" class="org.springframework.integration.gateway.MultipleEndpointGatewayTests$SampleEchoService"/>
</beans>

View File

@@ -0,0 +1,72 @@
/*
* 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.gateway;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class MultipleEndpointGatewayTests {
@Autowired
@Qualifier("gatewayA")
private SampleGateway gatewayA;
@Autowired
@Qualifier("gatewayB")
private SampleGateway gatewayB;
@Test
public void gatewayNoDefaultReplyChannel(){
gatewayA.echo("echoAsMessageChannel");
// there is nothing to assert. Successful execution of the above is all we care in this test
}
@Test
public void gatewayWithDefaultReplyChannel(){
gatewayB.echo("echoAsMessageChannelIgnoreDefOutChannel");
// there is nothing to assert. Successful execution of the above is all we care in this test
}
@Test
public void gatewayWithReplySentBackToDefaultReplyChannel(){
gatewayB.echo("echoAsMessageChannelDefaultOutputChannel");
// there is nothing to assert. Successful execution of the above is all we care in this test
}
public static interface SampleGateway{
public Object echo(Object value);
}
public static class SampleEchoService {
public Object echo(Object value){
return "R:" + value;
}
public Message echoAsMessage(Object value){
return MessageBuilder.withPayload("R:" + value).build();
}
}
}