Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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.
Expand Down Expand Up @@ -36,9 +36,10 @@
* @author Gary Russell
* @author Artem Bilan
* @author Shiliang Li
*
* @since 2.0.2
*/
abstract class HttpAdapterParsingUtils {
final class HttpAdapterParsingUtils {

static final String[] SYNC_REST_TEMPLATE_REFERENCE_ATTRIBUTES = {
"request-factory", "error-handler", "message-converters"
Expand All @@ -48,14 +49,22 @@ static void verifyNoRestTemplateAttributes(Element element, ParserContext parser
for (String attributeName : SYNC_REST_TEMPLATE_REFERENCE_ATTRIBUTES) {
if (element.hasAttribute(attributeName)) {
parserContext.getReaderContext().error("When providing a 'rest-template' reference, the '"
+ attributeName + "' attribute is not allowed.",
+ attributeName + "' attribute is not allowed, " +
"it must be set on the provided template instead",
parserContext.extractSource(element));
}
}

if (element.hasAttribute("encoding-mode")) {
parserContext.getReaderContext().error("When providing a 'rest-template' reference, " +
"the 'encoding-mode' must be set on the 'RestTemplate.uriTemplateHandler' property.",
parserContext.extractSource(element));
}
}

static void configureUriVariableExpressions(BeanDefinitionBuilder builder, ParserContext parserContext,
Element element) {

String uriVariablesExpression = element.getAttribute("uri-variables-expression");

List<Element> uriVariableElements = DomUtils.getChildElementsByTagName(element, "uri-variable");
Expand All @@ -73,7 +82,7 @@ static void configureUriVariableExpressions(BeanDefinitionBuilder builder, Parse
}

if (hasUriVariableExpressions) {
ManagedMap<String, Object> uriVariableExpressions = new ManagedMap<String, Object>();
ManagedMap<String, Object> uriVariableExpressions = new ManagedMap<>();
for (Element uriVariableElement : uriVariableElements) {
String name = uriVariableElement.getAttribute("name");
String expression = uriVariableElement.getAttribute("expression");
Expand Down Expand Up @@ -146,8 +155,8 @@ static void setExpectedResponseOrExpression(Element element, ParserContext parse

if (hasExpectedResponseType && hasExpectedResponseTypeExpression) {
parserContext.getReaderContext()
.error("The 'expected-response-type' and 'expected-response-type-expression' are mutually exclusive. " +
"You can only have one or the other", element);
.error("The 'expected-response-type' and 'expected-response-type-expression' " +
"are mutually exclusive. You can only have one or the other", element);
}

RootBeanDefinition expressionDef = null;
Expand All @@ -164,4 +173,7 @@ else if (hasExpectedResponseTypeExpression) {
}
}

private HttpAdapterParsingUtils() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@
By default 'status-code-expression' is null, meaning that the default '200 OK' response status
will be returned.
The 'http:inbound-gateway' resolves the 'status code' from the 'http_statusCode' header of the
reply
Message.
reply Message.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
Expand Down Expand Up @@ -412,7 +411,7 @@
<xsd:annotation>
<xsd:documentation>
Specify whether the outbound message's payload should be extracted
when preparing the request body. Otherwise the Message instance itself
when preparing the request body. Otherwise, the Message instance itself
will be serialized.
The default value is 'true'.
</xsd:documentation>
Expand Down Expand Up @@ -484,7 +483,7 @@
<xsd:annotation>
<xsd:documentation>
Specifies whether the outbound message's payload should be extracted
when preparing the request body. Otherwise the Message instance itself
when preparing the request body. Otherwise, the Message instance itself
will be serialized.
The default value is 'true'.
</xsd:documentation>
Expand All @@ -493,8 +492,8 @@
<xsd:attribute name="transfer-cookies" type="xsd:string" default="false">
<xsd:annotation>
<xsd:documentation><![CDATA[
When set to "true", if a response contains a 'Set-Cookie' header, it will be mapped to a 'Cookie' header. This enables simple
cookie handling where subsequent HTTP interactions in the same message flow can use a cookie
When set to "true", if a response contains a 'Set-Cookie' header, it will be mapped to a 'Cookie' header.
This enables simple cookie handling where subsequent HTTP interactions in the same message flow can use a cookie
supplied by the server. Default is "false".
]]></xsd:documentation>
</xsd:annotation>
Expand Down Expand Up @@ -602,7 +601,8 @@
<xsd:complexType name="headerType">
<xsd:annotation>
<xsd:documentation><![CDATA[
Expression to be evaluated against the ServletRequest(makes BODY and Headers available) as well as URI Variables (e.g., foo/bar/{id}).
Expression to be evaluated against the ServletRequest(makes BODY and Headers available)
as well as URI Variables (e.g., foo/bar/{id}).
]]></xsd:documentation>
</xsd:annotation>
<xsd:attribute name="name" use="required">
Expand Down Expand Up @@ -759,7 +759,7 @@
<xsd:attribute name="allow-credentials" default="true">
<xsd:annotation>
<xsd:documentation>
Set to "true" if the the browser should include any cookies associated to the domain
Set to "true" if the browser should include any cookies associated to the domain
of the request being annotated, or "false" if it should not. Empty string "" means undefined.
If true, the pre-flight response will include the header
'Access-Control-Allow-Credentials=true'. Default value is "true".
Expand Down Expand Up @@ -826,7 +826,7 @@
<xsd:annotation>
<xsd:documentation>
Provide a reference to a list of HttpMessageConverter instances. If specified,
these converters will replace all of the default converters that would normally
these converters will replace all default converters that would normally
be present on the underlying RestTemplate.
</xsd:documentation>
</xsd:annotation>
Expand All @@ -852,10 +852,11 @@
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="encoding-mode" default="TEMPLATE_AND_VALUES">
<xsd:attribute name="encoding-mode">
<xsd:annotation>
<xsd:documentation>
Set the encoding mode during URI building.
Defaults to 'TEMPLATE_AND_VALUES'
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
Expand Down Expand Up @@ -948,7 +949,7 @@
<xsd:attribute name="uri-variables-expression" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the SpEL expression to be evaluate as a Map for URI variable placeholders within 'url'.
Specifies the SpEL expression to be evaluated as a Map for URI variable placeholders within 'url'.
This attribute is mutually exclusive with 'uri-variable' sub-elements.
]]></xsd:documentation>
</xsd:annotation>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/http https://www.springframework.org/schema/integration/http/spring-integration-http.xsd">

<bean id="restTemplate" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.web.client.RestTemplate"/>
</bean>

<int-http:outbound-gateway url="/fake"
rest-template="restTemplate"
encoding-mode="NONE"/>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/integration/http
https://www.springframework.org/schema/integration/http/spring-integration-http.xsd
http://www.springframework.org/schema/integration
https://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
https://www.springframework.org/schema/util/spring-util.xsd">
https://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"/>

Expand Down
Loading