From f459981022677b58e65191c5256a16a1cd1114d3 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Wed, 6 Mar 2024 08:09:09 +0100 Subject: [PATCH 1/3] WW-5401 Improves logging around wrapping request and detecting multipart request --- .../org/apache/struts2/dispatcher/Dispatcher.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java index 70b85e1b79..fadbc1bd92 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java @@ -986,10 +986,12 @@ private void applyEncoding(HttpServletResponse response, String encoding) { public HttpServletRequest wrapRequest(HttpServletRequest request) throws IOException { // don't wrap more than once if (request instanceof StrutsRequestWrapper) { + LOG.debug("Request already wrapped with {}", StrutsRequestWrapper.class.getSimpleName()); return request; } if (isMultipartSupportEnabled(request) && isMultipartRequest(request)) { + LOG.debug("Wrapping multipart request with: {}", MultiPartRequestWrapper.class.getSimpleName()); request = new MultiPartRequestWrapper( getMultiPartRequest(), request, @@ -998,6 +1000,7 @@ public HttpServletRequest wrapRequest(HttpServletRequest request) throws IOExcep disableRequestAttributeValueStackLookup ); } else { + LOG.debug("Wrapping request using: {}", StrutsRequestWrapper.class.getSimpleName()); request = new StrutsRequestWrapper(request, disableRequestAttributeValueStackLookup); } @@ -1012,6 +1015,7 @@ public HttpServletRequest wrapRequest(HttpServletRequest request) throws IOExcep * @since 2.5.11 */ protected boolean isMultipartSupportEnabled(HttpServletRequest request) { + LOG.debug("Support for multipart request is enabled: {}", multipartSupportEnabled); return multipartSupportEnabled; } @@ -1026,9 +1030,12 @@ protected boolean isMultipartRequest(HttpServletRequest request) { String httpMethod = request.getMethod(); String contentType = request.getContentType(); - return REQUEST_POST_METHOD.equalsIgnoreCase(httpMethod) && - contentType != null && - multipartValidationPattern.matcher(contentType.toLowerCase(Locale.ENGLISH)).matches(); + boolean isPostRequest = REQUEST_POST_METHOD.equalsIgnoreCase(httpMethod); + boolean isProperContentType = contentType != null && multipartValidationPattern.matcher(contentType.toLowerCase(Locale.ENGLISH)).matches(); + + LOG.debug("Validating if this is proper Multipart request. Request is POST: {} and ContentType matches pattern ({}): {}", + isPostRequest, multipartValidationPattern, isProperContentType); + return isPostRequest && isProperContentType; } /** From c3201812754a1426c43ef2b55ff142dc954939c7 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Wed, 6 Mar 2024 14:35:53 +0100 Subject: [PATCH 2/3] WW-5401 Fixes typo Co-authored-by: Sebastian Peters --- .../src/main/java/org/apache/struts2/dispatcher/Dispatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java index fadbc1bd92..b879dad5a6 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java @@ -1033,7 +1033,7 @@ protected boolean isMultipartRequest(HttpServletRequest request) { boolean isPostRequest = REQUEST_POST_METHOD.equalsIgnoreCase(httpMethod); boolean isProperContentType = contentType != null && multipartValidationPattern.matcher(contentType.toLowerCase(Locale.ENGLISH)).matches(); - LOG.debug("Validating if this is proper Multipart request. Request is POST: {} and ContentType matches pattern ({}): {}", + LOG.debug("Validating if this is a proper Multipart request. Request is POST: {} and ContentType matches pattern ({}): {}", isPostRequest, multipartValidationPattern, isProperContentType); return isPostRequest && isProperContentType; } From ac6c88ad4b63cc874000c711afeb9a638ab03f81 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Wed, 6 Mar 2024 14:36:11 +0100 Subject: [PATCH 3/3] WW-5401 Uses same message approach Co-authored-by: Sebastian Peters --- .../src/main/java/org/apache/struts2/dispatcher/Dispatcher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java index b879dad5a6..5bad0b4feb 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java @@ -986,7 +986,7 @@ private void applyEncoding(HttpServletResponse response, String encoding) { public HttpServletRequest wrapRequest(HttpServletRequest request) throws IOException { // don't wrap more than once if (request instanceof StrutsRequestWrapper) { - LOG.debug("Request already wrapped with {}", StrutsRequestWrapper.class.getSimpleName()); + LOG.debug("Request already wrapped with: {}", StrutsRequestWrapper.class.getSimpleName()); return request; }