Skip to content

encode soap request body with the configured charset#3433

Merged
velo merged 1 commit into
OpenFeign:masterfrom
alhudz:soap-encoder-charset
Jun 23, 2026
Merged

encode soap request body with the configured charset#3433
velo merged 1 commit into
OpenFeign:masterfrom
alhudz:soap-encoder-charset

Conversation

@alhudz

@alhudz alhudz commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Repro: configure SOAPEncoder with withCharsetEncoding(UTF-16) and encode an object whose body holds a non-ASCII character (e.g. Café).
Expected: the request body bytes match the UTF-16 declared in the XML prolog the marshaller wrote.
Actual: the body is mangled. SOAPEncoder.encode writes the message to a ByteArrayOutputStream in charsetEncoding, then the soap module does new String(bos.toByteArray()) and soap-jakarta does bos.toString(). Both decode those bytes with the JVM platform default charset, and RequestTemplate.body(String) re-encodes as UTF-8, so the configured encoding is dropped and any non-ASCII content is corrupted (pure ASCII survives by accident, which is why the existing tests miss it).
Fix: hand the marshalled bytes to template.body(bos.toByteArray(), charsetEncoding) in both modules, the same way UrlencodedFormContentProcessor already passes bytes plus charset.

Regression test in both SOAPCodecTest files encodes non-ASCII content under UTF-16.

@velo velo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the right fix for the SOAP charset path: keep the marshalled bytes and pass the configured charset through to RequestTemplate. The UTF-16 non-ASCII tests in both SOAP modules cover the regression well.

@velo velo merged commit baeba5a into OpenFeign:master Jun 23, 2026
3 checks passed
@velo velo mentioned this pull request Jun 23, 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.

2 participants