From 0ae1021c26e95b49d6235c6f52fc509bc8c08271 Mon Sep 17 00:00:00 2001 From: Matthias Piepkorn <mpiepk@gmail.com> Date: Mon, 22 Jan 2018 12:01:26 +0000 Subject: [PATCH] add Keycloak 3.4.3 to CI matrix --- src/main/java/org/keycloak/protocol/cas/utils/ContentTypeHelper.java | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/keycloak/protocol/cas/utils/ContentTypeHelper.java b/src/main/java/org/keycloak/protocol/cas/utils/ContentTypeHelper.java index e842ef0..5096474 100644 --- a/src/main/java/org/keycloak/protocol/cas/utils/ContentTypeHelper.java +++ b/src/main/java/org/keycloak/protocol/cas/utils/ContentTypeHelper.java @@ -1,5 +1,6 @@ package org.keycloak.protocol.cas.utils; +import org.jboss.resteasy.spi.BadRequestException; import org.jboss.resteasy.spi.HttpRequest; import org.keycloak.protocol.cas.CASLoginProtocol; @@ -19,9 +20,15 @@ public MediaType selectResponseType() { String format = uriInfo.getQueryParameters().getFirst(CASLoginProtocol.FORMAT_PARAM); if (format != null && !format.isEmpty()) { - request.getMutableHeaders().add(HttpHeaders.ACCEPT, "application/" + format); + //if parameter is set, it overrides all header values (see spec section 2.5.1) + request.getMutableHeaders().putSingle(HttpHeaders.ACCEPT, "application/" + format.toLowerCase()); } - Variant variant = restRequest.selectVariant(Variant.mediaTypes(MediaType.APPLICATION_XML_TYPE, MediaType.APPLICATION_JSON_TYPE).build()); - return variant == null ? MediaType.APPLICATION_XML_TYPE : variant.getMediaType(); + try { + Variant variant = restRequest.selectVariant(Variant.mediaTypes(MediaType.APPLICATION_XML_TYPE, MediaType.APPLICATION_JSON_TYPE).build()); + return variant == null ? MediaType.APPLICATION_XML_TYPE : variant.getMediaType(); + } catch (BadRequestException e) { + //the default Accept header set by java.net.HttpURLConnection is invalid (cf. RESTEASY-960) + return MediaType.APPLICATION_XML_TYPE; + } } } -- Gitblit v1.9.1