mirror of
https://github.com/apache/struts.git
synced 2026-08-06 23:27:07 +00:00
WW-4963 Implements new ParametersAware interface
that uses withParameters instead of setHttpParameters and cleans up logic a bit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.action;
|
||||
|
||||
import org.apache.struts2.dispatcher.HttpParameters;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* One common use for this is to have the action propagate parameters to internally instantiated data
|
||||
* objects.
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
public interface ParametersAware {
|
||||
|
||||
/**
|
||||
* Sets the HTTP parameters in the implementing class.
|
||||
*
|
||||
* @param parameters an instance of {@link HttpParameters}.
|
||||
*/
|
||||
void withParameters(HttpParameters parameters);
|
||||
}
|
||||
@@ -31,13 +31,19 @@ import org.apache.struts2.dispatcher.HttpParameters;
|
||||
* One common use for this is to have the action propagate parameters to internally instantiated data
|
||||
* objects.
|
||||
* </p>
|
||||
*
|
||||
* @deprecated please use {@link org.apache.struts2.action.ParametersAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface HttpParametersAware {
|
||||
|
||||
/**
|
||||
* Sets the HTTP parameters in the implementing class.
|
||||
*
|
||||
* @param parameters an instance of {@link HttpParameters}.
|
||||
*
|
||||
* @deprecated please use {@link org.apache.struts2.action.ParametersAware#withParameters(HttpParameters)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
void setParameters(HttpParameters parameters);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.Map;
|
||||
* the map is <tt>java.lang.String[]</tt>.
|
||||
* </p>
|
||||
*
|
||||
* @deprecated please use {@link HttpParametersAware} instead
|
||||
* @deprecated please use {@link org.apache.struts2.action.ParametersAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ParameterAware {
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.apache.struts2.interceptor;
|
||||
|
||||
import org.apache.struts2.dispatcher.HttpParameters;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -28,13 +30,17 @@ import java.util.Map;
|
||||
* <p>
|
||||
* This interface is only relevant if the Action is used in a servlet environment.
|
||||
* </p>
|
||||
* @deprecated please use {@link org.apache.struts2.action.ParametersAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface RequestAware {
|
||||
|
||||
/**
|
||||
* Sets the Map of request attributes in the implementing class.
|
||||
*
|
||||
* @param request a Map of HTTP request attribute name/value pairs.
|
||||
* @deprecated please use {@link org.apache.struts2.action.ParametersAware#withParameters(HttpParameters)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setRequest(Map<String,Object> request);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.action.ParametersAware;
|
||||
import org.apache.struts2.interceptor.servlet.ServletPrincipalProxy;
|
||||
import org.apache.struts2.util.ServletContextAware;
|
||||
|
||||
@@ -103,7 +104,7 @@ import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
||||
* @see ServletRequestAware
|
||||
* @see ServletResponseAware
|
||||
* @see ParameterAware
|
||||
* @see HttpParametersAware
|
||||
* @see ParametersAware
|
||||
* @see SessionAware
|
||||
* @see ApplicationAware
|
||||
* @see PrincipalAware
|
||||
@@ -151,6 +152,10 @@ public class ServletConfigInterceptor extends AbstractInterceptor implements Str
|
||||
((HttpParametersAware) action).setParameters(context.getParameters());
|
||||
}
|
||||
|
||||
if (action instanceof ParametersAware) {
|
||||
((ParametersAware) action).withParameters(context.getParameters());
|
||||
}
|
||||
|
||||
if (action instanceof ApplicationAware) {
|
||||
((ApplicationAware) action).setApplication(context.getApplication());
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.action.ParametersAware;
|
||||
import org.apache.struts2.dispatcher.HttpParameters;
|
||||
import org.apache.struts2.interceptor.servlet.ServletPrincipalProxy;
|
||||
import org.apache.struts2.util.ServletContextAware;
|
||||
@@ -145,6 +146,22 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testActionParametersAware() throws Exception {
|
||||
ParametersAware mock = createMock(ParametersAware.class);
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
|
||||
HttpParameters params = HttpParameters.create().build();
|
||||
mai.getInvocationContext().setParameters(params);
|
||||
|
||||
mock.withParameters(params);
|
||||
expectLastCall().times(1);
|
||||
|
||||
replay(mock);
|
||||
interceptor.intercept(mai);
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testSessionAware() throws Exception {
|
||||
SessionAware mock = (SessionAware) createMock(SessionAware.class);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user