From 12943e0abb7f1306af9bbdbfdfe37cf3142f0fa7 Mon Sep 17 00:00:00 2001 From: Swapnil Mane Date: Wed, 24 Apr 2019 10:06:21 +0000 Subject: [PATCH] Applied fix from trunk for revision: 1858035 === Fixed: Parameters are not available to the next response type when form of enctype=multipart/form-data type is submitted (OFBIZ-10833) Reason: The UtilHttp.getMultiPartParameterMap method is used to get the parameters in case of multipart/form-data type. The getMultiPartParameterMap parse the request to get the parameters. {code} uploadedItems = UtilGenerics.checkList(upload.parseRequest(request)); {code} As per the Apache commons-fileupload guideline, a request can only be parsed once [1]. So, for the next response, again the same getMultiPartParameterMap method is executed (with the same request object), and no parameters are found, since, the request is already parsed. Also, have a look at the StackOverflow question [2], it also contains related information. Fix for the issue: Set the consumed parameters (except uploaded file(s)) in the request attribute so that it will be available to the next response. The uploaded file(s) are not set in request attribute again to avoid unnecessary memory consumption, also it makes no sense to traverse the uploaded file in the request. [1] http://commons.apache.org/proper/commons-fileupload/faq.html#empty-parse [2] https://stackoverflow.com/questions/13881272/servletfileuploadparserequestrequest-returns-an-empty-list Thanks: Ingo Wolfmayr for reporting issue and Jacques Le Roux for review. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/branches/release17.12@1858037 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/org/apache/ofbiz/base/util/UtilHttp.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java index f55a57347a..40aeed5b6d 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java @@ -257,6 +257,10 @@ public final class UtilHttp { multiPartMap.put(fieldName, item.getString()); } } + /* OFBIZ-10833 - Set the consumed parameters in request attributes for enctype="multipart/form-data" type form + * so that it will be available for the next response. Please refer Jira for more details. + */ + request.setAttribute(fieldName, multiPartMap.get(fieldName)); } else { String fileName = item.getName(); if (fileName.indexOf('\\') > -1 || fileName.indexOf('/') > -1) {