Closed
Conversation
MediaType.sortByQualityValue() was removed in Spring 7. Rather than reimplementing the sorting logic locally, simplify the two exception renderers to always write JSON responses directly. UAA is a JSON-only API — the Accept-header content negotiation was legacy code from Spring Security OAuth2 that never selected a non-JSON converter in practice. This removes the need for a custom MediaTypeUtils utility class and 200+ lines of reimplemented Spring internals. Clients sending non-JSON Accept headers (e.g. text/html) now receive the JSON error body with the correct HTTP status instead of a 406 with no body.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates UAA’s exception rendering to be JSON-only, eliminating reliance on MediaType.sortByQualityValue() (removed in Spring 7) by always serializing error responses as application/json regardless of the request’s Accept header.
Changes:
- Simplify
ConvertingExceptionViewto always write responses via a JSON-capableHttpMessageConverterand report JSON as the only supported media type on failure. - Simplify
DefaultOAuth2ExceptionRendererto always write JSON via message converters (no Accept-header sorting/negotiation). - Update
OAuth2AuthenticationEntryPointTeststo expect JSON error bodies and401for non-JSONAcceptheaders (e.g., XML/HTML).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| server/src/test/java/org/cloudfoundry/identity/uaa/oauth/provider/error/OAuth2AuthenticationEntryPointTests.java | Updates expectations so XML/HTML Accept headers still receive JSON error bodies with 401. |
| server/src/main/java/org/cloudfoundry/identity/uaa/web/ConvertingExceptionView.java | Removes Accept-based media type selection and always writes exception responses as JSON. |
| server/src/main/java/org/cloudfoundry/identity/uaa/oauth/provider/error/DefaultOAuth2ExceptionRenderer.java | Removes Accept-based media type selection and always writes OAuth2 exception responses as JSON. |
…-content-negotiation
Member
Author
|
close it for now and use the other PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MediaType.sortByQualityValue() was removed in Spring 7. Rather than
reimplementing the sorting logic locally, simplify the two exception
renderers to always write JSON responses directly. UAA is a JSON-only
API — the Accept-header content negotiation was legacy code from
Spring Security OAuth2 that never selected a non-JSON converter in
practice.
This removes the need for a custom MediaTypeUtils utility class and
200+ lines of reimplemented Spring internals. Clients sending non-JSON
Accept headers (e.g. text/html) now receive the JSON error body with
the correct HTTP status instead of a 406 with no body.
Alternative PR to #3856