Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GRANDGERARD Gilles
keycloak-protocol-cas
Commits
de7d2545
Commit
de7d2545
authored
Feb 14, 2017
by
Matthias Piepkorn
Committed by
matthiasp
Feb 14, 2017
Browse files
Do not fail on invalid Accept header
parent
4e2fd6ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/keycloak/protocol/cas/utils/ContentTypeHelper.java
View file @
de7d2545
package
org.keycloak.protocol.cas.utils
;
import
org.jboss.resteasy.spi.BadRequestException
;
import
org.jboss.resteasy.spi.HttpRequest
;
import
org.keycloak.protocol.cas.CASLoginProtocol
;
...
...
@@ -22,7 +23,12 @@ public class ContentTypeHelper {
//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
;
}
}
}
src/test/java/org/keycloak/protocol/cas/ContentTypeHelperTest.java
View file @
de7d2545
...
...
@@ -29,6 +29,7 @@ public class ContentTypeHelperTest {
assertEquals
(
MediaType
.
APPLICATION_XML_TYPE
,
get
(
"http://example.com/?format=xml"
,
MediaType
.
APPLICATION_JSON
).
selectResponseType
());
assertEquals
(
MediaType
.
APPLICATION_XML_TYPE
,
get
(
"http://example.com/"
,
MediaType
.
TEXT_PLAIN
).
selectResponseType
());
assertEquals
(
MediaType
.
APPLICATION_XML_TYPE
,
get
(
"http://example.com/"
,
"text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
).
selectResponseType
());
}
private
ContentTypeHelper
get
(
String
uri
,
String
acceptHeader
)
throws
Exception
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment