From 2955ef989e091af55b3f18c3b24ebf9b0e0ab49f Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 16 Aug 2010 20:43:30 +0000 Subject: [PATCH] INT-1349 Added support for sub-elements within the HTTP outbound adapters. Map payloads no longer provide values for the URI template placeholder replacements. --- .../http/DefaultParameterExtractor.java | 76 ------------------- .../HttpRequestExecutingMessageHandler.java | 56 +++++++++++--- .../integration/http/ParameterExtractor.java | 36 --------- .../HttpOutboundChannelAdapterParser.java | 17 ++++- .../config/HttpOutboundGatewayParser.java | 17 ++++- .../config/spring-integration-http-2.0.xsd | 49 +++++++----- .../http/DefaultParameterExtractorTests.java | 50 ------------ .../http/UriVariableExpressionTests.java | 64 ++++++++++++++++ ...boundChannelAdapterParserTests-context.xml | 25 +++--- ...HttpOutboundChannelAdapterParserTests.java | 15 ++-- ...HttpOutboundGatewayParserTests-context.xml | 29 ++++--- .../HttpOutboundGatewayParserTests.java | 12 ++- 12 files changed, 217 insertions(+), 229 deletions(-) delete mode 100644 spring-integration-http/src/main/java/org/springframework/integration/http/DefaultParameterExtractor.java delete mode 100644 spring-integration-http/src/main/java/org/springframework/integration/http/ParameterExtractor.java delete mode 100644 spring-integration-http/src/test/java/org/springframework/integration/http/DefaultParameterExtractorTests.java create mode 100644 spring-integration-http/src/test/java/org/springframework/integration/http/UriVariableExpressionTests.java diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/DefaultParameterExtractor.java b/spring-integration-http/src/main/java/org/springframework/integration/http/DefaultParameterExtractor.java deleted file mode 100644 index 77c9bebb56..0000000000 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/DefaultParameterExtractor.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2002-2008 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.http; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.expression.Expression; -import org.springframework.expression.spel.standard.SpelExpressionParser; -import org.springframework.integration.Message; - -/** - * @author Dave Syer - * @since 2.0 - * - */ -public class DefaultParameterExtractor implements ParameterExtractor { - - private static Log logger = LogFactory.getLog(DefaultParameterExtractor.class); - - private SpelExpressionParser parser = new SpelExpressionParser(); - - private Map dynamicParameterExpressions = new HashMap(); - - /** - * A map of parameter name to SpEL expressions on the message. - * - * @param dynamicParameterExpressions the dynamic parameter expressions to set - */ - public void setDynamicParameterExpressions(Map dynamicParameterExpressions) { - this.dynamicParameterExpressions.clear(); - for (String key : dynamicParameterExpressions.keySet()) { - this.dynamicParameterExpressions.put(key, parser.parseExpression(dynamicParameterExpressions.get(key))); - } - } - - public Map fromMessage(Message requestMessage) { - - Map params = new HashMap(); - for (String key : dynamicParameterExpressions.keySet()) { - Object value = dynamicParameterExpressions.get(key).getValue(requestMessage); - params.put(key, value); - } - - if (requestMessage.getPayload() instanceof Map) { - Map payloadMap = (Map) requestMessage.getPayload(); - for (Object key : payloadMap.keySet()) { - if (key instanceof String) { - params.put((String) key, payloadMap.get(key).toString()); - } - else if (logger.isDebugEnabled()) { - logger.debug("ignoring Map value for non-String key: " + key); - } - } - } - - return params; - - } - -} diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/HttpRequestExecutingMessageHandler.java b/spring-integration-http/src/main/java/org/springframework/integration/http/HttpRequestExecutingMessageHandler.java index a5e6cd1f0c..3cdd073da3 100755 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/HttpRequestExecutingMessageHandler.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/HttpRequestExecutingMessageHandler.java @@ -17,9 +17,17 @@ package org.springframework.integration.http; import java.net.URI; +import java.util.HashMap; import java.util.List; import java.util.Map; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.core.convert.ConversionService; +import org.springframework.expression.Expression; +import org.springframework.expression.ExpressionParser; +import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.expression.spel.support.StandardEvaluationContext; +import org.springframework.expression.spel.support.StandardTypeConverter; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -29,11 +37,13 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.integration.Message; import org.springframework.integration.MessageHandlingException; import org.springframework.integration.MessagingException; +import org.springframework.integration.context.SimpleBeanResolver; import org.springframework.integration.core.MessageBuilder; import org.springframework.integration.core.MessageHandler; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.integration.mapping.HeaderMapper; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import org.springframework.web.client.ResponseErrorHandler; import org.springframework.web.client.RestTemplate; @@ -46,6 +56,9 @@ import org.springframework.web.client.RestTemplate; */ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMessageHandler { + private static final ExpressionParser PARSER = new SpelExpressionParser(); + + private final String uri; private volatile HttpMethod httpMethod = HttpMethod.POST; @@ -54,13 +67,16 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe private volatile Class expectedResponseType; + private final RestTemplate restTemplate = new RestTemplate(); + private final DefaultOutboundRequestMapper requestMapper = new DefaultOutboundRequestMapper(); private volatile HeaderMapper headerMapper = new DefaultHttpHeaderMapper(); - private final RestTemplate restTemplate = new RestTemplate(); + private final Map uriVariableExpressions = new HashMap(); + + private final StandardEvaluationContext evaluationContext = new StandardEvaluationContext(); - private ParameterExtractor parameterExtractor = new DefaultParameterExtractor(); /** * Create a handler that will send requests to the provided URI. @@ -156,19 +172,41 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe } /** - * Set the {@link ParameterExtractor} for creating URI parameters from the outbound message. - * - * @param parameterExtractor the parameter extractor to set + * Set the Map of URI variable expressions to evaluate against the outbound message + * when replacing the variable placeholders in a URI template. */ - public void setParameterExtractor(ParameterExtractor parameterExtractor) { - this.parameterExtractor = parameterExtractor; + public void setUriVariableExpressions(Map uriVariableExpressions) { + synchronized (this.uriVariableExpressions) { + this.uriVariableExpressions.clear(); + if (!CollectionUtils.isEmpty(uriVariableExpressions)) { + for (Map.Entry entry : uriVariableExpressions.entrySet()) { + this.uriVariableExpressions.put(entry.getKey(), PARSER.parseExpression(entry.getValue())); + } + } + } + } + + @Override + public void onInit() { + super.onInit(); + BeanFactory beanFactory = this.getBeanFactory(); + if (beanFactory != null) { + this.evaluationContext.setBeanResolver(new SimpleBeanResolver(beanFactory)); + } + ConversionService conversionService = this.getConversionService(); + if (conversionService != null) { + this.evaluationContext.setTypeConverter(new StandardTypeConverter(conversionService)); + } } @Override protected Object handleRequestMessage(Message requestMessage) { try { - // TODO: allow a boolean flag for treating Map as queryParams vs. uriVariables? - Map uriVariables = this.parameterExtractor.fromMessage(requestMessage); + Map uriVariables = new HashMap(); + for (Map.Entry entry : this.uriVariableExpressions.entrySet()) { + Object value = entry.getValue().getValue(this.evaluationContext, requestMessage, String.class); + uriVariables.put(entry.getKey(), value); + } HttpEntity httpRequest = this.requestMapper.fromMessage(requestMessage); ResponseEntity httpResponse = this.restTemplate.exchange(this.uri, this.httpMethod, httpRequest, this.expectedResponseType, uriVariables); if (this.expectReply) { diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/ParameterExtractor.java b/spring-integration-http/src/main/java/org/springframework/integration/http/ParameterExtractor.java deleted file mode 100644 index 337154a364..0000000000 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/ParameterExtractor.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2002-2008 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.http; - -import java.util.Map; - -import org.springframework.integration.Message; - -/** - * @author Dave Syer - * - * @since 2.0 - * - */ -public interface ParameterExtractor { - - /** - * @param requestMessage - * @return a map of parameters - */ - Map fromMessage(Message requestMessage); - -} diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParser.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParser.java index 6095b46ecb..b2d637451d 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParser.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParser.java @@ -16,6 +16,10 @@ package org.springframework.integration.http.config; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.w3c.dom.Element; import org.springframework.beans.factory.support.AbstractBeanDefinition; @@ -23,6 +27,8 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; +import org.springframework.util.CollectionUtils; +import org.springframework.util.xml.DomUtils; /** * Parser for the 'outbound-channel-adapter' element of the http namespace. @@ -43,11 +49,20 @@ public class HttpOutboundChannelAdapterParser extends AbstractOutboundChannelAda IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "http-method"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "header-mapper"); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "parameter-extractor"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "charset"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-payload"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "expected-response-type"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-factory"); + List uriVariableElements = DomUtils.getChildElementsByTagName(element, "uri-variable"); + if (!CollectionUtils.isEmpty(uriVariableElements)) { + Map uriVariableExpressions = new HashMap(); + for (Element uriVariableElement : uriVariableElements) { + String name = uriVariableElement.getAttribute("name"); + String expression = uriVariableElement.getAttribute("expression"); + uriVariableExpressions.put(name, expression); + } + builder.addPropertyValue("uriVariableExpressions", uriVariableExpressions); + } return builder.getBeanDefinition(); } diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundGatewayParser.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundGatewayParser.java index f4da5bb26f..eb6c9ad361 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundGatewayParser.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpOutboundGatewayParser.java @@ -16,12 +16,18 @@ package org.springframework.integration.http.config; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.AbstractConsumerEndpointParser; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; +import org.springframework.util.CollectionUtils; +import org.springframework.util.xml.DomUtils; /** * Parser for the 'outbound-gateway' element of the http namespace. @@ -46,13 +52,22 @@ public class HttpOutboundGatewayParser extends AbstractConsumerEndpointParser { IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "http-method"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "header-mapper"); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "parameter-extractor"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "charset"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-request-payload", "extractPayload"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "expected-response-type"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout", "sendTimeout"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-factory"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel", "outputChannel"); + List uriVariableElements = DomUtils.getChildElementsByTagName(element, "uri-variable"); + if (!CollectionUtils.isEmpty(uriVariableElements)) { + Map uriVariableExpressions = new HashMap(); + for (Element uriVariableElement : uriVariableElements) { + String name = uriVariableElement.getAttribute("name"); + String expression = uriVariableElement.getAttribute("expression"); + uriVariableExpressions.put(name, expression); + } + builder.addPropertyValue("uriVariableExpressions", uriVariableExpressions); + } return builder; } diff --git a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.0.xsd b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.0.xsd index cca35a8074..1cfeea1426 100644 --- a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.0.xsd +++ b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.0.xsd @@ -125,6 +125,9 @@ Defines an outbound HTTP-based Channel Adapter. + + + @@ -134,15 +137,6 @@ ]]> - - - - - - - - - @@ -228,6 +222,9 @@ + + + @@ -235,15 +232,6 @@ - - - - - - - - - @@ -307,6 +295,31 @@ + + + + + + + + + + + + + + + + diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/DefaultParameterExtractorTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/DefaultParameterExtractorTests.java deleted file mode 100644 index 5a8ab8d6ac..0000000000 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/DefaultParameterExtractorTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2002-2008 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.http; - -import static org.junit.Assert.assertEquals; - -import java.util.Collections; -import java.util.Map; - -import org.junit.Test; -import org.springframework.integration.core.GenericMessage; - -/** - * @author Dave Syer - * @since 2.0 - * - */ -public class DefaultParameterExtractorTests { - - @Test - public void testFromMessage() throws Exception { - DefaultParameterExtractor mapper = new DefaultParameterExtractor(); - Map params = mapper.fromMessage(new GenericMessage(Collections.singletonMap("foo", "bar"))); - assertEquals(1, params.size()); - assertEquals("bar", params.get("foo")); - } - - @Test - public void testFromMessageWithExpressions() throws Exception { - DefaultParameterExtractor mapper = new DefaultParameterExtractor(); - mapper.setDynamicParameterExpressions(Collections.singletonMap("foo", "payload")); - Map params = mapper.fromMessage(new GenericMessage("bar")); - assertEquals(1, params.size()); - assertEquals("bar", params.get("foo")); - } - -} diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/UriVariableExpressionTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/UriVariableExpressionTests.java new file mode 100644 index 0000000000..0b67fff41e --- /dev/null +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/UriVariableExpressionTests.java @@ -0,0 +1,64 @@ +/* + * Copyright 2002-2010 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.http; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.net.URI; +import java.util.Collections; +import java.util.concurrent.atomic.AtomicReference; + +import org.junit.Test; + +import org.springframework.http.HttpMethod; +import org.springframework.http.client.ClientHttpRequest; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.integration.Message; +import org.springframework.integration.core.GenericMessage; + +/** + * @author Dave Syer + * @author Mark Fisher + * @since 2.0 + */ +public class UriVariableExpressionTests { + + @Test + public void testFromMessageWithExpressions() throws Exception { + final AtomicReference uriHolder = new AtomicReference(); + HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("http://test/{foo}"); + handler.setUriVariableExpressions(Collections.singletonMap("foo", "payload")); + handler.setRequestFactory(new SimpleClientHttpRequestFactory() { + public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { + uriHolder.set(uri); + throw new RuntimeException("intentional"); + } + }); + Message message = new GenericMessage("bar"); + Exception exception = null; + try { + handler.handleMessage(message); + } + catch (Exception e) { + exception = e; + } + assertEquals("intentional", exception.getCause().getMessage()); + assertEquals("http://test/bar", uriHolder.get().toString()); + } + +} diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests-context.xml b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests-context.xml index f791860845..12dad0d28e 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests-context.xml +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests-context.xml @@ -15,22 +15,21 @@ + url="http://localhost/test2/{foo}" + http-method="GET" + channel="requests" + charset="UTF-8" + message-converters="converterList" + extract-payload="false" + expected-response-type="java.lang.Boolean" + request-factory="testRequestFactory" + order="77" + auto-startup="false"> + + - - diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests.java index 087559eba3..e1bd671dae 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests.java @@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.util.Map; + import org.junit.Test; import org.junit.runner.RunWith; @@ -27,6 +29,7 @@ import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; +import org.springframework.expression.Expression; import org.springframework.http.HttpMethod; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory; @@ -34,7 +37,6 @@ import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.http.DefaultOutboundRequestMapper; import org.springframework.integration.http.HttpRequestExecutingMessageHandler; import org.springframework.integration.http.OutboundRequestMapper; -import org.springframework.integration.http.ParameterExtractor; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -54,9 +56,6 @@ public class HttpOutboundChannelAdapterParserTests { @Autowired private ApplicationContext applicationContext; - @Autowired - private ParameterExtractor parameterExtractor; - @Test public void minimalConfig() { @@ -80,6 +79,7 @@ public class HttpOutboundChannelAdapterParserTests { } @Test + @SuppressWarnings("unchecked") public void fullConfig() { DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.fullConfigEndpoint); HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) endpointAccessor.getPropertyValue("handler"); @@ -101,11 +101,14 @@ public class HttpOutboundChannelAdapterParserTests { Object requestFactoryBean = this.applicationContext.getBean("testRequestFactory"); assertEquals(requestFactoryBean, requestFactory); DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(mapper); - assertEquals("http://localhost/test2", handlerAccessor.getPropertyValue("uri")); + assertEquals("http://localhost/test2/{foo}", handlerAccessor.getPropertyValue("uri")); assertEquals(HttpMethod.GET, handlerAccessor.getPropertyValue("httpMethod")); assertEquals("UTF-8", mapperAccessor.getPropertyValue("charset")); assertEquals(false, mapperAccessor.getPropertyValue("extractPayload")); - assertEquals(parameterExtractor, handlerAccessor.getPropertyValue("parameterExtractor")); + Map uriVariableExpressions = + (Map) handlerAccessor.getPropertyValue("uriVariableExpressions"); + assertEquals(1, uriVariableExpressions.size()); + assertEquals("headers.bar", uriVariableExpressions.get("foo").getExpressionString()); } } diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests-context.xml b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests-context.xml index df5d0e091c..1f75688db9 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests-context.xml +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests-context.xml @@ -21,24 +21,23 @@ + url="http://localhost/test2" + http-method="PUT" + request-channel="requests" + request-factory="testRequestFactory" + request-timeout="1234" + message-converters="converterList" + extract-request-payload="false" + expected-response-type="java.lang.String" + reply-channel="replies" + charset="UTF-8" + order="77" + auto-startup="false"> + + - - diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests.java index 083fc544b8..727c42041e 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests.java @@ -21,6 +21,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.util.Map; + import org.junit.Test; import org.junit.runner.RunWith; @@ -28,6 +30,7 @@ import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; +import org.springframework.expression.Expression; import org.springframework.http.HttpMethod; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory; @@ -36,7 +39,6 @@ import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.http.DefaultOutboundRequestMapper; import org.springframework.integration.http.HttpRequestExecutingMessageHandler; import org.springframework.integration.http.OutboundRequestMapper; -import org.springframework.integration.http.ParameterExtractor; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -56,8 +58,6 @@ public class HttpOutboundGatewayParserTests { @Autowired private ApplicationContext applicationContext; - @Autowired - private ParameterExtractor parameterExtractor; @Test public void minimalConfig() { @@ -83,6 +83,7 @@ public class HttpOutboundGatewayParserTests { } @Test + @SuppressWarnings("unchecked") public void fullConfig() throws Exception { DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.fullConfigEndpoint); HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) endpointAccessor.getPropertyValue("handler"); @@ -114,7 +115,10 @@ public class HttpOutboundGatewayParserTests { Object sendTimeout = new DirectFieldAccessor( handlerAccessor.getPropertyValue("messagingTemplate")).getPropertyValue("sendTimeout"); assertEquals(new Long("1234"), sendTimeout); - assertEquals(parameterExtractor, handlerAccessor.getPropertyValue("parameterExtractor")); + Map uriVariableExpressions = + (Map) handlerAccessor.getPropertyValue("uriVariableExpressions"); + assertEquals(1, uriVariableExpressions.size()); + assertEquals("headers.bar", uriVariableExpressions.get("foo").getExpressionString()); } }