svn commit: r1858035 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1858035 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java

Swapnil M Mane
Author: swapnilmmane
Date: Wed Apr 24 09:57:08 2019
New Revision: 1858035

URL: http://svn.apache.org/viewvc?rev=1858035&view=rev
Log:
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.<FileItem>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.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java?rev=1858035&r1=1858034&r2=1858035&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java Wed Apr 24 09:57:08 2019
@@ -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) {