Skip to content

Commit 626b14e

Browse files
artembilangaryrussell
authored andcommitted
GH-3954: Fix WebFlux XML config for ambiguity (#3973)
* GH-3954: Fix WebFlux XML config for ambiguity Fixes #3954 When `web-client` attribute is provided for the WebFlux outbound components configuration via XML, the `encoding-mode` is silently ignored * Check for `encoding-mode` attribute presence in the `WebFluxOutboundChannelAdapterParser` when `web-client` is provided and throw respective exception to reject such a config **Cherry-pick to `5.5.x`** * * Improve error messages in the `WebFluxOutboundChannelAdapterParser`
1 parent e63edde commit 626b14e

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxOutboundChannelAdapterParser.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ static BeanDefinitionBuilder buildWebFluxRequestExecutingMessageHandler(Element
4949

5050
String webClientRef = element.getAttribute("web-client");
5151
if (StringUtils.hasText(webClientRef)) {
52+
if (element.hasAttribute("encoding-mode")) {
53+
parserContext.getReaderContext()
54+
.error("The 'web-client' and 'encoding-mode' attributes are mutually exclusive.", element);
55+
}
56+
5257
builder.getBeanDefinition()
5358
.getConstructorArgumentValues()
5459
.addIndexedArgumentValue(1, new RuntimeBeanReference(webClientRef));
@@ -65,8 +70,8 @@ static BeanDefinitionBuilder buildWebFluxRequestExecutingMessageHandler(Element
6570

6671
if (hasType && hasTypeExpression) {
6772
parserContext.getReaderContext()
68-
.error("The 'publisher-element-type' and 'publisher-element-type-expression' " +
69-
"are mutually exclusive. You can only have one or the other", element);
73+
.error("The 'publisher-element-type' and 'publisher-element-type-expression' attributes " +
74+
"are mutually exclusive.", element);
7075
}
7176

7277
if (hasType) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:int-webflux="http://www.springframework.org/schema/integration/webflux"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
6+
http://www.springframework.org/schema/integration/webflux https://www.springframework.org/schema/integration/webflux/spring-integration-webflux.xsd">
7+
8+
<bean id="webClient" class="org.springframework.web.reactive.function.client.WebClient"
9+
factory-method="create"/>
10+
11+
<int-webflux:outbound-gateway url="/fake"
12+
web-client="webClient"
13+
encoding-mode="VALUES_ONLY"/>
14+
15+
</beans>

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParserTests-context.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<outbound-gateway id="reactiveFullConfig"
2626
url="http://localhost/test2"
2727
http-method="PUT"
28+
encoding-mode="NONE"
2829
request-channel="requests"
2930
reply-timeout="1234"
3031
extract-request-payload="false"

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParserTests.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.integration.webflux.config;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2021

2122
import java.nio.charset.StandardCharsets;
2223
import java.util.Map;
@@ -26,7 +27,9 @@
2627
import org.springframework.beans.DirectFieldAccessor;
2728
import org.springframework.beans.factory.annotation.Autowired;
2829
import org.springframework.beans.factory.annotation.Qualifier;
30+
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
2931
import org.springframework.context.ApplicationContext;
32+
import org.springframework.context.support.ClassPathXmlApplicationContext;
3033
import org.springframework.expression.Expression;
3134
import org.springframework.http.HttpMethod;
3235
import org.springframework.integration.endpoint.AbstractEndpoint;
@@ -37,6 +40,7 @@
3740
import org.springframework.util.ObjectUtils;
3841
import org.springframework.web.reactive.function.BodyExtractor;
3942
import org.springframework.web.reactive.function.client.WebClient;
43+
import org.springframework.web.util.DefaultUriBuilderFactory;
4044

4145
/**
4246
* @author Artem Bilan
@@ -129,6 +133,17 @@ public void reactiveFullConfig() {
129133
.isEqualTo("headers.elementType");
130134
assertThat(handlerAccessor.getPropertyValue("extractResponseBody"))
131135
.isEqualTo(false);
136+
assertThat(handlerAccessor.getPropertyValue("webClient.uriBuilderFactory.encodingMode"))
137+
.isEqualTo(DefaultUriBuilderFactory.EncodingMode.NONE);
138+
}
139+
140+
@Test
141+
void webClientAndEncodingModeExclusiveness() {
142+
assertThatExceptionOfType(BeanDefinitionParsingException.class)
143+
.isThrownBy(() ->
144+
new ClassPathXmlApplicationContext("WebFluxOutboundGatewayParser-encoding-mode-fail.xml",
145+
getClass()))
146+
.withMessageContaining("The 'web-client' and 'encoding-mode' attributes are mutually exclusive");
132147
}
133148

134149
}

0 commit comments

Comments
 (0)