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

This commit is contained in:
Lukasz Lenart
2016-10-06 20:51:19 +02:00
parent 67541e07a7
commit bb403720ac
5 changed files with 78 additions and 9 deletions
@@ -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;
}
@@ -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);
}
@@ -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);
}
@@ -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) {
@@ -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);