[ofbiz-framework] branch trunk updated: Fixed: The createTaskContent request does not work

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

[ofbiz-framework] branch trunk updated: Fixed: The createTaskContent request does not work

jleroux@apache.org
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new f4acda5  Fixed: The createTaskContent request does not work
f4acda5 is described below

commit f4acda5ade516410fec18cdde20c482c3ddeae11
Author: Jacques Le Roux <[hidden email]>
AuthorDate: Fri Mar 27 10:55:59 2020 +0100

    Fixed: The createTaskContent request does not work
   
    (OFBIZ-11246)
   
    It seems that same request can not be parsed multiple times if it has multi part
    object in it as the parse method remove it after that.
   
    Found one stackoverflow link around the same:
   
    https://stackoverflow.com/questions/13881272/
    servletfileuploadparserequestrequest-returns-an-empty-list
   
    I believe that all places/uploads using this workflow should resulting the same
    issue.
   
    One possible solution I could think of without going with new approach is to set
    list of file Items into the request attribute and use it if parse method remove
    it and unable to retrieve on 2nd call.
   
    Thanks: Ankush Upadhyay for the analysis and initial patch. I only slightly
    modified it.
---
 .../src/main/java/org/apache/ofbiz/content/layout/LayoutWorker.java   | 4 ++++
 framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/layout/LayoutWorker.java b/applications/content/src/main/java/org/apache/ofbiz/content/layout/LayoutWorker.java
index 07e3e79..dad4217 100644
--- a/applications/content/src/main/java/org/apache/ofbiz/content/layout/LayoutWorker.java
+++ b/applications/content/src/main/java/org/apache/ofbiz/content/layout/LayoutWorker.java
@@ -35,6 +35,7 @@ import org.apache.ofbiz.base.util.UtilGenerics;
 import org.apache.ofbiz.base.util.UtilHttp;
 import org.apache.ofbiz.base.util.UtilMisc;
 import org.apache.ofbiz.base.util.UtilProperties;
+import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.service.ServiceUtil;
 
 /**
@@ -66,6 +67,9 @@ public final class LayoutWorker {
             return ServiceUtil.returnError(e4.getMessage());
         }
 
+        if(lst.size() == 0 && UtilValidate.isNotEmpty(request.getAttribute("fileItems"))) {
+            lst = UtilGenerics.cast(request.getAttribute("fileItems"));
+        }
         if (lst.size() == 0) {
             String errMsg = UtilProperties.getMessage(err_resource,
                     "layoutEvents.no_files_uploaded", locale);
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 169ed10..5452a19 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
@@ -66,6 +66,7 @@ import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.FileUploadException;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.commons.fileupload.servlet.ServletRequestContext;
 import org.apache.commons.lang.RandomStringUtils;
 import org.apache.http.conn.ssl.NoopHostnameVerifier;
 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@@ -225,6 +226,7 @@ public final class UtilHttp {
                 Debug.logError("File upload error" + e, module);
             }
             if (uploadedItems != null) {
+                request.setAttribute("fileItems", uploadedItems);
                 for (FileItem item: uploadedItems) {
                     String fieldName = item.getFieldName();
                     //byte[] itemBytes = item.get();