From a6c85c1dd91cc62632aa4d3ec9227a2d36a2a3f3 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 2 Sep 2011 08:26:13 -0400 Subject: [PATCH] INT-1677 finished the namespace support for payload-expression attribute and header sub-element, added parser test --- .../config/HttpInboundEndpointParser.java | 35 +++++++++++++++++++ .../config/spring-integration-http-2.1.xsd | 14 ++++++++ ...boundChannelAdapterParserTests-context.xml | 8 +++++ .../HttpInboundChannelAdapterParserTests.java | 24 +++++++++++++ 4 files changed, 81 insertions(+) diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java index f99f8f5f80..762d62284e 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java @@ -16,13 +16,22 @@ package org.springframework.integration.http.config; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.ManagedMap; +import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.ExpressionFactoryBean; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; @@ -76,6 +85,32 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse } builder.addPropertyReference("requestChannel", inputChannelRef); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel"); + + + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "path"); + String payloadExpression = element.getAttribute("payload-expression"); + if (StringUtils.hasText(payloadExpression)){ + RootBeanDefinition expressionDef = new RootBeanDefinition(ExpressionFactoryBean.class); + expressionDef.getConstructorArgumentValues().addGenericArgumentValue(payloadExpression); + builder.addPropertyValue("payloadExpression", expressionDef); + } + + List headerElements = DomUtils.getChildElementsByTagName(element, "header"); + if (!CollectionUtils.isEmpty(headerElements)) { + + ManagedMap headerElementsMap = new ManagedMap(); + for (Element headerElement : headerElements) { + String name = headerElement.getAttribute("name"); + String expression = headerElement.getAttribute("expression"); + if (StringUtils.hasText(expression)){ + RootBeanDefinition expressionDef = new RootBeanDefinition(ExpressionFactoryBean.class); + expressionDef.getConstructorArgumentValues().addGenericArgumentValue(expression); + headerElementsMap.put(name, expressionDef); + } + } + builder.addPropertyValue("headerExpressions", headerElementsMap); + } + if (this.expectReply) { IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout"); diff --git a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.1.xsd b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.1.xsd index 5b3c1615df..d07ee90c78 100644 --- a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.1.xsd +++ b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.1.xsd @@ -67,6 +67,13 @@ + + + + Allows you to specify URI path (e.g., /orderId/{order}) + + + @@ -155,6 +162,13 @@ The String "HTTP_REQUEST_HEADERS" will match against any of the standard HTTP Re + + + + Allows you to specify URI path (e.g., /orderId/{order}) + + + diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml index 4dc44dabb2..d83435343d 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml @@ -26,5 +26,13 @@ + + +
+ diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java index 18a0252235..6a8aa31e59 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java @@ -72,6 +72,9 @@ public class HttpInboundChannelAdapterParserTests { @Autowired private HttpRequestHandlingMessagingGateway withMappedHeaders; + + @Autowired + private HttpRequestHandlingMessagingGateway inboundAdapterWithExpressions; @Autowired private HttpRequestHandlingController inboundController; @@ -113,6 +116,27 @@ public class HttpInboundChannelAdapterParserTests { assertEquals("foo", map.get("foo")); assertEquals("bar", map.get("bar")); } + + @Test + @SuppressWarnings("unchecked")// INT-1677 + public void withExpressions() throws Exception { + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setMethod("POST"); + request.setContentType("text/plain"); + request.setParameter("foo", "bar"); + request.setContent("hello".getBytes()); + request.setRequestURI("/fname/bill/lname/clinton"); + + MockHttpServletResponse response = new MockHttpServletResponse(); + inboundAdapterWithExpressions.handleRequest(request, response); + assertEquals(HttpServletResponse.SC_OK, response.getStatus()); + Message message = requests.receive(0); + assertNotNull(message); + Object payload = message.getPayload(); + assertTrue(payload instanceof String); + assertEquals("bill", payload); + assertEquals("clinton", message.getHeaders().get("lname")); + } @Test public void getRequestNotAllowed() throws Exception {