Repository: struts Updated Branches: refs/heads/master 547718fcc -> 175c852ee
WW-4684 Uses charset and adds some logging Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/175c852e Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/175c852e Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/175c852e Branch: refs/heads/master Commit: 175c852eefbd1353991db6f691264af072ab058c Parents: 547718f Author: Lukasz Lenart <lukaszlen...@apache.org> Authored: Mon Sep 5 12:14:12 2016 +0200 Committer: Lukasz Lenart <lukaszlen...@apache.org> Committed: Mon Sep 5 12:14:12 2016 +0200 ---------------------------------------------------------------------- .../java/org/apache/struts2/json/JSONInterceptor.java | 12 +++++++++--- .../org/apache/struts2/json/JSONInterceptorTest.java | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/175c852e/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java ---------------------------------------------------------------------- diff --git a/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java b/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java index d7836eb..66be65f 100644 --- a/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java +++ b/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java @@ -187,19 +187,25 @@ public class JSONInterceptor extends AbstractInterceptor { protected String readContentType(HttpServletRequest request) { String contentType = request.getHeader("Content-Type"); + LOG.debug("Content Type from request: {}", contentType); + if (contentType != null && contentType.contains(";")) { - contentType = contentType.substring(0, contentType.indexOf(";")); + contentType = contentType.substring(0, contentType.indexOf(";")).trim(); } return contentType; } protected String readContentTypeEncoding(HttpServletRequest request) { String contentTypeEncoding = request.getHeader("Content-Type"); - if (contentTypeEncoding != null && contentTypeEncoding.contains(";encoding=")) { - contentTypeEncoding = contentTypeEncoding.substring(contentTypeEncoding.indexOf(";encoding=") + ";encoding=".length()); + LOG.debug("Content Type encoding from request: {}", contentTypeEncoding); + + if (contentTypeEncoding != null && contentTypeEncoding.contains(";charset=")) { + contentTypeEncoding = contentTypeEncoding.substring(contentTypeEncoding.indexOf(";charset=") + ";charset=".length()).trim(); } else { contentTypeEncoding = defaultEncoding; } + + LOG.debug("Content Type encoding to be used in de-serialisation: {}", contentTypeEncoding); return contentTypeEncoding; } http://git-wip-us.apache.org/repos/asf/struts/blob/175c852e/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java ---------------------------------------------------------------------- diff --git a/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java b/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java index ac4c39b..5ff929c 100644 --- a/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java +++ b/plugins/json/src/test/java/org/apache/struts2/json/JSONInterceptorTest.java @@ -71,7 +71,7 @@ public class JSONInterceptorTest extends StrutsTestCase { private void tryBadJSON(String fileName) throws Exception { // request setRequestContent(fileName); - this.request.addHeader("Content-Type", "application/json;encoding=UTF-8"); + this.request.addHeader("Content-Type", "application/json; charset=UTF-8"); JSONInterceptor interceptor = new JSONInterceptor(); interceptor.setEnableSMD(true);