mirror of
https://github.com/apache/struts.git
synced 2026-08-07 07:37:20 +00:00
WW-4684 Uses charset and adds some logging
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user