Skip to main content

Fixing Keycloak Error : MediaType not set on path , with response status 200

Using a custom endpoint with Media Type set as 'Application/Json'.
When this endpoint is accessed, below error is returned.

ERROR [org.keycloak.headers.DefaultSecurityHeadersProvider] (default task-16) MediaType not set on path /auth/realms/my-realm/broker/keycloak-oidc/token, with response status 200
06:31:08,489 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-16) Uncaught server error: javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
at org.keycloak.keycloak-services@10.0.2//org.keycloak.headers.DefaultSecurityHeadersProvider.addHeaders(DefaultSecurityHeadersProvider.java:71)
at org.keycloak.keycloak-services@10.0.2//org.keycloak.services.filters.KeycloakSecurityHeadersFilter.filter(KeycloakSecurityHeadersFilter.java:36)

The fix for this is to bind the blank response to Application/Json as follows:

return Response.ok(json, MediaType.APPLICATION_JSON).build();


Do try it out, and let me know if it works.

Do drop some comments is any issues are faced.



=============== Happy Coding ===============


Comments