diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java index 5d2f54356f..75307c73cd 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -19,7 +19,6 @@ package org.springframework.integration.handler; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; import org.springframework.integration.MessageDeliveryException; -import org.springframework.integration.MessageHandlingException; import org.springframework.integration.MessageHeaders; import org.springframework.integration.core.MessageProducer; import org.springframework.integration.core.MessagingTemplate; @@ -69,8 +68,8 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa } /** - * Flag wether reply is required. If true an incoming message MUST result in a reply message being sent. - * If false an incoming message MAY result in a reply message being sent + * Flag whether a reply is required. If true an incoming message MUST result in a reply message being sent. + * If false an incoming message MAY result in a reply message being sent. Default is false. */ public void setRequiresReply(boolean requiresReply) { this.requiresReply = requiresReply; @@ -101,8 +100,8 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa this.handleResult(result, requestHeaders); } else if (this.requiresReply) { - throw new MessageHandlingException(message, "handler '" + this - + "' requires a reply, but no reply was received"); + throw new ReplyRequiredException(message, "No reply produced by handler '" + + this.getComponentName() + "', and its 'requiresReply' property is set to true."); } else if (logger.isDebugEnabled()) { logger.debug("handler '" + this + "' produced no reply for request Message: " + message); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/ReplyRequiredException.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/ReplyRequiredException.java new file mode 100644 index 0000000000..e3fd26a2b3 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/ReplyRequiredException.java @@ -0,0 +1,36 @@ +/* + * Copyright 2002-2011 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.handler; + +import org.springframework.integration.Message; +import org.springframework.integration.MessagingException; + +/** + * Exception that indicates no reply message is produced by a handler + * that does have a value of true for the 'requiresReply' property. + * + * @author Mark Fisher + * @since 2.1 + */ +@SuppressWarnings("serial") +public class ReplyRequiredException extends MessagingException { + + public ReplyRequiredException(Message failedMessage, String description) { + super(failedMessage, description); + } + +} diff --git a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ServiceActivatorEndpointTests.java b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ServiceActivatorEndpointTests.java index d31298e5f3..af939da109 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ServiceActivatorEndpointTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/ServiceActivatorEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -24,10 +24,10 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import org.springframework.integration.Message; -import org.springframework.integration.MessageHandlingException; import org.springframework.integration.MessagingException; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.channel.TestChannelResolver; +import org.springframework.integration.handler.ReplyRequiredException; import org.springframework.integration.handler.ServiceActivatingHandler; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.support.MessageBuilder; @@ -154,7 +154,7 @@ public class ServiceActivatorEndpointTests { assertNull(channel.receive(0)); } - @Test(expected = MessageHandlingException.class) + @Test(expected = ReplyRequiredException.class) public void noReplyMessageWithRequiresReply() { QueueChannel channel = new QueueChannel(1); ServiceActivatingHandler endpoint = new ServiceActivatingHandler( diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests.java b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests.java index c392c495b4..d93fa375c7 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -24,7 +24,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; -import org.springframework.integration.MessageHandlingException; +import org.springframework.integration.handler.ReplyRequiredException; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -47,7 +47,7 @@ public class GatewayRequiresReplyTests { assertEquals("bar", result); } - @Test(expected = MessageHandlingException.class) + @Test(expected = ReplyRequiredException.class) public void noReplyReceived() { TestService gateway = (TestService) applicationContext.getBean("gateway"); gateway.test("bad"); @@ -65,7 +65,7 @@ public class GatewayRequiresReplyTests { public String test(String s); } - public static class LongRunningService{ + public static class LongRunningService { public String echo(String value) throws Exception{ Thread.sleep(5000); return value; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/router/config/SplitterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/router/config/SplitterParserTests.java index 1bddf63cc8..e139dfd65a 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/router/config/SplitterParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/router/config/SplitterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -17,12 +17,13 @@ package org.springframework.integration.router.config; import org.junit.Test; + import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; -import org.springframework.integration.MessageHandlingException; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.core.PollableChannel; +import org.springframework.integration.handler.ReplyRequiredException; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.support.MessageBuilder; @@ -94,7 +95,7 @@ public class SplitterParserTests { assertNull(output.receive(0)); } - @Test(expected=MessageHandlingException.class) + @Test(expected = ReplyRequiredException.class) public void splitterParserTestWithRequiresReply() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "splitterParserTests.xml", this.getClass());