Adjusts usage of parameters

This commit is contained in:
Lukasz Lenart
2015-11-25 19:03:30 +01:00
parent ce8ac8e3ce
commit 60b9d85d44
8 changed files with 27 additions and 22 deletions
@@ -34,6 +34,6 @@ public class ExampleAction extends ActionSupport {
}
public Map getRenderParameters() {
return ActionContext.getContext().getParameters();
return ActionContext.getContext().getParameters().toMap();
}
}
@@ -70,7 +70,8 @@ public class DateTextFieldInterceptor implements Interceptor {
DateWord[] dateWords = DateWord.getAll();
// Get all the values of date type
for (String name : parameters.getNames()) {
Set<String> names = parameters.getNames();
for (String name : names) {
for (DateWord dateWord : dateWords) {
String dateKey = "__" + dateWord.getDescription() + "_";
@@ -95,7 +96,7 @@ public class DateTextFieldInterceptor implements Interceptor {
}
// Create all the date objects
Map<String, String> newParams = new HashMap<>();
Map<String, Object> 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();
@@ -109,7 +110,7 @@ public class DateTextFieldInterceptor implements Interceptor {
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
formatter.setLenient(false);
Date value = formatter.parse(dateValue);
newParams.put(dateEntry.getKey(), formatter.format(value));
newParams.put(dateEntry.getKey(), value);
} catch (ParseException e) {
LOG.warn("Cannot parse the parameter '{}' with format '{}' and with value '{}'", dateEntry.getKey(), dateFormat, dateValue);
}
@@ -27,6 +27,7 @@ import com.opensymphony.xwork2.interceptor.ValidationAware;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.result.ServletRedirectResult;
@@ -315,13 +316,9 @@ public class MessageStoreInterceptor extends AbstractInterceptor {
protected String getRequestOperationMode(ActionInvocation invocation) {
String reqOperationMode = NONE;
if (allowRequestParameterSwitch) {
Map reqParams = (Map) invocation.getInvocationContext().get(ActionContext.PARAMETERS);
boolean containsParameter = reqParams.containsKey(requestParameterSwitch);
if (containsParameter) {
String[] reqParamsArr = (String[]) reqParams.get(requestParameterSwitch);
if (reqParamsArr != null && reqParamsArr.length > 0) {
reqOperationMode = reqParamsArr[0];
}
HttpParameters reqParams = invocation.getInvocationContext().getParameters();
if (reqParams.contains(requestParameterSwitch)) {
reqOperationMode = reqParams.get(requestParameterSwitch).getValue();
}
}
return reqOperationMode;
@@ -21,6 +21,8 @@
package org.apache.struts2.interceptor;
import org.apache.struts2.dispatcher.HttpParameters;
import java.util.Map;
@@ -47,5 +49,5 @@ public interface ParameterAware {
*
* @param parameters a Map of parameters (name/value Strings).
*/
public void setParameters(Map<String, String[]> parameters);
public void setParameters(HttpParameters parameters);
}
@@ -135,7 +135,7 @@ public class ServletConfigInterceptor extends AbstractInterceptor implements Str
}
if (action instanceof ParameterAware) {
((ParameterAware) action).setParameters(context.getParameters().getHttpParameters());
((ParameterAware) action).setParameters(context.getParameters());
}
if (action instanceof ApplicationAware) {
@@ -28,8 +28,10 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.ApplicationMap;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.dispatcher.RequestMap;
import org.apache.struts2.dispatcher.SessionMap;
@@ -72,18 +74,16 @@ public class DWRValidator {
ServletContext servletContext = WebContextFactory.get().getServletContext();
HttpServletResponse res = WebContextFactory.get().getHttpServletResponse();
Map<String, Object> requestParams = new HashMap<String, Object>(req.getParameterMap());
HttpParameters.Builder requestParams = HttpParameters.create(req.getParameterMap());
if (params != null) {
requestParams.putAll(params);
} else {
params = requestParams;
requestParams = requestParams.withExtraParams(params);
}
Map requestMap = new RequestMap(req);
Map session = new SessionMap(req);
Map application = new ApplicationMap(servletContext);
Dispatcher du = Dispatcher.getInstance();
HashMap<String, Object> ctx = du.createContextMap(requestMap,
params,
requestParams.build(),
session,
application,
req,
@@ -21,6 +21,7 @@
package org.apache.struts2;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.views.util.UrlHelper;
import javax.servlet.Servlet;
@@ -53,11 +54,13 @@ public abstract class JSPRuntime {
int i = location.indexOf("?");
if (i > 0) {
//extract params from the url and add them to the request
Map<String, Object> parameters = ActionContext.getContext().getParameters();
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.putAll(queryParams);
if (queryParams != null && !queryParams.isEmpty()) {
parameters = parameters.clone(queryParams);
ActionContext.getContext().setParameters(parameters);
}
location = location.substring(0, i);
}
@@ -27,6 +27,7 @@ import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
import com.sun.net.httpserver.HttpsParameters;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.commons.lang3.StringUtils;
@@ -35,6 +36,7 @@ import org.apache.struts2.StrutsException;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.dispatcher.ApplicationMap;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.dispatcher.RequestMap;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
@@ -389,7 +391,7 @@ public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
extraContext.put(StrutsStatics.HTTP_RESPONSE, servletResponse);
extraContext.put(StrutsStatics.SERVLET_CONTEXT, servletContext);
// End dummy servlet objects
extraContext.put(ActionContext.PARAMETERS, parameterMap);
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(parameterMap).build());
extraContext.put(ActionContext.SESSION, sessionMap);
extraContext.put(ActionContext.APPLICATION, applicationMap);