From 47ee0c737bce4437e1074fec2d714270b00e98a4 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sat, 28 Aug 2010 16:04:13 +0000 Subject: [PATCH] INT-1384 removed the recently added (yesterday) "requiresReply" Message header, but added the "requires-reply" attribute on the element --- .../integration/MessageHeaders.java | 7 ------ .../config/ServiceActivatorFactoryBean.java | 11 +++++++- ...tractDelegatingConsumerEndpointParser.java | 1 + .../integration/core/MessageBuilder.java | 4 --- .../GatewayMethodInboundMessageMapper.java | 3 --- .../AbstractReplyProducingMessageHandler.java | 25 ++++++++----------- .../config/xml/spring-integration-2.0.xsd | 9 +++++++ .../GatewayRequiresReplyTests-context.xml | 4 ++- 8 files changed, 33 insertions(+), 31 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/MessageHeaders.java b/spring-integration-core/src/main/java/org/springframework/integration/MessageHeaders.java index 293194872e..7089a92e0a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/MessageHeaders.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/MessageHeaders.java @@ -58,8 +58,6 @@ public final class MessageHeaders implements Map, Serializable { public static final String CORRELATION_ID = PREFIX + "correlationId"; - public static final String REQUIRES_REPLY = PREFIX + "requiresReply"; - public static final String REPLY_CHANNEL = PREFIX + "replyChannel"; public static final String ERROR_CHANNEL = PREFIX + "errorChannel"; @@ -100,11 +98,6 @@ public final class MessageHeaders implements Map, Serializable { return this.get(REPLY_CHANNEL); } - public boolean getRequiresReply() { - Boolean headerValue = this.get(REQUIRES_REPLY, Boolean.class); - return (headerValue != null && headerValue); - } - public Object getErrorChannel() { return this.get(ERROR_CHANNEL); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/ServiceActivatorFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/ServiceActivatorFactoryBean.java index 99dacf3160..d334b64c12 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/ServiceActivatorFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/ServiceActivatorFactoryBean.java @@ -32,10 +32,16 @@ public class ServiceActivatorFactoryBean extends AbstractMessageHandlerFactoryBe private volatile Long sendTimeout; + private volatile Boolean requiresReply; + public void setSendTimeout(Long sendTimeout) { this.sendTimeout = sendTimeout; } + public void setRequiresReply(Boolean requiresReply) { + this.requiresReply = requiresReply; + } + @Override MessageHandler createMethodInvokingHandler(Object targetObject, String targetMethodName) { ServiceActivatingHandler handler = (StringUtils.hasText(targetMethodName)) @@ -58,7 +64,10 @@ public class ServiceActivatorFactoryBean extends AbstractMessageHandlerFactoryBe private ServiceActivatingHandler configureHandler(ServiceActivatingHandler handler) { if (this.sendTimeout != null) { - handler.setSendTimeout(sendTimeout); + handler.setSendTimeout(this.sendTimeout); + } + if (this.requiresReply != null) { + handler.setRequiresReply(this.requiresReply); } return handler; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractDelegatingConsumerEndpointParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractDelegatingConsumerEndpointParser.java index a98bebef1a..6a5d79ef62 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractDelegatingConsumerEndpointParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractDelegatingConsumerEndpointParser.java @@ -83,6 +83,7 @@ abstract class AbstractDelegatingConsumerEndpointParser extends AbstractConsumer "a 'ref' or inner-bean definition is provided.", element); } } + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "requires-reply"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout"); this.postProcess(builder, element, parserContext); return builder; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/core/MessageBuilder.java b/spring-integration-core/src/main/java/org/springframework/integration/core/MessageBuilder.java index ebfe4aeae6..ce16d38c82 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/core/MessageBuilder.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/core/MessageBuilder.java @@ -167,10 +167,6 @@ public final class MessageBuilder { return this.setHeader(MessageHeaders.CORRELATION_ID, correlationId); } - public MessageBuilder setRequiresReply(Boolean requiresReply) { - return this.setHeader(MessageHeaders.REQUIRES_REPLY, requiresReply); - } - public MessageBuilder setReplyChannel(MessageChannel replyChannel) { return this.setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java index cd34413c09..711aae5670 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayMethodInboundMessageMapper.java @@ -202,9 +202,6 @@ class GatewayMethodInboundMessageMapper implements InboundMessageMapper message) { Object result = this.handleRequestMessage(message); - if (result == null) { - if (this.requiresReply) { - throw new MessageHandlingException(message, "handler '" + this - + "' requires a reply, but no reply was received"); - } - if (message != null && message.getHeaders().getRequiresReply()) { - throw new MessageHandlingException(message, - "A reply Message is required by this request Message, but none was received."); - } - if (logger.isDebugEnabled()) { - logger.debug("handler '" + this + "' produced no reply for request Message: " + message); - } - return; + if (result != null) { + MessageHeaders requestHeaders = message.getHeaders(); + this.handleResult(result, requestHeaders); + } + else if (this.requiresReply) { + throw new MessageHandlingException(message, "handler '" + this + + "' requires a reply, but no reply was received"); + } + else if (logger.isDebugEnabled()) { + logger.debug("handler '" + this + "' produced no reply for request Message: " + message); } - MessageHeaders requestHeaders = message.getHeaders(); - this.handleResult(result, requestHeaders); } protected void handleResult(Object result, MessageHeaders requestHeaders) { diff --git a/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd b/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd index 1c02036848..b7d171a76b 100644 --- a/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd +++ b/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd @@ -798,6 +798,15 @@ + + + + Specify whether the service method must return a non-null value. This value will be + FALSE by default, but if set to TRUE, a MessageHandlingException will be thrown when + the underlying service method (or expression) returns a NULL value. + + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests-context.xml index db31f1aa73..3ee9230dde 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests-context.xml @@ -12,6 +12,8 @@ default-reply-timeout="3000" service-interface="org.springframework.integration.gateway.GatewayRequiresReplyTests$TestService" /> - +