Repository: struts
Updated Branches:
  refs/heads/master 7cd3d30fd -> 1bd9bde61


WW-4572 Fixes issue with file upload


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/69da41eb
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/69da41eb
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/69da41eb

Branch: refs/heads/master
Commit: 69da41eb793ad31a6c076e109dbfa6dd1b5a1cd5
Parents: 7cd3d30
Author: Lukasz Lenart <lukaszlen...@apache.org>
Authored: Fri Oct 7 10:05:38 2016 +0200
Committer: Lukasz Lenart <lukaszlen...@apache.org>
Committed: Fri Oct 7 10:05:38 2016 +0200

----------------------------------------------------------------------
 .../xwork2/interceptor/ParametersInterceptor.java        |  4 +++-
 .../org/apache/struts2/dispatcher/HttpParameters.java    |  9 +++++----
 .../java/org/apache/struts2/dispatcher/Parameter.java    |  8 ++++++++
 .../apache/struts2/interceptor/CheckboxInterceptor.java  |  6 +++---
 .../struts2/interceptor/DateTextFieldInterceptor.java    |  6 +++---
 .../struts2/interceptor/FileUploadInterceptor.java       | 11 ++++++-----
 .../struts2/interceptor/MultiselectInterceptor.java      |  7 ++++---
 .../src/main/java/org/apache/struts2/JSPRuntime.java     | 10 +++++++---
 8 files changed, 39 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/69da41eb/core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java
 
b/core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java
index 07bb9df..4c94b6b 100644
--- 
a/core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java
+++ 
b/core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java
@@ -203,7 +203,9 @@ public class ParametersInterceptor extends 
MethodFilterInterceptor {
             String name = entry.getKey();
             Parameter value = entry.getValue();
             try {
-                if (value.isMultiple()) {
+                if (value instanceof Parameter.File) {
+                    newStack.setParameter(name, value.getObject());
+                } else  if (value.isMultiple()) {
                     newStack.setParameter(name, value.getMultipleValues());
                 } else {
                     newStack.setParameter(name, value.getValue());

http://git-wip-us.apache.org/repos/asf/struts/blob/69da41eb/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java 
b/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java
index a85c9c7..5c6360e 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java
@@ -53,10 +53,6 @@ public class HttpParameters implements Cloneable {
         return parameters.containsKey(name);
     }
 
-    public HttpParameters clone(Map<String, ?> newParams) {
-        return 
HttpParameters.createEmpty().withParent(this).withExtraParams(newParams).build();
-    }
-
     public Map<String, String[]> toMap() {
         Map<String, String[]> result = new HashMap<>(parameters.size());
         for (Map.Entry<String, Parameter> entry : parameters.entrySet()) {
@@ -65,6 +61,11 @@ public class HttpParameters implements Cloneable {
         return result;
     }
 
+    public HttpParameters appendAll(Map<String, Parameter> newParams) {
+        parameters.putAll(newParams);
+        return this;
+    }
+
     public static class Builder {
         private Map<String, Object> requestParameterMap;
         private HttpParameters parent;

http://git-wip-us.apache.org/repos/asf/struts/blob/69da41eb/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java 
b/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java
index 7a08895..97f7946 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/Parameter.java
@@ -3,6 +3,8 @@ package org.apache.struts2.dispatcher;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
+import java.io.File;
+
 public interface Parameter {
 
     String getName();
@@ -82,6 +84,12 @@ public interface Parameter {
         }
     }
 
+    class File extends Request {
+        public File(String name, Object value) {
+            super(name, value);
+        }
+    }
+
     class EmptyHttpParameter implements Parameter {
 
         private String name;

http://git-wip-us.apache.org/repos/asf/struts/blob/69da41eb/core/src/main/java/org/apache/struts2/interceptor/CheckboxInterceptor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/struts2/interceptor/CheckboxInterceptor.java 
b/core/src/main/java/org/apache/struts2/interceptor/CheckboxInterceptor.java
index 2bb49aa..369f81e 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/CheckboxInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/CheckboxInterceptor.java
@@ -61,7 +61,7 @@ public class CheckboxInterceptor extends AbstractInterceptor {
 
     public String intercept(ActionInvocation ai) throws Exception {
         HttpParameters parameters = ai.getInvocationContext().getParameters();
-        Map<String, String[]> extraParams = new HashMap<>();
+        Map<String, Parameter> extraParams = new HashMap<>();
 
         for (String name : parameters.getNames()) {
             if (name.startsWith("__checkbox_")) {
@@ -77,13 +77,13 @@ public class CheckboxInterceptor extends 
AbstractInterceptor {
                 // is this checkbox checked/submitted?
                 if (!parameters.contains(checkboxName)) {
                     // if not, let's be sure to default the value to false
-                    extraParams.put(checkboxName, new String[]{ uncheckedValue 
});
+                    extraParams.put(checkboxName, new 
Parameter.Request(checkboxName, uncheckedValue));
                 }
             }
         }
 
 
-        ai.getInvocationContext().setParameters(parameters.clone(extraParams));
+        ai.getInvocationContext().getParameters().appendAll(extraParams);
 
         return ai.invoke();
     }

http://git-wip-us.apache.org/repos/asf/struts/blob/69da41eb/core/src/main/java/org/apache/struts2/interceptor/DateTextFieldInterceptor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/struts2/interceptor/DateTextFieldInterceptor.java
 
b/core/src/main/java/org/apache/struts2/interceptor/DateTextFieldInterceptor.java
index c71cf4d..acadde2 100644
--- 
a/core/src/main/java/org/apache/struts2/interceptor/DateTextFieldInterceptor.java
+++ 
b/core/src/main/java/org/apache/struts2/interceptor/DateTextFieldInterceptor.java
@@ -96,7 +96,7 @@ public class DateTextFieldInterceptor implements Interceptor {
         }
 
         // Create all the date objects
-        Map<String, Object> newParams = new HashMap<>();
+        Map<String, Parameter> newParams = new HashMap<>();
         Set<Entry<String, Map<String, String>>> dateEntries = dates.entrySet();
         for (Entry<String, Map<String, String>> dateEntry : dateEntries) {
                Set<Entry<String, String>> dateFormatEntries = 
dateEntry.getValue().entrySet();
@@ -110,13 +110,13 @@ public class DateTextFieldInterceptor implements 
Interceptor {
                SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
                formatter.setLenient(false);
                 Date value = formatter.parse(dateValue);
-                newParams.put(dateEntry.getKey(), value);
+                newParams.put(dateEntry.getKey(), new 
Parameter.Request(dateEntry.getKey(), value));
             } catch (ParseException e) {
                 LOG.warn("Cannot parse the parameter '{}' with format '{}' and 
with value '{}'", dateEntry.getKey(), dateFormat, dateValue);
             }
         }
 
-        ai.getInvocationContext().setParameters(parameters.clone(newParams));
+        ai.getInvocationContext().getParameters().appendAll(newParams);
 
         return ai.invoke();
     }

http://git-wip-us.apache.org/repos/asf/struts/blob/69da41eb/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java 
b/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
index 0ceacc4..680f827 100644
--- 
a/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
+++ 
b/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
@@ -30,6 +30,7 @@ import com.opensymphony.xwork2.util.TextParseUtil;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.dispatcher.Parameter;
 import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
 import org.apache.struts2.util.ContentTypeMatcher;
 
@@ -294,11 +295,11 @@ public class FileUploadInterceptor extends 
AbstractInterceptor {
                         }
 
                         if (!acceptedFiles.isEmpty()) {
-                            Map<String, Object> newParams = new HashMap<>();
-                            newParams.put(inputName, acceptedFiles.toArray(new 
File[acceptedFiles.size()]));
-                            newParams.put(contentTypeName, 
acceptedContentTypes.toArray(new String[acceptedContentTypes.size()]));
-                            newParams.put(fileNameName, 
acceptedFileNames.toArray(new String[acceptedFileNames.size()]));
-                            
ac.setParameters(ac.getParameters().clone(newParams));
+                            Map<String, Parameter> newParams = new HashMap<>();
+                            newParams.put(inputName, new 
Parameter.File(inputName, acceptedFiles.toArray(new 
File[acceptedFiles.size()])));
+                            newParams.put(contentTypeName, new 
Parameter.File(contentTypeName, acceptedContentTypes.toArray(new 
String[acceptedContentTypes.size()])));
+                            newParams.put(fileNameName, new 
Parameter.File(fileNameName, acceptedFileNames.toArray(new 
String[acceptedFileNames.size()])));
+                            ac.getParameters().appendAll(newParams);
                         }
                     }
                 } else {

http://git-wip-us.apache.org/repos/asf/struts/blob/69da41eb/core/src/main/java/org/apache/struts2/interceptor/MultiselectInterceptor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/struts2/interceptor/MultiselectInterceptor.java 
b/core/src/main/java/org/apache/struts2/interceptor/MultiselectInterceptor.java
index 337fd0c..a62de22 100644
--- 
a/core/src/main/java/org/apache/struts2/interceptor/MultiselectInterceptor.java
+++ 
b/core/src/main/java/org/apache/struts2/interceptor/MultiselectInterceptor.java
@@ -23,6 +23,7 @@ package org.apache.struts2.interceptor;
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
 import org.apache.struts2.dispatcher.HttpParameters;
+import org.apache.struts2.dispatcher.Parameter;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -47,7 +48,7 @@ public class MultiselectInterceptor extends 
AbstractInterceptor {
      */
     public String intercept(ActionInvocation ai) throws Exception {
         HttpParameters parameters = ai.getInvocationContext().getParameters();
-        Map<String, Object> newParams = new HashMap<>();
+        Map<String, Parameter> newParams = new HashMap<>();
 
         for (String name : parameters.getNames()) {
             if (name.startsWith("__multiselect_")) {
@@ -56,14 +57,14 @@ public class MultiselectInterceptor extends 
AbstractInterceptor {
                 // is this multi-select box submitted?
                 if (!parameters.contains(key)) {
                     // if not, let's be sure to default the value to an empty 
string array
-                    newParams.put(key, new String[0]);
+                    newParams.put(key, new Parameter.Request(key, new 
String[0]));
                 }
 
                 parameters = parameters.remove(name);
             }
         }
 
-        ai.getInvocationContext().setParameters(parameters.clone(newParams));
+        ai.getInvocationContext().getParameters().appendAll(newParams);
 
         return ai.invoke();
     }

http://git-wip-us.apache.org/repos/asf/struts/blob/69da41eb/plugins/embeddedjsp/src/main/java/org/apache/struts2/JSPRuntime.java
----------------------------------------------------------------------
diff --git 
a/plugins/embeddedjsp/src/main/java/org/apache/struts2/JSPRuntime.java 
b/plugins/embeddedjsp/src/main/java/org/apache/struts2/JSPRuntime.java
index bd9b4a8..1aa719a 100644
--- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/JSPRuntime.java
+++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/JSPRuntime.java
@@ -22,12 +22,14 @@ package org.apache.struts2;
 
 import com.opensymphony.xwork2.ActionContext;
 import org.apache.struts2.dispatcher.HttpParameters;
+import org.apache.struts2.dispatcher.Parameter;
 import org.apache.struts2.views.util.UrlHelper;
 
 import javax.servlet.Servlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.HttpJspPage;
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -54,12 +56,14 @@ public abstract class JSPRuntime {
         int i = location.indexOf("?");
         if (i > 0) {
             //extract params from the url and add them to the request
-            HttpParameters parameters = 
ActionContext.getContext().getParameters();
             String query = location.substring(i + 1);
             Map<String, Object> queryParams = 
urlHelper.parseQueryString(query, true);
             if (queryParams != null && !queryParams.isEmpty()) {
-                parameters = parameters.clone(queryParams);
-                ActionContext.getContext().setParameters(parameters);
+                Map<String, Parameter> newParams = new HashMap<>();
+                for (Map.Entry<String, Object> entry : queryParams.entrySet()) 
{
+                    newParams.put(entry.getKey(), new 
Parameter.Request(entry.getKey(), entry.getValue()));
+                }
+                
ActionContext.getContext().getParameters().appendAll(newParams);
             }
             location = location.substring(0, i);
         }

Reply via email to