Skip to content

GH-11235: Fix form data read in MultipartAware converter - #11240

Closed
kdelay wants to merge 1 commit into
spring-projects:mainfrom
kdelay:GH-11235
Closed

GH-11235: Fix form data read in MultipartAware converter#11240
kdelay wants to merge 1 commit into
spring-projects:mainfrom
kdelay:GH-11235

Conversation

@kdelay

@kdelay kdelay commented Aug 2, 2026

Copy link
Copy Markdown

Fixes: gh-11235

HttpDslTests.testHttpProxyFlow() fails because of a regression in MultipartAwareFormHttpMessageConverter, not because of the reflective RestTestClient field path.

The converter used to delegate to an AllEncompassingFormHttpMessageConverter, which reads and writes both application/x-www-form-urlencoded and multipart/form-data. It now delegates to a MultipartHttpMessageConverter, which handles only multipart/form-data, so any form-urlencoded request body fails with:

org.springframework.http.converter.HttpMessageNotReadableException:
No multipart boundary found in Content-Type: "application/x-www-form-urlencoded"

The proxied request in that test is a POST to /service/internal with a form-urlencoded body, which is why it surfaced there. Any HTTP inbound gateway or channel adapter receiving a form post is affected, since HttpRequestHandlingEndpointSupport registers this converter first.

Changes:

  • non-multipart reads and writes go to a FormHttpMessageConverter; the MultipartHttpMessageConverter is kept for multipart, selected by the same isMultipart() rule the old delegate used (a multipart content type, or a non-String value in the map)
  • getSupportedMediaTypes() reports the media types of both delegates and canWrite() accepts both; with the multipart-only delegate, application/x-www-form-urlencoded had disappeared from both
  • the read delegates against a MultiValueMap target type. HttpRequestHandlingEndpointSupport.extractRequestBody() falls back to byte[] when no request payload type is configured, and FormHttpMessageConverter.read() returns a single-value Map for a non-MultiValueMap type, which then fails the cast in this converter.
  • setCharset() now applies to both delegates

Verification:

  • MultipartAwareFormHttpMessageConverterTests is new; with only the test files applied and the converter reverted, all four of its tests fail, as does testHttpProxyFlow()
  • ./gradlew :spring-integration-http:test — 235 tests, 0 failures
  • ./gradlew :spring-integration-webflux:test — 35 tests, 0 failures
  • checkstyleMain and checkstyleTest pass for the http module

Fixes: spring-projectsgh-11235

`MultipartAwareFormHttpMessageConverter` used to delegate to an
`AllEncompassingFormHttpMessageConverter`, which reads and writes both
`application/x-www-form-urlencoded` and `multipart/form-data`. It now
delegates to a `MultipartHttpMessageConverter`, which handles only
`multipart/form-data`. Therefore a form-urlencoded request body fails
with `No multipart boundary found in Content-Type`, and this is what
disabled `HttpDslTests.testHttpProxyFlow()`: the proxied `POST` to the
internal gateway carries a form-urlencoded body.

* delegate non-multipart reads and writes to a `FormHttpMessageConverter`
and keep the `MultipartHttpMessageConverter` for multipart
* report the media types of both delegates from `getSupportedMediaTypes()`
and accept both in `canWrite()`
* read against a `MultiValueMap` target type: the inbound endpoint falls
back to `byte[]` when no request payload type is configured, and
`FormHttpMessageConverter` returns a single-value `Map` for that type
* add `MultipartAwareFormHttpMessageConverterTests` and re-enable
`HttpDslTests.testHttpProxyFlow()`

Signed-off-by: kdelay <kdelay20@gmail.com>
@artembilan

Copy link
Copy Markdown
Member

Duplicate of: #11236?

give you AI a hint to not fix if it is present on the issue already .

@kdelay kdelay closed this Aug 2, 2026
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.

Investigate flaky/failing HttpDslTests.testHttpProxyFlow()

2 participants