WW-4684 Uses charset and adds some logging

This commit is contained in:
Lukasz Lenart
2016-09-05 12:14:12 +02:00
parent 547718fcc6
commit 175c852eef
2 changed files with 10 additions and 4 deletions
@@ -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;
}
@@ -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);