Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 7.0.x/merge-master-…
Browse files Browse the repository at this point in the history
…2024-11-02
  • Loading branch information
kusalk committed Nov 2, 2024
2 parents 99434d9 + 1908cba commit a43f8a5
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 33 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/org/apache/struts2/ActionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,9 @@ public final boolean equals(Object obj) {
}
return Objects.equals(getContextMap(), other.getContextMap());
}

@Override
public final int hashCode() {
return Objects.hash(getContextMap());
}
}
3 changes: 3 additions & 0 deletions core/src/main/java/org/apache/struts2/ModelDriven.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public interface ModelDriven<T> {

/**
* Gets the model to be pushed onto the ValueStack instead of the Action itself.
* <p>
* Please be aware that all setters and getters of every depth on the object returned by this method are available
* for user parameter injection!
*
* @return the model
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
public class ResultConfig extends Located implements Serializable {

protected Map<String,String> params;
protected Map<String, String> params;
protected String className;
protected String name;

Expand All @@ -64,7 +64,7 @@ public String getName() {
return name;
}

public Map<String,String> getParams() {
public Map<String, String> getParams() {
return params;
}

Expand Down Expand Up @@ -139,7 +139,7 @@ public Builder addParam(String name, String value) {
return this;
}

public Builder addParams(Map<String,String> params) {
public Builder addParams(Map<String, String> params) {
target.params.putAll(params);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import org.apache.struts2.factory.ConverterFactory;
import org.apache.struts2.factory.DefaultActionFactory;
import org.apache.struts2.factory.DefaultInterceptorFactory;
import org.apache.struts2.factory.DefaultResultFactory;
import org.apache.struts2.factory.DefaultUnknownHandlerFactory;
import org.apache.struts2.factory.DefaultValidatorFactory;
import org.apache.struts2.factory.InterceptorFactory;
Expand Down Expand Up @@ -109,6 +108,7 @@
import org.apache.struts2.conversion.StrutsConversionPropertiesProcessor;
import org.apache.struts2.conversion.StrutsTypeConverterCreator;
import org.apache.struts2.conversion.StrutsTypeConverterHolder;
import org.apache.struts2.factory.StrutsResultFactory;
import org.apache.struts2.ognl.OgnlGuard;
import org.apache.struts2.ognl.ProviderAllowlist;
import org.apache.struts2.ognl.StrutsOgnlGuard;
Expand Down Expand Up @@ -364,7 +364,7 @@ public static ContainerBuilder bootstrapFactories(ContainerBuilder builder) {
// TODO: SpringObjectFactoryTest fails when these are SINGLETON
.factory(ObjectFactory.class, Scope.PROTOTYPE)
.factory(ActionFactory.class, DefaultActionFactory.class, Scope.PROTOTYPE)
.factory(ResultFactory.class, DefaultResultFactory.class, Scope.PROTOTYPE)
.factory(ResultFactory.class, StrutsResultFactory.class, Scope.PROTOTYPE)
.factory(InterceptorFactory.class, DefaultInterceptorFactory.class, Scope.PROTOTYPE)
.factory(ValidatorFactory.class, DefaultValidatorFactory.class, Scope.PROTOTYPE)
.factory(ConverterFactory.class, StrutsConverterFactory.class, Scope.PROTOTYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@

/**
* Default implementation
*
* @deprecated since 6.7.0, use {@link StrutsResultFactory} instead.
*/
@Deprecated
public class DefaultResultFactory implements ResultFactory {

private ObjectFactory objectFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@
*/
package org.apache.struts2.interceptor.parameter;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ClassUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ActionContext;
import org.apache.struts2.ActionInvocation;
import org.apache.struts2.ModelDriven;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.action.NoParameters;
import org.apache.struts2.action.ParameterNameAware;
import org.apache.struts2.action.ParameterValueAware;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.dispatcher.Parameter;
import org.apache.struts2.inject.Inject;
import org.apache.struts2.interceptor.MethodFilterInterceptor;
import org.apache.struts2.ognl.ThreadAllowlist;
import org.apache.struts2.security.AcceptedPatternsChecker;
import org.apache.struts2.security.DefaultAcceptedPatternsChecker;
import org.apache.struts2.security.ExcludedPatternsChecker;
Expand All @@ -32,17 +43,6 @@
import org.apache.struts2.util.ValueStack;
import org.apache.struts2.util.ValueStackFactory;
import org.apache.struts2.util.reflection.ReflectionContextState;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ClassUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.action.NoParameters;
import org.apache.struts2.action.ParameterNameAware;
import org.apache.struts2.action.ParameterValueAware;
import org.apache.struts2.dispatcher.HttpParameters;
import org.apache.struts2.dispatcher.Parameter;
import org.apache.struts2.ognl.ThreadAllowlist;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
Expand All @@ -63,15 +63,15 @@
import java.util.TreeMap;
import java.util.regex.Pattern;

import static org.apache.struts2.security.DefaultAcceptedPatternsChecker.NESTING_CHARS;
import static org.apache.struts2.security.DefaultAcceptedPatternsChecker.NESTING_CHARS_STR;
import static org.apache.struts2.util.DebugUtils.logWarningForFirstOccurrence;
import static org.apache.struts2.util.DebugUtils.notifyDeveloperOfError;
import static java.lang.String.format;
import static java.util.Collections.unmodifiableSet;
import static java.util.stream.Collectors.joining;
import static org.apache.commons.lang3.StringUtils.indexOfAny;
import static org.apache.commons.lang3.StringUtils.normalizeSpace;
import static org.apache.struts2.security.DefaultAcceptedPatternsChecker.NESTING_CHARS;
import static org.apache.struts2.security.DefaultAcceptedPatternsChecker.NESTING_CHARS_STR;
import static org.apache.struts2.util.DebugUtils.logWarningForFirstOccurrence;
import static org.apache.struts2.util.DebugUtils.notifyDeveloperOfError;

/**
* This interceptor sets all parameters on the value stack.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;


/**
Expand Down Expand Up @@ -101,11 +102,11 @@ public void loadPackages() throws ConfigurationException {
HashMap<String, String> interceptorParams = new HashMap<>();
interceptorParams.put("excludes", "blah,bar");

HashMap successParams1 = new HashMap();
Map<String, String> successParams1 = new HashMap<>();
successParams1.put("propertyName", "baz");
successParams1.put("expectedValue", 1);
successParams1.put("expectedValue", "1");

HashMap successParams2 = new HashMap();
Map<String, String> successParams2 = new HashMap<>();
successParams2.put("propertyName", "blah");
successParams2.put("expectedValue", null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.struts2.config.entities.ResultTypeConfig;
import org.apache.struts2.config.impl.DefaultConfiguration;
import org.apache.struts2.factory.DefaultInterceptorFactory;
import org.apache.struts2.factory.DefaultResultFactory;
import org.apache.struts2.inject.Container;
import org.apache.struts2.inject.Scope.Strategy;
import org.apache.struts2.ognl.OgnlReflectionProvider;
Expand Down Expand Up @@ -97,6 +96,7 @@
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.dontfind.DontFindMeAction;
import org.apache.struts2.factory.StrutsResultFactory;
import org.apache.struts2.ognl.ProviderAllowlist;
import org.apache.struts2.result.ServletDispatcherResult;
import org.easymock.EasyMock;
Expand Down Expand Up @@ -918,7 +918,7 @@ public void setProperty(String name, Object value, Object o, Map<String, Object>
dif.setObjectFactory((ObjectFactory) obj);
dif.setReflectionProvider(rp);

DefaultResultFactory drf = new DefaultResultFactory();
StrutsResultFactory drf = new StrutsResultFactory();
drf.setObjectFactory((ObjectFactory) obj);
drf.setReflectionProvider(rp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,9 @@ public void testInvoke() throws Exception {
((MockActionProxy)restActionInvocation.getProxy()).setMethod("index");

// Define result 'success'
ResultConfig resultConfig = new ResultConfig.Builder("success",
"org.apache.struts2.result.HttpHeaderResult")
ResultConfig resultConfig = new ResultConfig.Builder("success", "org.apache.struts2.result.HttpHeaderResult")
.addParam("status", "123").build();
ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest",
"RestAction", "org.apache.rest.RestAction")
ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", "RestAction", "org.apache.rest.RestAction")
.addResultConfig(resultConfig)
.build();
((MockActionProxy)restActionInvocation.getProxy()).setConfig(actionConfig);
Expand All @@ -264,16 +262,16 @@ public void testInvoke() throws Exception {

class RestActionInvocationTester extends RestActionInvocation {
RestActionInvocationTester() {
super(new HashMap<String, Object>(), true);
List<InterceptorMapping> interceptorMappings = new ArrayList<InterceptorMapping>();
super(new HashMap<>(), true);
List<InterceptorMapping> interceptorMappings = new ArrayList<>();
MockInterceptor mockInterceptor = new MockInterceptor();
mockInterceptor.setFoo("interceptor");
mockInterceptor.setExpectedFoo("interceptor");
interceptorMappings.add(new InterceptorMapping("interceptor", mockInterceptor));
interceptors = interceptorMappings.iterator();
MockActionProxy actionProxy = new MockActionProxy();
ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest",
"RestAction", "org.apache.rest.RestAction").build();
ActionConfig actionConfig = new ActionConfig.Builder(
"org.apache.rest", "RestAction", "org.apache.rest.RestAction").build();
actionProxy.setConfig(actionConfig);
proxy = actionProxy;
action = new RestAction();
Expand Down

0 comments on commit a43f8a5

Please sign in to comment.