Skip to content

Conversation

@artembilan
Copy link
Member

Fixes #3938

The encoding-mode is a property of the RestTemplate. Therefore, it cannot be set on the component configuration together with an externally injected rest-template

Even if HttpRequestExecutingMessageHandler has an assertion for such an ambiguity, the XML parser just ignores this encoding-mode when it encounters the rest-template

  • Fix HttpAdapterParsingUtils.verifyNoRestTemplateAttributes() to check for not allowed attributes with a encoding-mode as well
  • Remove a default from the encoding-mode to not cause an ambiguity in the parser
  • Fix some typos in the spring-integration-http.xsd
  • Rework OutboundResponseTypeTests to JUnit 5

Cherry-pick to 5.5.x

Fixes spring-projects#3938

The `encoding-mode` is a property of the `RestTemplate`.
Therefore, it cannot be set on the component configuration together with
an externally injected `rest-template`

Even if `HttpRequestExecutingMessageHandler` has an assertion for such
an ambiguity, the XML parser just ignores this `encoding-mode`
when it encounters the `rest-template`

* Fix `HttpAdapterParsingUtils.verifyNoRestTemplateAttributes()` to check for not allowed
attributes with a `encoding-mode` as well
* Remove a `default` from the `encoding-mode` to not cause an ambiguity in the parser
* Fix some typos in the `spring-integration-http.xsd`
* Rework `OutboundResponseTypeTests` to JUnit 5

**Cherry-pick to `5.5.x`**

static final String[] SYNC_REST_TEMPLATE_REFERENCE_ATTRIBUTES = {
"request-factory", "error-handler", "message-converters"
"request-factory", "error-handler", "message-converters", "encoding-mode"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this will break the for loops that use this constant (gateway and adapter parsers). (Set reference instead of value). We don't appear to have test coverage for this condition.

I also think we need to improve the error message to say that this property must be set on the template's UriBuilderFactory, whereas the other 3 are set on the template itself.

…ils`

* Cover `encoding-mode` and `rest-template` ambiguity with a test against failing XML configuration
@garyrussell
Copy link
Contributor

Could we also improve

parserContext.getReaderContext().error("When providing a 'rest-template' reference, the '"
				+ attributeName + "' attribute is not allowed.",
		parserContext.extractSource(element));

to

parserContext.getReaderContext().error("When providing a 'rest-template' reference, the '"
				+ attributeName + "' attribute is not allowed, it must be set on the provided template instead",
		parserContext.extractSource(element));

??

@garyrussell garyrussell merged commit 053c86a into spring-projects:main Nov 7, 2022
garyrussell pushed a commit that referenced this pull request Nov 7, 2022
* GH-3938: Fix HTTP XML configuration for ambiguity

Fixes #3938

The `encoding-mode` is a property of the `RestTemplate`.
Therefore, it cannot be set on the component configuration together with
an externally injected `rest-template`

Even if `HttpRequestExecutingMessageHandler` has an assertion for such
an ambiguity, the XML parser just ignores this `encoding-mode`
when it encounters the `rest-template`

* Fix `HttpAdapterParsingUtils.verifyNoRestTemplateAttributes()` to check for not allowed
attributes with a `encoding-mode` as well
* Remove a `default` from the `encoding-mode` to not cause an ambiguity in the parser
* Fix some typos in the `spring-integration-http.xsd`
* Rework `OutboundResponseTypeTests` to JUnit 5

**Cherry-pick to `5.5.x`**

* * Fix error handling for `encoding-mode` in the `HttpAdapterParsingUtils`
* Cover `encoding-mode` and `rest-template` ambiguity with a test against failing XML configuration

* * Improve error message for ambiguous attributes in the `HttpAdapterParsingUtils`
@garyrussell
Copy link
Contributor

... and cherry-picked as e4e8041

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

encoding-mode attribute of http:outbound-gateway is silently ignore if rest-template is present

2 participants