commit | author | age
|
513246
|
1 |
package org.keycloak.protocol.cas.utils; |
MP |
2 |
|
|
3 |
import org.jboss.resteasy.spi.HttpRequest; |
|
4 |
import org.keycloak.protocol.cas.CASLoginProtocol; |
|
5 |
|
cdfb79
|
6 |
import javax.ws.rs.BadRequestException; |
513246
|
7 |
import javax.ws.rs.core.*; |
MP |
8 |
|
|
9 |
public class ContentTypeHelper { |
|
10 |
private final HttpRequest request; |
|
11 |
private final Request restRequest; |
|
12 |
private final UriInfo uriInfo; |
|
13 |
|
|
14 |
public ContentTypeHelper(HttpRequest request, Request restRequest, UriInfo uriInfo) { |
|
15 |
this.request = request; |
|
16 |
this.restRequest = restRequest; |
|
17 |
this.uriInfo = uriInfo; |
|
18 |
} |
|
19 |
|
|
20 |
public MediaType selectResponseType() { |
|
21 |
String format = uriInfo.getQueryParameters().getFirst(CASLoginProtocol.FORMAT_PARAM); |
|
22 |
if (format != null && !format.isEmpty()) { |
5ba0b0
|
23 |
//if parameter is set, it overrides all header values (see spec section 2.5.1) |
MP |
24 |
request.getMutableHeaders().putSingle(HttpHeaders.ACCEPT, "application/" + format.toLowerCase()); |
513246
|
25 |
} |
de7d25
|
26 |
try { |
MP |
27 |
Variant variant = restRequest.selectVariant(Variant.mediaTypes(MediaType.APPLICATION_XML_TYPE, MediaType.APPLICATION_JSON_TYPE).build()); |
|
28 |
return variant == null ? MediaType.APPLICATION_XML_TYPE : variant.getMediaType(); |
|
29 |
} catch (BadRequestException e) { |
|
30 |
//the default Accept header set by java.net.HttpURLConnection is invalid (cf. RESTEASY-960) |
|
31 |
return MediaType.APPLICATION_XML_TYPE; |
|
32 |
} |
513246
|
33 |
} |
MP |
34 |
} |