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 407e7fb92f..479dde16eb 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 @@ -35,6 +35,7 @@ import org.springframework.util.xml.DomUtils; * Parser for the 'outbound-channel-adapter' element of the http namespace. * * @author Mark Fisher + * @author Oleg Zhurakousky * @since 2.0 */ public class HttpOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser { @@ -46,7 +47,18 @@ public class HttpOutboundChannelAdapterParser extends AbstractOutboundChannelAda builder.addPropertyValue("expectReply", false); builder.addConstructorArgValue(element.getAttribute("url")); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "http-method"); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters"); + + String restTemplate = element.getAttribute("rest-template"); + if (StringUtils.hasText(restTemplate)){ + HttpParsingUtils.verifyNoRestTemplateAttributes(element, parserContext); + builder.addPropertyReference("restTemplate", restTemplate); + } + else { + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters"); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-handler"); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-factory"); + } + String headerMapper = element.getAttribute("header-mapper"); String mappedRequestHeaders = element.getAttribute("mapped-request-headers"); if (StringUtils.hasText(headerMapper)) { @@ -66,8 +78,6 @@ public class HttpOutboundChannelAdapterParser extends AbstractOutboundChannelAda IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "charset"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-payload"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "expected-response-type"); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-factory"); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-handler"); List uriVariableElements = DomUtils.getChildElementsByTagName(element, "uri-variable"); if (!CollectionUtils.isEmpty(uriVariableElements)) { Map uriVariableExpressions = new HashMap(); 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 d5b795630c..1d2945ae40 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 @@ -48,7 +48,19 @@ public class HttpOutboundGatewayParser extends AbstractConsumerEndpointParser { "org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler"); builder.addConstructorArgValue(element.getAttribute("url")); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "http-method"); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters"); + //IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters"); + + String restTemplate = element.getAttribute("rest-template"); + if (StringUtils.hasText(restTemplate)){ + HttpParsingUtils.verifyNoRestTemplateAttributes(element, parserContext); + builder.addPropertyReference("restTemplate", restTemplate); + } + else { + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converters"); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-handler"); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-factory"); + } + String headerMapper = element.getAttribute("header-mapper"); String mappedRequestHeaders = element.getAttribute("mapped-request-headers"); String mappedResponseHeaders = element.getAttribute("mapped-response-headers"); @@ -71,8 +83,8 @@ public class HttpOutboundGatewayParser extends AbstractConsumerEndpointParser { 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, "error-handler"); + //IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-factory"); + //IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-handler"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel", "outputChannel"); List uriVariableElements = DomUtils.getChildElementsByTagName(element, "uri-variable"); if (!CollectionUtils.isEmpty(uriVariableElements)) { diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpParsingUtils.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpParsingUtils.java new file mode 100644 index 0000000000..6494409bad --- /dev/null +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpParsingUtils.java @@ -0,0 +1,40 @@ +/* + * 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.http.config; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.xml.ParserContext; + +/** + * @author Oleg Zhurakousky + * @since 2.0.2 + */ +public class HttpParsingUtils { + + private static final String[] REST_TEMPLATE_ATTRIBUTES = { + "request-factory", "error-handler", "message-converters" + }; + + static void verifyNoRestTemplateAttributes(Element element, ParserContext parserContext) { + for (String attributeName : REST_TEMPLATE_ATTRIBUTES) { + if (element.hasAttribute(attributeName)) { + parserContext.getReaderContext().error("When providing a 'rest-template' reference, the '" + + attributeName + "' attribute is not allowed", parserContext.extractSource(element)); + } + } + } +} diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java index 9d9808f540..732f097b0d 100755 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java @@ -94,7 +94,7 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe private final Map uriVariableExpressions = new HashMap(); - private final RestTemplate restTemplate = new RestTemplate(); + private volatile RestTemplate restTemplate = new RestTemplate(); private final StandardEvaluationContext evaluationContext = new StandardEvaluationContext(); @@ -115,6 +115,9 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe this.uri = uri; } + public void setRestTemplate(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } /** * Specify the {@link HttpMethod} for requests. The default method will be POST. 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 85fb61689f..5a34d13e4c 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 @@ -234,6 +234,15 @@ The String "HTTP_REQUEST_HEADERS" will match against any of the standard HTTP Re + + + + + + + + + @@ -362,6 +371,15 @@ The String "HTTP_REQUEST_HEADERS" will match against any of the standard HTTP Re + + + + + + + + +