]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-23: Improve detection of json content type.
authorRay Lee <rhlee@berkeley.edu>
Thu, 11 Aug 2016 07:20:34 +0000 (00:20 -0700)
committerRay Lee <rhlee@berkeley.edu>
Thu, 11 Aug 2016 07:20:34 +0000 (00:20 -0700)
services/common/src/main/java/org/collectionspace/services/common/xmljson/RequestUtils.java
services/common/src/test/java/org/collectionspace/services/common/xmljson/test/RequestUtilsTest.java

index 790297c1c677f59fca918e921a81b748205b386e..e563eee7a4498a933b34f0f1e5dc40216d04317b 100644 (file)
@@ -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));
     }
     
     /**
index dfed6c5933f90e6180d6e03db6957a733249bac9..946d32fad5bba4e100e133022f9b5552349121cc 100644 (file)
@@ -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