From 66a8927000a079d608ee0b07a30d69a26a1e0315 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 1 Feb 2011 17:22:54 -0500 Subject: [PATCH] INT-1391 added 'requires-reply' attribute to element --- .../config/xml/ServiceActivatorParser.java | 6 +- .../config/xml/spring-integration-1.0.xsd | 17 +++- .../GatewayRequiresReplyTests-context.xml | 37 +++++++++ .../gateway/GatewayRequiresReplyTests.java | 83 +++++++++++++++++++ 4 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests-context.xml create mode 100644 org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests.java diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ServiceActivatorParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ServiceActivatorParser.java index 2b11b99953..6ff6bc0c4b 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ServiceActivatorParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ServiceActivatorParser.java @@ -34,12 +34,12 @@ public class ServiceActivatorParser extends AbstractConsumerEndpointParser { @Override protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) { BeanDefinition innerHandlerDefinition = this.parseInnerHandlerDefinition(element, parserContext); - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( IntegrationNamespaceUtils.BASE_PACKAGE + ".handler.ServiceActivatingHandler"); if (innerHandlerDefinition != null){ builder.addConstructorArgValue(innerHandlerDefinition); - } else { + } + else { String ref = element.getAttribute(REF_ATTRIBUTE); if (!StringUtils.hasText(ref)) { parserContext.getReaderContext().error("The '" + REF_ATTRIBUTE + "' attribute is required for element " @@ -47,11 +47,11 @@ public class ServiceActivatorParser extends AbstractConsumerEndpointParser { } builder.addConstructorArgReference(ref); } - if (StringUtils.hasText(element.getAttribute(METHOD_ATTRIBUTE))) { String method = element.getAttribute(METHOD_ATTRIBUTE); builder.getRawBeanDefinition().getConstructorArgumentValues().addGenericArgumentValue(method, "java.lang.String"); } + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "requires-reply"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout"); return builder; } diff --git a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd index 1dc8166644..0d7ac73456 100644 --- a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd +++ b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd @@ -443,7 +443,7 @@ default="true" /> - + Defines an endpoint for exposing any bean @@ -459,6 +459,21 @@ should be provided along with 'ref'. + + + + + + + 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/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests-context.xml new file mode 100644 index 0000000000..074dd0b291 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests-context.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests.java new file mode 100644 index 0000000000..c51010a486 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayRequiresReplyTests.java @@ -0,0 +1,83 @@ +/* + * 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.gateway; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.integration.message.MessageHandlingException; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Mark Fisher + * @since 1.0.5 + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class GatewayRequiresReplyTests { + + @Autowired + private ApplicationContext applicationContext; + + + @Test + public void replyReceived() { + TestService gateway = (TestService) applicationContext.getBean("gateway"); + String result = gateway.test("foo"); + assertEquals("bar", result); + } + + @Test(expected = MessageHandlingException.class) + public void noReplyReceived() { + TestService gateway = (TestService) applicationContext.getBean("gateway"); + gateway.test("bad"); + } + + @Test + public void timedOutGateway() { + TestService gateway = (TestService) applicationContext.getBean("timeoutGateway"); + String result = gateway.test("hello"); + assertNull(result); + } + + + public static interface TestService { + public String test(String s); + } + + + public static class TestServiceBean { + public String process(String s) { + return "foo".equals(s) ? "bar" : null; + } + } + + + public static class LongRunningService { + public String echo(String value) throws Exception{ + Thread.sleep(5000); + return value; + } + } + +}