Skip to content

Migrate MediaType.sortByQualityValue#3901

Closed
strehle wants to merge 4 commits intodevelopfrom
simplify-exception-content-negotiation
Closed

Migrate MediaType.sortByQualityValue#3901
strehle wants to merge 4 commits intodevelopfrom
simplify-exception-content-negotiation

Conversation

@strehle
Copy link
Copy Markdown
Member

@strehle strehle commented May 6, 2026

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

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 ConvertingExceptionView to always write responses via a JSON-capable HttpMessageConverter and report JSON as the only supported media type on failure.
  • Simplify DefaultOAuth2ExceptionRenderer to always write JSON via message converters (no Accept-header sorting/negotiation).
  • Update OAuth2AuthenticationEntryPointTests to expect JSON error bodies and 401 for non-JSON Accept headers (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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@strehle strehle requested review from duanemay and fhanik May 6, 2026 16:42
@strehle
Copy link
Copy Markdown
Member Author

strehle commented May 7, 2026

close it for now and use the other PR

@strehle strehle closed this May 7, 2026
@strehle strehle deleted the simplify-exception-content-negotiation branch May 7, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants