From: Ray Lee Date: Thu, 11 Aug 2016 07:20:34 +0000 (-0700) Subject: DRYD-23: Improve detection of json content type. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=45a00ac25a2e794bc151a299bf36f41c1fd9a2f6;p=tmp%2Fjakarta-migration.git DRYD-23: Improve detection of json content type. --- diff --git a/services/common/src/main/java/org/collectionspace/services/common/xmljson/RequestUtils.java b/services/common/src/main/java/org/collectionspace/services/common/xmljson/RequestUtils.java index 790297c1c..e563eee7a 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/xmljson/RequestUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/xmljson/RequestUtils.java @@ -24,7 +24,13 @@ public class RequestUtils { * @return true if the request contains JSON content, false otherwise */ public static boolean isJsonContent(HttpServletRequest request) { - return StringUtils.equals(request.getContentType(), MediaType.APPLICATION_JSON); + String contentType = request.getContentType(); + + if (contentType == null) { + return false; + } + + return MediaType.APPLICATION_JSON_TYPE.isCompatible(MediaType.valueOf(contentType)); } /** diff --git a/services/common/src/test/java/org/collectionspace/services/common/xmljson/test/RequestUtilsTest.java b/services/common/src/test/java/org/collectionspace/services/common/xmljson/test/RequestUtilsTest.java index dfed6c593..946d32fad 100644 --- a/services/common/src/test/java/org/collectionspace/services/common/xmljson/test/RequestUtilsTest.java +++ b/services/common/src/test/java/org/collectionspace/services/common/xmljson/test/RequestUtilsTest.java @@ -18,6 +18,7 @@ public class RequestUtilsTest { assertFalse(isJsonContent(requestWithContentType(null))); assertFalse(isJsonContent(requestWithContentType("application/xml"))); assertTrue(isJsonContent(requestWithContentType("application/json"))); + assertTrue(isJsonContent(requestWithContentType("application/json;charset=utf-8"))); } @Test