You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2016/10/06 18:51:34 UTC

struts git commit: WW-4572 Reverts ParameterAware interface to its previous version and introduces new one

Repository: struts
Updated Branches:
  refs/heads/master 67541e07a -> bb403720a


WW-4572 Reverts ParameterAware interface to its previous version and introduces new one


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

Branch: refs/heads/master
Commit: bb403720acb559ba10e372511dc6caaeda724c3b
Parents: 67541e0
Author: Lukasz Lenart <lu...@apache.org>
Authored: Thu Oct 6 20:51:19 2016 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Thu Oct 6 20:51:19 2016 +0200

----------------------------------------------------------------------
 .../struts2/dispatcher/HttpParameters.java      |  6 +--
 .../interceptor/HttpParametersAware.java        | 47 ++++++++++++++++++++
 .../struts2/interceptor/ParameterAware.java     |  8 ++--
 .../interceptor/ServletConfigInterceptor.java   |  8 +++-
 .../ServletConfigInterceptorTest.java           | 18 +++++++-
 5 files changed, 78 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/bb403720/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 4b35705..a85c9c7 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/HttpParameters.java
@@ -57,10 +57,10 @@ public class HttpParameters implements Cloneable {
         return HttpParameters.createEmpty().withParent(this).withExtraParams(newParams).build();
     }
 
-    public Map<String, Object> toMap() {
-        Map<String, Object> result = new HashMap<>(parameters.size());
+    public Map<String, String[]> toMap() {
+        Map<String, String[]> result = new HashMap<>(parameters.size());
         for (Map.Entry<String, Parameter> entry : parameters.entrySet()) {
-            result.put(entry.getKey(), entry.getValue().getObject());
+            result.put(entry.getKey(), entry.getValue().getMultipleValues());
         }
         return result;
     }

http://git-wip-us.apache.org/repos/asf/struts/blob/bb403720/core/src/main/java/org/apache/struts2/interceptor/HttpParametersAware.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/interceptor/HttpParametersAware.java b/core/src/main/java/org/apache/struts2/interceptor/HttpParametersAware.java
new file mode 100644
index 0000000..854f85b
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/interceptor/HttpParametersAware.java
@@ -0,0 +1,47 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.struts2.interceptor;
+
+import org.apache.struts2.dispatcher.HttpParameters;
+
+
+/**
+ * <p>
+ * This interface gives actions an alternative way of receiving input parameters. The parameters will
+ * contain all input parameters as implementation of {@link org.apache.struts2.dispatcher.Parameter}.
+ * Actions that need this should simply implement it.
+ * </p>
+ *
+ * <p>
+ * One common use for this is to have the action propagate parameters to internally instantiated data
+ * objects.
+ * </p>
+ */
+public interface HttpParametersAware {
+
+    /**
+     * Sets the HTTP parameters in the implementing class.
+     *
+     * @param parameters an instance of {@link HttpParameters}.
+     */
+    void setParameters(HttpParameters parameters);
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/bb403720/core/src/main/java/org/apache/struts2/interceptor/ParameterAware.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/interceptor/ParameterAware.java b/core/src/main/java/org/apache/struts2/interceptor/ParameterAware.java
index b37c0c6..755efbb 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/ParameterAware.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/ParameterAware.java
@@ -21,11 +21,8 @@
 
 package org.apache.struts2.interceptor;
 
-import org.apache.struts2.dispatcher.HttpParameters;
-
 import java.util.Map;
 
-
 /**
  * <p>
  * This interface gives actions an alternative way of receiving input parameters. The map will
@@ -41,7 +38,10 @@ import java.util.Map;
  * Note that all parameter values for a given name will be returned, so the type of the objects in
  * the map is <tt>java.lang.String[]</tt>.
  * </p>
+ *
+ * @deprecated please use {@link HttpParametersAware} instead
  */
+@Deprecated
 public interface ParameterAware {
 
     /**
@@ -49,5 +49,5 @@ public interface ParameterAware {
      *
      * @param parameters a Map of parameters (name/value Strings).
      */
-    public void setParameters(HttpParameters parameters);
+    public void setParameters(Map<String, String[]> parameters);
 }

http://git-wip-us.apache.org/repos/asf/struts/blob/bb403720/core/src/main/java/org/apache/struts2/interceptor/ServletConfigInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/interceptor/ServletConfigInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/ServletConfigInterceptor.java
index 4542d43..c92d482 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/ServletConfigInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/ServletConfigInterceptor.java
@@ -57,6 +57,8 @@ import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
  *
  * <li>{@link ParameterAware}</li>
  *
+ * <li>{@link HttpParametersAware}</li>
+ *
  * <li>{@link RequestAware}</li>
  *
  * <li>{@link SessionAware}</li>
@@ -135,7 +137,11 @@ public class ServletConfigInterceptor extends AbstractInterceptor implements Str
         }
 
         if (action instanceof ParameterAware) {
-            ((ParameterAware) action).setParameters(context.getParameters());
+            ((ParameterAware) action).setParameters(context.getParameters().toMap());
+        }
+
+        if (action instanceof HttpParametersAware) {
+            ((HttpParametersAware) action).setParameters(context.getParameters());
         }
 
         if (action instanceof ApplicationAware) {

http://git-wip-us.apache.org/repos/asf/struts/blob/bb403720/core/src/test/java/org/apache/struts2/interceptor/ServletConfigInterceptorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/interceptor/ServletConfigInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/ServletConfigInterceptorTest.java
index 244d5f3..1320b60 100644
--- a/core/src/test/java/org/apache/struts2/interceptor/ServletConfigInterceptorTest.java
+++ b/core/src/test/java/org/apache/struts2/interceptor/ServletConfigInterceptorTest.java
@@ -84,7 +84,23 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
     }
 
     public void testParameterAware() throws Exception {
-        ParameterAware mock = (ParameterAware) createMock(ParameterAware.class);
+        ParameterAware mock = createMock(ParameterAware.class);
+
+        MockActionInvocation mai = createActionInvocation(mock);
+
+        HttpParameters param = HttpParameters.createEmpty().build();
+        mai.getInvocationContext().setParameters(param);
+
+        mock.setParameters(param.toMap());
+        expectLastCall().times(1);
+
+        replay(mock);
+        interceptor.intercept(mai);
+        verify(mock);
+    }
+
+    public void testHttpParametersAware() throws Exception {
+        HttpParametersAware mock = createMock(HttpParametersAware.class);
 
         MockActionInvocation mai = createActionInvocation(mock);