Skip to content

Commit

Permalink
WW-4572 Reverts ParameterAware interface to its previous version and …
Browse files Browse the repository at this point in the history
…introduces new one
  • Loading branch information
lukaszlenart committed Oct 6, 2016
1 parent 67541e0 commit bb40372
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public HttpParameters clone(Map<String, ?> newParams) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,13 +38,16 @@
* 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 {

/**
* Sets the map of input parameters in the implementing class.
*
* @param parameters a Map of parameters (name/value Strings).
*/
public void setParameters(HttpParameters parameters);
public void setParameters(Map<String, String[]> parameters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
*
* <li>{@link ParameterAware}</li>
*
* <li>{@link HttpParametersAware}</li>
*
* <li>{@link RequestAware}</li>
*
* <li>{@link SessionAware}</li>
Expand Down Expand Up @@ -135,7 +137,11 @@ public String intercept(ActionInvocation invocation) throws Exception {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,23 @@ public void testServletResponseAware() throws Exception {
}

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);

Expand Down

0 comments on commit bb40372

Please sign in to comment.