diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/GatewayParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/GatewayParser.java index 3fe403d1dc..c6d1d8f26b 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/GatewayParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/GatewayParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -37,6 +37,11 @@ public class GatewayParser extends AbstractSimpleBeanDefinitionParser { "default-request-channel", "default-reply-channel", "message-mapper" }; + private static String[] innerAttributes = new String[] { + "request-channel", "reply-channel", "request-timeout", "reply-timeout" + }; + + @Override protected String getBeanClassName(Element element) { return IntegrationNamespaceUtils.BASE_PACKAGE + ".gateway.GatewayProxyFactoryBean"; @@ -45,11 +50,28 @@ public class GatewayParser extends AbstractSimpleBeanDefinitionParser { @Override protected boolean isEligibleAttribute(String attributeName) { return !ObjectUtils.containsElement(referenceAttributes, attributeName) + && !ObjectUtils.containsElement(innerAttributes, attributeName) && super.isEligibleAttribute(attributeName); } @Override protected void postProcess(BeanDefinitionBuilder builder, Element element) { + if ("chain".equals(element.getParentNode().getLocalName())) { + this.postProcessInnerGateway(builder, element); + } + else { + this.postProcessGateway(builder, element); + } + } + + private void postProcessInnerGateway(BeanDefinitionBuilder builder, Element element) { + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-channel", "defaultRequestChannel"); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel", "defaultReplyChannel"); + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout", "defaultRequestTimeout"); + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout", "defaultReplyTimeout"); + } + + private void postProcessGateway(BeanDefinitionBuilder builder, Element element) { for (String attributeName : referenceAttributes) { IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, attributeName); } diff --git a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd index 4b4d6e4450..f53a11032a 100644 --- a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd +++ b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd @@ -350,6 +350,36 @@ + + + + Defines a Messaging Gateway to be used within a chain. + + + + + + + + + + + + + + + + + + + + + + + + @@ -706,7 +736,7 @@ - + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessaheHandlerTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessageHandlerTests-context.xml similarity index 87% rename from org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessaheHandlerTests-context.xml rename to org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessageHandlerTests-context.xml index bf49ea743a..188f21cac0 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessaheHandlerTests-context.xml +++ b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessageHandlerTests-context.xml @@ -8,7 +8,7 @@ + service-interface="org.springframework.integration.gateway.GatewayInvokingMessageHandlerTests$SimpleGateway"/> @@ -19,9 +19,9 @@ - + - + @@ -31,7 +31,7 @@ - + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessaheHandlerTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessageHandlerTests.java similarity index 73% rename from org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessaheHandlerTests.java rename to org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessageHandlerTests.java index d86c274f87..503b2f7fc5 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessaheHandlerTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/gateway/GatewayInvokingMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -13,32 +13,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.gateway; import junit.framework.Assert; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.channel.SubscribableChannel; import org.springframework.integration.core.Message; -import org.springframework.integration.message.MessageDeliveryException; import org.springframework.integration.message.MessageHandler; -import org.springframework.integration.message.MessageHandlingException; -import org.springframework.integration.message.MessageRejectedException; import org.springframework.integration.message.StringMessage; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * TODO - insert COMMENT * @author Oleg Zhurakousky * @since 2.0 */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) -public class GatewayInvokingMessaheHandlerTests { +public class GatewayInvokingMessageHandlerTests { + @Autowired @Qualifier("inputA") SubscribableChannel channel; @@ -52,11 +51,9 @@ public class GatewayInvokingMessaheHandlerTests { SubscribableChannel output; @Test - public void validateGatewayInTheChainViaChannel(){ + public void validateGatewayInTheChainViaChannel() { output.subscribe(new MessageHandler() { - public void handleMessage(Message message) - throws MessageRejectedException, MessageHandlingException, - MessageDeliveryException { + public void handleMessage(Message message) { Assert.assertEquals("echo:echo:hello", message.getPayload()); Assert.assertEquals("foo", message.getHeaders().get("foo")); Assert.assertEquals("oleg", message.getHeaders().get("name")); @@ -64,12 +61,11 @@ public class GatewayInvokingMessaheHandlerTests { }); channel.send(new StringMessage("hello")); } + @Test - public void validateGatewayInTheChainViaAnotherGateway(){ + public void validateGatewayInTheChainViaAnotherGateway() { output.subscribe(new MessageHandler() { - public void handleMessage(Message message) - throws MessageRejectedException, MessageHandlingException, - MessageDeliveryException { + public void handleMessage(Message message) { Assert.assertEquals("echo:echo:hello", message.getPayload()); Assert.assertEquals("foo", message.getHeaders().get("foo")); Assert.assertEquals("oleg", message.getHeaders().get("name")); @@ -78,14 +74,15 @@ public class GatewayInvokingMessaheHandlerTests { String result = gateway.sendRecieve("hello"); Assert.assertEquals("echo:echo:hello", result); } - - public static interface SimpleGateway{ + + public static interface SimpleGateway { public String sendRecieve(String str); } - + public static class SimpleService { - public String echo(String str){ + public String echo(String str) { return "echo:" + str; } } + }