From 4773de94c46981b3b0856694a78408f1540995ec Mon Sep 17 00:00:00 2001
From: Manfred Riem
Date: Wed, 8 Jan 2025 16:30:04 -0600
Subject: [PATCH] Fixes #4470 - Add logging to FileUploadManager for debugging
purposes
---
.../FileUploadMultiPartManager.java | 30 ++++++++++++++-----
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/extension/fileupload/src/main/java/cloud/piranha/extension/fileupload/FileUploadMultiPartManager.java b/extension/fileupload/src/main/java/cloud/piranha/extension/fileupload/FileUploadMultiPartManager.java
index fee5dc2b9..522b7ecc2 100644
--- a/extension/fileupload/src/main/java/cloud/piranha/extension/fileupload/FileUploadMultiPartManager.java
+++ b/extension/fileupload/src/main/java/cloud/piranha/extension/fileupload/FileUploadMultiPartManager.java
@@ -50,10 +50,10 @@
* The ApacheMultiPartManager.
*
*
- The FileUploadMultiPartManager implements the MultiPartManager API that delivers
- file upload functionality to a web application by delegating to Apache
- Commons File Upload.
-
+ * The FileUploadMultiPartManager implements the MultiPartManager API that
+ * delivers file upload functionality to a web application by delegating to
+ * Apache Commons File Upload.
+ *
*
* @author Manfred Riem (mriem@manorrock.com)
*/
@@ -73,9 +73,14 @@ public FileUploadMultiPartManager() {
@SuppressWarnings("unchecked")
@Override
public Collection getParts(WebApplication webApplication, WebApplicationRequest request) throws ServletException {
- LOGGER.log(TRACE, "Getting parts for request: {0}", request);
-
+ if (LOGGER.isLoggable(TRACE)) {
+ LOGGER.log(TRACE, "Getting parts for request: {0}", request);
+ }
+
if (!JakartaServletFileUpload.isMultipartContent(request)) {
+ if (LOGGER.isLoggable(TRACE)) {
+ LOGGER.log(TRACE, "Request: {0} is not a multipart/form-date request");
+ }
throw new ServletException("Not a multipart/form-data request");
}
@@ -98,15 +103,26 @@ public Collection getParts(WebApplication webApplication, WebApplicationRe
@Override
public Part getPart(WebApplication webApplication, WebApplicationRequest request, String name) throws ServletException {
- LOGGER.log(TRACE, "Getting part: {0} for request: {1}", name, request);
+ if (LOGGER.isLoggable(TRACE)) {
+ LOGGER.log(TRACE, "Getting part: {0} for request: {1}", name, request);
+ }
if (!JakartaServletFileUpload.isMultipartContent(request)) {
+ if (LOGGER.isLoggable(TRACE)) {
+ LOGGER.log(TRACE, "Request: {0} is not a multipart/form-date request");
+ }
throw new ServletException("Not a multipart/form-data request");
}
for (Part part : getParts(webApplication, request)) {
if (part.getName().equals(name)) {
+ if (LOGGER.isLoggable(TRACE)) {
+ LOGGER.log(TRACE, "Found part: {0}", part.getName());
+ }
return part;
}
}
+ if (LOGGER.isLoggable(TRACE)) {
+ LOGGER.log(TRACE, "Unable to find part: {0}", name);
+ }
return null;
}