Skip to content

Fix default charset in Undertow consumer when Content-Type omits charset#22471

Open
Croway wants to merge 1 commit intoapache:mainfrom
Croway:quick-fix/undertow-default-charset
Open

Fix default charset in Undertow consumer when Content-Type omits charset#22471
Croway wants to merge 1 commit intoapache:mainfrom
Croway:quick-fix/undertow-default-charset

Conversation

@Croway
Copy link
Copy Markdown
Contributor

@Croway Croway commented Apr 7, 2026

Summary

  • Undertow's getRequestCharset() defaults to ISO-8859-1 when no charset is specified in the Content-Type header, causing UTF-8 encoded request bodies (e.g. application/json) to be decoded incorrectly
  • Only set the exchange charset property when explicitly specified in the header, letting Camel's type conversion default to UTF-8 — matching the behavior of DefaultHttpBinding
  • Added test that sends JSON with non-ASCII UTF-8 characters and Content-Type: application/json (no charset)

Test plan

  • New test RestUndertowHttpPostJsonPojoCharsetTest fails before fix, passes after
  • All 161 existing Undertow tests pass

… no charset

Undertow's getRequestCharset() defaults to ISO-8859-1 when no charset
is specified in the Content-Type header. This causes UTF-8 encoded
request bodies to be decoded incorrectly. Only set the exchange charset
property when explicitly specified, letting Camel default to UTF-8.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

Copy link
Copy Markdown
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

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

Nice fix, thanks @Croway! 👍

The change correctly aligns UndertowConsumer with DefaultHttpBinding's behavior — only setting the charset property when explicitly specified in the Content-Type header, rather than relying on Undertow's getRequestCharset() which defaults to ISO-8859-1.

The test coverage is good — sending non-ASCII UTF-8 characters with Content-Type: application/json (no charset) is exactly the right scenario to validate.

One minor note: there's no JIRA ticket linked. For changelog traceability a JIRA issue is typically preferred even for bug fixes, but not blocking.

LGTM ✅

Claude Code on behalf of Guillaume Nodet

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 7, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants