[ofbiz-framework] branch release18.12 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 release18.12 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 release18.12
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/release18.12 by this push:
     new 8f51785  Fixed: The createTaskContent request does not work
8f51785 is described below

commit 8f51785dab6b6a6bbed8e64219f7f5c64fb36c64
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 c450d1c..e842c21 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 7c044f7..260f88d 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
@@ -56,6 +56,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;
@@ -228,6 +229,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();