ReplyMessageCorrelator simply returns the same Message. The base class already resolves the replyChannel from the 'returnAddress' header value.

This commit is contained in:
Mark Fisher
2008-10-02 00:42:33 +00:00
parent 21fb3a9907
commit 64158f454e
2 changed files with 2 additions and 28 deletions

View File

@@ -16,11 +16,8 @@
package org.springframework.integration.gateway;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.endpoint.AbstractMessageHandlingEndpoint;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessageHandlingException;
import org.springframework.integration.message.MessagingException;
/**
* A handler for receiving messages from a "reply channel".
@@ -31,30 +28,7 @@ public class ReplyMessageCorrelator extends AbstractMessageHandlingEndpoint {
@Override
public Message<?> handle(Message<?> message) {
Object returnAddress = message.getHeaders().getReturnAddress();
if (returnAddress == null) {
throw new MessageHandlingException(message,
"unable to correlate response, message has no returnAddress");
}
MessageChannel replyChannel = null;
if (returnAddress instanceof MessageChannel) {
replyChannel = (MessageChannel) returnAddress;
}
else if (returnAddress instanceof String) {
replyChannel = this.getChannelRegistry().lookupChannel((String) returnAddress);
if (replyChannel == null) {
throw new MessagingException(message,
"unable to resolve returnAddress '" + returnAddress + "'");
}
}
else {
throw new MessagingException(message,
"invalid returnAddress type [" + returnAddress.getClass() + "]");
}
if (replyChannel != null) {
replyChannel.send(message);
}
return null;
return message;
}
}

View File

@@ -36,7 +36,7 @@ public class ReplyMessageCorrelatorTests {
QueueChannel replyChannel = new QueueChannel();
Message<String> message = MessageBuilder.withPayload("test")
.setCorrelationId("123").setReturnAddress(replyChannel).build();
correlator.handle(message);
correlator.onMessage(message);
Message<?> reply = replyChannel.receive(0);
assertEquals("test", reply.getPayload());
}