Adjusts interceptor

This commit is contained in:
Lukasz Lenart
2015-10-05 20:56:19 +02:00
parent c14791a2a0
commit 582bb32e4b
3 changed files with 19 additions and 10 deletions
@@ -57,15 +57,23 @@ public class HttpParameters implements Cloneable {
return HttpParameters.createEmpty().withParent(this).withExtraParams(newParams).build();
}
public Map<String, String[]> getHttpParameters() {
Map<String, String[]> result = new HashMap<>(parameters.size());
for (Map.Entry<String, Parameter> entry : parameters.entrySet()) {
result.put(entry.getKey(), entry.getValue().getMultipleValue());
}
return result;
}
public static class Builder {
private Map<String, String[]> requestParameterMap;
private HttpParameters parent;
protected Builder(Map<String, ?> requestParameterMap) {
this.requestParameterMap = toStringArrayMpa(requestParameterMap);
this.requestParameterMap = toStringArrayMap(requestParameterMap);
}
private Map<String, String[]> toStringArrayMpa(Map<String, ?> map) {
private Map<String, String[]> toStringArrayMap(Map<String, ?> map) {
Map<String, String[]> result = new TreeMap<>();
for (Map.Entry<String, ?> entry : map.entrySet()) {
Object value = entry.getValue();
@@ -94,11 +102,16 @@ public class HttpParameters implements Cloneable {
public Builder withExtraParams(Map<String, ?> params) {
if (params != null) {
requestParameterMap.putAll(toStringArrayMpa(params));
requestParameterMap.putAll(toStringArrayMap(params));
}
return this;
}
public Builder withComparator(Comparator<String> orderedComparator) {
requestParameterMap = new TreeMap<>(orderedComparator);
return this;
}
public HttpParameters build() {
Map<String, Parameter> parameters = (parent == null)
? new HashMap<String, Parameter>()
@@ -113,10 +126,5 @@ public class HttpParameters implements Cloneable {
}
return new HttpParameters(parameters);
}
public Builder withComparator(Comparator<String> orderedComparator) {
requestParameterMap = new TreeMap<>(orderedComparator);
return this;
}
}
}
@@ -135,7 +135,7 @@ public class ServletConfigInterceptor extends AbstractInterceptor implements Str
}
if (action instanceof ParameterAware) {
((ParameterAware) action).setParameters((Map)context.getParameters());
((ParameterAware) action).setParameters(context.getParameters().getHttpParameters());
}
if (action instanceof ApplicationAware) {
@@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.StrutsInternalTestCase;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.util.ServletContextAware;
import org.easymock.MockControl;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -89,7 +90,7 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
MockActionInvocation mai = createActionInvocation(mock);
Map<String, Object> param = new HashMap<String, Object>();
mai.getInvocationContext().setParameters(param);
mai.getInvocationContext().setParameters(HttpParameters.createEmpty().build());
mock.setParameters((Map)param);
control.setVoidCallable();