From 45a00ac25a2e794bc151a299bf36f41c1fd9a2f6 Mon Sep 17 00:00:00 2001 From: Ray Lee Date: Thu, 11 Aug 2016 00:20:34 -0700 Subject: [PATCH] DRYD-23: Improve detection of json content type. --- .../services/common/xmljson/RequestUtils.java | 8 +++++++- .../services/common/xmljson/test/RequestUtilsTest.java | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) 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 -- 2.47.3