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 |
|
|
6 |
import javax.ws.rs.core.*; |
|
7 |
|
|
8 |
public class ContentTypeHelper { |
|
9 |
private final HttpRequest request; |
|
10 |
private final Request restRequest; |
|
11 |
private final UriInfo uriInfo; |
|
12 |
|
|
13 |
public ContentTypeHelper(HttpRequest request, Request restRequest, UriInfo uriInfo) { |
|
14 |
this.request = request; |
|
15 |
this.restRequest = restRequest; |
|
16 |
this.uriInfo = uriInfo; |
|
17 |
} |
|
18 |
|
|
19 |
public MediaType selectResponseType() { |
|
20 |
String format = uriInfo.getQueryParameters().getFirst(CASLoginProtocol.FORMAT_PARAM); |
|
21 |
if (format != null && !format.isEmpty()) { |
5ba0b0
|
22 |
//if parameter is set, it overrides all header values (see spec section 2.5.1) |
MP |
23 |
request.getMutableHeaders().putSingle(HttpHeaders.ACCEPT, "application/" + format.toLowerCase()); |
513246
|
24 |
} |
MP |
25 |
Variant variant = restRequest.selectVariant(Variant.mediaTypes(MediaType.APPLICATION_XML_TYPE, MediaType.APPLICATION_JSON_TYPE).build()); |
|
26 |
return variant == null ? MediaType.APPLICATION_XML_TYPE : variant.getMediaType(); |
|
27 |
} |
|
28 |
} |