From 4cd00295797e5152bbfca8ee0102670f30ec6a07 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 15 Dec 2022 13:05:35 -0500 Subject: [PATCH] GH-3954: Fix WebFlux XML config for ambiguity (#3973) * 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`** * * Improve error messages in the `WebFluxOutboundChannelAdapterParser` --- .../WebFluxOutboundChannelAdapterParser.java | 9 +++++++-- ...uxOutboundGatewayParser-encoding-mode-fail.xml | 15 +++++++++++++++ .../WebFluxOutboundGatewayParserTests-context.xml | 1 + .../config/WebFluxOutboundGatewayParserTests.java | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) 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 d9afb27ba4..e4c8c8328f 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 @@ public class WebFluxOutboundChannelAdapterParser extends HttpOutboundChannelAdap String webClientRef = element.getAttribute("web-client"); if (StringUtils.hasText(webClientRef)) { + if (element.hasAttribute("encoding-mode")) { + parserContext.getReaderContext() + .error("The 'web-client' and 'encoding-mode' attributes are mutually exclusive.", element); + } + builder.getBeanDefinition() .getConstructorArgumentValues() .addIndexedArgumentValue(1, new RuntimeBeanReference(webClientRef)); @@ -67,8 +72,8 @@ public class WebFluxOutboundChannelAdapterParser extends HttpOutboundChannelAdap 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/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 0000000000..c3e6374679 --- /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 b78b84d210..b217a78bd2 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' attributes are mutually exclusive"); } }