From e46d5b727f0206f04b41a511d73f8b9510f97501 Mon Sep 17 00:00:00 2001
From: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Date: Thu, 05 Oct 2023 08:47:15 +0000
Subject: [PATCH] Update to Keycloak 22.0.4

---
 src/main/java/org/keycloak/protocol/cas/utils/ContentTypeHelper.java |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 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 0e13ca6..789c8f9 100644
--- a/src/main/java/org/keycloak/protocol/cas/utils/ContentTypeHelper.java
+++ b/src/main/java/org/keycloak/protocol/cas/utils/ContentTypeHelper.java
@@ -1,9 +1,9 @@
 package org.keycloak.protocol.cas.utils;
 
+import jakarta.ws.rs.BadRequestException;
+import jakarta.ws.rs.core.*;
 import org.jboss.resteasy.spi.HttpRequest;
 import org.keycloak.protocol.cas.CASLoginProtocol;
-
-import javax.ws.rs.core.*;
 
 public class ContentTypeHelper {
     private final HttpRequest request;
@@ -22,7 +22,12 @@
             //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