From ea0863757fdaf1c34c11edd6675455d00e80b43b Mon Sep 17 00:00:00 2001 From: abilan Date: Thu, 15 Dec 2022 10:44:34 -0500 Subject: [PATCH 1/2] GH-3954: Fix WebFlux XML config for ambiguity Fixes https://github.com/spring-projects/spring-integration/issues/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`** --- .../WebFluxOutboundChannelAdapterParser.java | 5 +++++ ...uxOutboundGatewayParser-encoding-mode-fail.xml | 15 +++++++++++++++ .../WebFluxOutboundGatewayParserTests-context.xml | 1 + .../config/WebFluxOutboundGatewayParserTests.java | 15 +++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParser-encoding-mode-fail.xml diff --git a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxOutboundChannelAdapterParser.java b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxOutboundChannelAdapterParser.java index d9afb27ba44..45d20d8c3ff 100644 --- a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxOutboundChannelAdapterParser.java +++ b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxOutboundChannelAdapterParser.java @@ -51,6 +51,11 @@ static BeanDefinitionBuilder buildWebFluxRequestExecutingMessageHandler(Element String webClientRef = element.getAttribute("web-client"); if (StringUtils.hasText(webClientRef)) { + if (element.hasAttribute("encoding-mode")) { + parserContext.getReaderContext() + .error("The 'web-client' and 'encoding-mode' are mutually exclusive.", element); + } + builder.getBeanDefinition() .getConstructorArgumentValues() .addIndexedArgumentValue(1, new RuntimeBeanReference(webClientRef)); diff --git a/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParser-encoding-mode-fail.xml b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParser-encoding-mode-fail.xml new file mode 100644 index 00000000000..c3e63746796 --- /dev/null +++ b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParser-encoding-mode-fail.xml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParserTests-context.xml b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParserTests-context.xml index b78b84d2104..b217a78bd2a 100644 --- a/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParserTests-context.xml +++ b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParserTests-context.xml @@ -25,6 +25,7 @@ + new ClassPathXmlApplicationContext("WebFluxOutboundGatewayParser-encoding-mode-fail.xml", + getClass())) + .withMessageContaining("The 'web-client' and 'encoding-mode' are mutually exclusive"); } } From 668b13858268664a3bb4228d857de68bedef2951 Mon Sep 17 00:00:00 2001 From: abilan Date: Thu, 15 Dec 2022 12:25:23 -0500 Subject: [PATCH 2/2] * Improve error messages in the `WebFluxOutboundChannelAdapterParser` --- .../webflux/config/WebFluxOutboundChannelAdapterParser.java | 6 +++--- .../webflux/config/WebFluxOutboundGatewayParserTests.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxOutboundChannelAdapterParser.java b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxOutboundChannelAdapterParser.java index 45d20d8c3ff..e4c8c8328ff 100644 --- a/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxOutboundChannelAdapterParser.java +++ b/spring-integration-webflux/src/main/java/org/springframework/integration/webflux/config/WebFluxOutboundChannelAdapterParser.java @@ -53,7 +53,7 @@ static BeanDefinitionBuilder buildWebFluxRequestExecutingMessageHandler(Element if (StringUtils.hasText(webClientRef)) { if (element.hasAttribute("encoding-mode")) { parserContext.getReaderContext() - .error("The 'web-client' and 'encoding-mode' are mutually exclusive.", element); + .error("The 'web-client' and 'encoding-mode' attributes are mutually exclusive.", element); } builder.getBeanDefinition() @@ -72,8 +72,8 @@ static BeanDefinitionBuilder buildWebFluxRequestExecutingMessageHandler(Element if (hasType && hasTypeExpression) { parserContext.getReaderContext() - .error("The 'publisher-element-type' and 'publisher-element-type-expression' " + - "are mutually exclusive. You can only have one or the other", element); + .error("The 'publisher-element-type' and 'publisher-element-type-expression' attributes " + + "are mutually exclusive.", element); } if (hasType) { diff --git a/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParserTests.java b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParserTests.java index 0ceb493d2e1..5daed5cd38b 100644 --- a/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParserTests.java +++ b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/config/WebFluxOutboundGatewayParserTests.java @@ -146,7 +146,7 @@ void webClientAndEncodingModeExclusiveness() { .isThrownBy(() -> new ClassPathXmlApplicationContext("WebFluxOutboundGatewayParser-encoding-mode-fail.xml", getClass())) - .withMessageContaining("The 'web-client' and 'encoding-mode' are mutually exclusive"); + .withMessageContaining("The 'web-client' and 'encoding-mode' attributes are mutually exclusive"); } }