INT-1227 removed the protected getOutputChannel() method from AbstractReplyProducingMessageHandler. BridgeHandler no longer asserts an output channel in order to throw an Exception. Instead, a ChannelResolutionException is thrown in the normal place for a missing outputChannel property or replyChannel header in the AbstractReplyProducingMessageHandler.

This commit is contained in:
Mark Fisher
2010-08-30 21:29:16 +00:00
parent c44355c5c9
commit 8967d7eb51
3 changed files with 8 additions and 23 deletions

View File

@@ -57,10 +57,6 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa
this.outputChannel = outputChannel;
}
protected MessageChannel getOutputChannel() {
return this.outputChannel;
}
/**
* Set the timeout for sending reply Messages.
*/
@@ -122,7 +118,6 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa
this.sendReplyMessage(replyMessage, requestHeaders.getReplyChannel());
}
@SuppressWarnings("unchecked")
private Message<?> createReplyMessage(Object reply, MessageHeaders requestHeaders) {
if (reply instanceof Message) {
return MessageBuilder.fromMessage((Message<?>) reply).copyHeadersIfAbsent(requestHeaders).build();
@@ -144,9 +139,8 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa
if (logger.isDebugEnabled()) {
logger.debug("handler '" + this + "' sending reply Message: " + replyMessage);
}
MessageChannel outputChannel = this.getOutputChannel();
if (outputChannel != null) {
this.sendMessage(replyMessage, outputChannel);
if (this.outputChannel != null) {
this.sendMessage(replyMessage, this.outputChannel);
}
else if (replyChannelHeaderValue != null) {
this.sendMessage(replyMessage, replyChannelHeaderValue);

View File

@@ -17,7 +17,6 @@
package org.springframework.integration.handler;
import org.springframework.integration.Message;
import org.springframework.util.Assert;
/**
* A simple MessageHandler implementation that passes the request Message
@@ -28,7 +27,7 @@ import org.springframework.util.Assert;
* The BridgeHandler can be used as a stopper at the end of an assembly line of
* channels. In this setup the output channel doesn't have to be set, but if the
* output channel is omitted the <tt>REPLY_CHANNEL</tt> MUST be set on the
* message.
* message. Otherwise, a MessagingException will be thrown at runtime.
*
* @author Mark Fisher
* @author Iwein Fuld
@@ -42,14 +41,7 @@ public class BridgeHandler extends AbstractReplyProducingMessageHandler {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
if (requestMessage.getHeaders().getReplyChannel() == null) {
this.verifyOutputChannel();
}
return requestMessage;
}
private void verifyOutputChannel() {
Assert.state(super.getOutputChannel() != null, "Bridge handler requires an output channel");
}
}

View File

@@ -24,8 +24,8 @@ import org.hamcrest.Matcher;
import org.junit.Test;
import org.springframework.integration.Message;
import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.core.ChannelResolutionException;
import org.springframework.integration.core.GenericMessage;
import org.springframework.integration.core.MessageBuilder;
import org.springframework.integration.core.PollableChannel;
@@ -55,18 +55,17 @@ public class BridgeHandlerTests {
assertThat(reply, sameExceptImmutableHeaders(request));
}
@Test(expected = MessageHandlingException.class)
@Test(expected = ChannelResolutionException.class)
public void missingOutputChannelVerifiedAtRuntime() {
Message<?> request = new GenericMessage<String>("test");
handler.handleMessage(request);
}
@SuppressWarnings("unchecked")
@Test(timeout=1000)
public void missingOutputChannelAllowedForReplyChannelMessages() throws Exception {
PollableChannel replyChannel = new QueueChannel();
Message request = MessageBuilder.withPayload("tst").setReplyChannel(replyChannel ).build();
handler.handleMessage(request );
Message<String> request = MessageBuilder.withPayload("tst").setReplyChannel(replyChannel ).build();
handler.handleMessage(request);
assertThat(replyChannel.receive(), sameExceptImmutableHeaders(request));
}