diff --git a/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java index 4591a1b59d..088cf24dda 100644 --- a/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java @@ -82,14 +82,6 @@ public XmlConfigurationProvider(String filename) { this.configFileName = filename; } - /** - * @deprecated since 6.2.0, use {@link #XmlConfigurationProvider(String)} - */ - @Deprecated - public XmlConfigurationProvider(String filename, @Deprecated boolean notUsed) { - this(filename); - } - @Override public void init(Configuration configuration) { super.init(configuration); diff --git a/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java index 6de2024609..46fc721424 100644 --- a/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java +++ b/core/src/main/java/com/opensymphony/xwork2/config/providers/XmlDocConfigurationProvider.java @@ -465,7 +465,7 @@ protected void addAction(Element actionElement, PackageConfig.Builder packageCon Location location = DomHelper.getLocationObject(actionElement); if (!className.isEmpty()) { - verifyAction(className, name, location); + verifyAction(className, location); } Map results; @@ -496,7 +496,7 @@ protected ActionConfig buildActionConfig(Element actionElement, String methodName = trimToNull(actionElement.getAttribute("method")); List interceptorList = buildInterceptorList(actionElement, packageContext); - List exceptionMappings = buildExceptionMappings(actionElement, packageContext); + List exceptionMappings = buildExceptionMappings(actionElement); Set allowedMethods = buildAllowedMethods(actionElement, packageContext); return new ActionConfig.Builder(packageContext.getName(), actionName, className) @@ -511,15 +511,6 @@ protected ActionConfig buildActionConfig(Element actionElement, .build(); } - /** - * @deprecated since 6.2.0, use {@link #verifyAction(String, Location)} - */ - @Deprecated - protected boolean verifyAction(String className, String name, Location loc) { - verifyAction(className, loc); - return true; - } - protected void verifyAction(String className, Location loc) { if (className.contains("{")) { LOG.debug("Action class [{}] contains a wildcard replacement value, so it can't be verified", className); @@ -785,14 +776,6 @@ protected static String guessResultType(String type) { return sb.toString(); } - /** - * @deprecated since 6.2.0, use {@link #buildExceptionMappings(Element)} - */ - @Deprecated - protected List buildExceptionMappings(Element element, PackageConfig.Builder packageContext) { - return buildExceptionMappings(element); - } - /** * Build a list of exception mapping objects from below a given XML element. * @@ -930,7 +913,7 @@ protected void loadGlobalExceptionMappings(PackageConfig.Builder packageContext, if (globalExceptionMappingList.getLength() > 0) { Element globalExceptionMappingElement = (Element) globalExceptionMappingList.item(0); - List exceptionMappings = buildExceptionMappings(globalExceptionMappingElement, packageContext); + List exceptionMappings = buildExceptionMappings(globalExceptionMappingElement); packageContext.addGlobalExceptionMappingConfigs(exceptionMappings); } } diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlBeanInfoCacheFactory.java b/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlBeanInfoCacheFactory.java index 8f7414a690..3513e6a818 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlBeanInfoCacheFactory.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlBeanInfoCacheFactory.java @@ -30,13 +30,6 @@ public class DefaultOgnlBeanInfoCacheFactory extends DefaultOgnlCacheFactory implements BeanInfoCacheFactory { - /** - * @deprecated since 6.4.0, use {@link #DefaultOgnlBeanInfoCacheFactory(String, String)} - */ - @Deprecated - public DefaultOgnlBeanInfoCacheFactory() { - } - @Inject public DefaultOgnlBeanInfoCacheFactory(@Inject(value = StrutsConstants.STRUTS_OGNL_BEANINFO_CACHE_MAXSIZE) String cacheMaxSize, @Inject(value = StrutsConstants.STRUTS_OGNL_BEANINFO_CACHE_TYPE) String defaultCacheType) { diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlCacheFactory.java b/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlCacheFactory.java index e503f49983..889591b69f 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlCacheFactory.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlCacheFactory.java @@ -15,8 +15,6 @@ */ package com.opensymphony.xwork2.ognl; -import org.apache.commons.lang3.BooleanUtils; - /** *

Default OGNL Cache factory implementation.

* @@ -30,18 +28,10 @@ public class DefaultOgnlCacheFactory implements OgnlCacheFactory buildOgnlCache(int evictionLimit, int initialCapacity, float loadFactor, CacheType cacheType) { - switch (cacheType) { - case BASIC: - return new OgnlDefaultCache<>(evictionLimit, initialCapacity, loadFactor); - case LRU: - return new OgnlLRUCache<>(evictionLimit, initialCapacity, loadFactor); - case WTLFU: - return new OgnlCaffeineCache<>(evictionLimit, initialCapacity); - default: - throw new IllegalArgumentException("Unknown cache type: " + cacheType); - } + return switch (cacheType) { + case BASIC -> new OgnlDefaultCache<>(evictionLimit, initialCapacity, loadFactor); + case LRU -> new OgnlLRUCache<>(evictionLimit, initialCapacity, loadFactor); + case WTLFU -> new OgnlCaffeineCache<>(evictionLimit, initialCapacity); + }; } @Override @@ -79,28 +64,8 @@ public int getCacheMaxSize() { return cacheMaxSize; } - /** - * @deprecated since 6.4.0 - */ - @Deprecated - protected void setCacheMaxSize(String maxSize) { - cacheMaxSize = Integer.parseInt(maxSize); - } - @Override public CacheType getDefaultCacheType() { return defaultCacheType; } - - /** - * No effect when {@code useLRUMode} is {@code false} - * - * @deprecated since 6.4.0 - */ - @Deprecated - protected void setUseLRUCache(String useLRUMode) { - if (BooleanUtils.toBoolean(useLRUMode)) { - defaultCacheType = CacheType.LRU; - } - } } diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlExpressionCacheFactory.java b/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlExpressionCacheFactory.java index fadc8b3a54..9a8555f912 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlExpressionCacheFactory.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/DefaultOgnlExpressionCacheFactory.java @@ -30,13 +30,6 @@ public class DefaultOgnlExpressionCacheFactory extends DefaultOgnlCacheFactory implements ExpressionCacheFactory { - /** - * @deprecated since 6.4.0, use {@link #DefaultOgnlExpressionCacheFactory(String, String)} - */ - @Deprecated - public DefaultOgnlExpressionCacheFactory() { - } - @Inject public DefaultOgnlExpressionCacheFactory(@Inject(value = StrutsConstants.STRUTS_OGNL_EXPRESSION_CACHE_MAXSIZE) String cacheMaxSize, @Inject(value = StrutsConstants.STRUTS_OGNL_EXPRESSION_CACHE_TYPE) String defaultCacheType) { diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlCacheFactory.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlCacheFactory.java index 874bf4a2e1..708c6728d9 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlCacheFactory.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlCacheFactory.java @@ -25,22 +25,6 @@ public interface OgnlCacheFactory { OgnlCache buildOgnlCache(); - /** - * Note that if {@code lruCache} is {@code false}, the cache type could still be LRU if the default cache type is - * configured as such. - * @deprecated since 6.4.0, use {@link #buildOgnlCache(int, int, float, CacheType)} - */ - @Deprecated - default OgnlCache buildOgnlCache(int evictionLimit, - int initialCapacity, - float loadFactor, - boolean lruCache) { - return buildOgnlCache(evictionLimit, - initialCapacity, - loadFactor, - lruCache ? CacheType.LRU : getDefaultCacheType()); - } - /** * @param evictionLimit maximum capacity of the cache where applicable for cache type chosen * @param initialCapacity initial capacity of the cache where applicable for cache type chosen @@ -52,14 +36,6 @@ default OgnlCache buildOgnlCache(int evictionLimit, int getCacheMaxSize(); - /** - * @deprecated since 6.4.0 - */ - @Deprecated - default boolean getUseLRUCache() { - return CacheType.LRU.equals(getDefaultCacheType()); - } - CacheType getDefaultCacheType(); enum CacheType { diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java index 78cada96df..3ec09f1eed 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java @@ -36,7 +36,6 @@ import org.apache.logging.log4j.Logger; import org.apache.struts2.StrutsConstants; import org.apache.struts2.ognl.OgnlGuard; -import org.apache.struts2.ognl.StrutsOgnlGuard; import java.beans.BeanInfo; import java.beans.IntrospectionException; @@ -46,13 +45,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; -import java.util.Set; -import java.util.regex.Pattern; -import static com.opensymphony.xwork2.util.ConfigParseUtil.toClassesSet; -import static com.opensymphony.xwork2.util.ConfigParseUtil.toNewPatternsSet; -import static com.opensymphony.xwork2.util.ConfigParseUtil.toPackageNamesSet; -import static java.util.Collections.emptySet; import static java.util.Objects.requireNonNull; import static org.apache.struts2.ognl.OgnlGuard.EXPR_BLOCKED; @@ -78,18 +71,6 @@ public class OgnlUtil { private Container container; - /** - * Construct a new OgnlUtil instance for use with the framework - * - * @deprecated since 6.0.0. Use {@link #OgnlUtil(ExpressionCacheFactory, BeanInfoCacheFactory, OgnlGuard) instead. - */ - @Deprecated - public OgnlUtil() { - this(new DefaultOgnlExpressionCacheFactory<>(), - new DefaultOgnlBeanInfoCacheFactory<>(), - new StrutsOgnlGuard()); - } - /** * Construct a new OgnlUtil instance for use with the framework, with optional cache factories for OGNL Expression * and BeanInfo caches. @@ -147,131 +128,11 @@ protected void setEnableEvalExpression(String evalExpression) { } } - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - protected void setExcludedClasses(String commaDelimitedClasses) { - // Must be set directly on SecurityMemberAccess - } - - /** - * @deprecated since 6.5.0, no replacement. - */ - @Deprecated - protected void setDevModeExcludedClasses(String commaDelimitedClasses) { - // Must be set directly on SecurityMemberAccess - } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - protected void setExcludedPackageNamePatterns(String commaDelimitedPackagePatterns) { - // Must be set directly on SecurityMemberAccess - } - - /** - * @deprecated since 6.5.0, no replacement. - */ - @Deprecated - protected void setDevModeExcludedPackageNamePatterns(String commaDelimitedPackagePatterns) { - // Must be set directly on SecurityMemberAccess - } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - protected void setExcludedPackageNames(String commaDelimitedPackageNames) { - // Must be set directly on SecurityMemberAccess - } - - /** - * @deprecated since 6.5.0, no replacement. - */ - @Deprecated - protected void setDevModeExcludedPackageNames(String commaDelimitedPackageNames) { - // Must be set directly on SecurityMemberAccess - } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - public void setExcludedPackageExemptClasses(String commaDelimitedClasses) { - // Must be set directly on SecurityMemberAccess - } - - /** - * @deprecated since 6.5.0, no replacement. - */ - @Deprecated - public void setDevModeExcludedPackageExemptClasses(String commaDelimitedClasses) { - // Must be set directly on SecurityMemberAccess - } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - public Set getExcludedClasses() { - return toClassesSet(container.getInstance(String.class, StrutsConstants.STRUTS_EXCLUDED_CLASSES)); - } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - public Set getExcludedPackageNamePatterns() { - return toNewPatternsSet(emptySet(), container.getInstance(String.class, StrutsConstants.STRUTS_EXCLUDED_PACKAGE_NAME_PATTERNS)); - } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - public Set getExcludedPackageNames() { - return toPackageNamesSet(container.getInstance(String.class, StrutsConstants.STRUTS_EXCLUDED_PACKAGE_NAMES)); - } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - public Set getExcludedPackageExemptClasses() { - return toClassesSet(container.getInstance(String.class, StrutsConstants.STRUTS_EXCLUDED_PACKAGE_EXEMPT_CLASSES)); - } - @Inject protected void setContainer(Container container) { this.container = container; } - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - protected void setAllowStaticFieldAccess(String allowStaticFieldAccess) { - // Must be set directly on SecurityMemberAccess - } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - protected void setDisallowProxyMemberAccess(String disallowProxyMemberAccess) { - // Must be set directly on SecurityMemberAccess - } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - protected void setDisallowDefaultPackageAccess(String disallowDefaultPackageAccess) { - // Must be set directly on SecurityMemberAccess - } - /** * @param maxLength Injects the Struts OGNL expression maximum length. */ @@ -291,22 +152,6 @@ protected void applyExpressionMaxLength(String maxLength) { } } - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - public boolean isDisallowProxyMemberAccess() { - return BooleanUtils.toBoolean(container.getInstance(String.class, StrutsConstants.STRUTS_DISALLOW_PROXY_MEMBER_ACCESS)); - } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - public boolean isDisallowDefaultPackageAccess() { - return BooleanUtils.toBoolean(container.getInstance(String.class, StrutsConstants.STRUTS_DISALLOW_DEFAULT_PACKAGE_ACCESS)); - } - /** * Convenience mechanism to clear the OGNL Runtime Cache via OgnlUtil. May be utilized * by applications that generate many unique OGNL expressions over time. diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java index 980d634c13..0da14020dc 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java @@ -23,7 +23,6 @@ import com.opensymphony.xwork2.conversion.impl.XWorkConverter; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor; import com.opensymphony.xwork2.ognl.accessor.RootAccessor; import com.opensymphony.xwork2.util.ClearableValueStack; import com.opensymphony.xwork2.util.CompoundRoot; @@ -109,34 +108,6 @@ protected OgnlValueStack(ValueStack vs, XWorkConverter xworkConverter, RootAcces this(vs, xworkConverter, accessor, null, securityMemberAccess); } - /** - * @deprecated since 6.4.0, use {@link #OgnlValueStack(ValueStack, XWorkConverter, RootAccessor, TextProvider, SecurityMemberAccess)} instead. - */ - @Deprecated - protected OgnlValueStack(ValueStack vs, - XWorkConverter xworkConverter, - CompoundRootAccessor accessor, - TextProvider prov, - boolean allowStaticFieldAccess) { - this(vs, xworkConverter, accessor, prov, new SecurityMemberAccess(allowStaticFieldAccess)); - } - - /** - * @deprecated since 6.4.0, use {@link #OgnlValueStack(XWorkConverter, RootAccessor, TextProvider, SecurityMemberAccess)} instead. - */ - @Deprecated - protected OgnlValueStack(XWorkConverter xworkConverter, CompoundRootAccessor accessor, TextProvider prov, boolean allowStaticFieldAccess) { - this(xworkConverter, accessor, prov, new SecurityMemberAccess(allowStaticFieldAccess)); - } - - /** - * @deprecated since 6.4.0, use {@link #OgnlValueStack(ValueStack, XWorkConverter, RootAccessor, SecurityMemberAccess)} instead. - */ - @Deprecated - protected OgnlValueStack(ValueStack vs, XWorkConverter xworkConverter, CompoundRootAccessor accessor, boolean allowStaticFieldAccess) { - this(vs, xworkConverter, accessor, new SecurityMemberAccess(allowStaticFieldAccess)); - } - @Inject protected void setOgnlUtil(OgnlUtil ognlUtil) { this.ognlUtil = ognlUtil; @@ -155,14 +126,6 @@ protected void setRoot(XWorkConverter xworkConverter, RootAccessor accessor, Com ((OgnlContext) context).setKeepLastEvaluation(false); } - /** - * @deprecated since 6.4.0, use {@link #setRoot(XWorkConverter, RootAccessor, CompoundRoot, SecurityMemberAccess)} instead. - */ - @Deprecated - protected void setRoot(XWorkConverter xworkConverter, CompoundRootAccessor accessor, CompoundRoot compoundRoot, boolean allowStaticFieldAccess) { - setRoot(xworkConverter, accessor, compoundRoot, new SecurityMemberAccess(allowStaticFieldAccess)); - } - @Inject(StrutsConstants.STRUTS_DEVMODE) protected void setDevMode(String mode) { this.devMode = BooleanUtils.toBoolean(mode); @@ -535,12 +498,4 @@ public void useAcceptProperties(Set acceptedProperties) { public void useExcludeProperties(Set excludeProperties) { securityMemberAccess.useExcludeProperties(excludeProperties); } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - protected void setXWorkConverter(final XWorkConverter converter) { - // no-op - } } diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java index 2910d40a69..137889110a 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStackFactory.java @@ -30,7 +30,6 @@ import ognl.MethodAccessor; import ognl.OgnlRuntime; import ognl.PropertyAccessor; -import org.apache.commons.lang3.BooleanUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.StrutsConstants; @@ -159,12 +158,4 @@ protected void registerPropertyAccessors() throws ClassNotFoundException { LOG.debug("Registered custom OGNL PropertyAccessor [{}] for class [{}]", propertyAccessor.getClass().getName(), cls.getName()); } } - - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated - protected boolean containerAllowsStaticFieldAccess() { - return BooleanUtils.toBoolean(container.getInstance(String.class, StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS)); - } } diff --git a/core/src/main/java/org/apache/struts2/StrutsConstants.java b/core/src/main/java/org/apache/struts2/StrutsConstants.java index 6383236a27..c8c7489d44 100644 --- a/core/src/main/java/org/apache/struts2/StrutsConstants.java +++ b/core/src/main/java/org/apache/struts2/StrutsConstants.java @@ -310,13 +310,6 @@ public final class StrutsConstants { */ public static final String STRUTS_OGNL_BEANINFO_CACHE_MAXSIZE = "struts.ognl.beanInfoCacheMaxSize"; - /** - * @since 6.0.0 - * @deprecated since 6.4.0, use {@link StrutsConstants#STRUTS_OGNL_BEANINFO_CACHE_TYPE} instead. - */ - @Deprecated - public static final String STRUTS_OGNL_BEANINFO_CACHE_LRU_MODE = "struts.ognl.beanInfoCacheLRUMode"; - /** * Logs properties that are not found (very verbose) * @since 6.0.0 @@ -372,13 +365,6 @@ public final class StrutsConstants { */ public static final String STRUTS_OGNL_EXPRESSION_CACHE_MAXSIZE = "struts.ognl.expressionCacheMaxSize"; - /** - * @since 6.0.0 - * @deprecated since 6.4.0, use {@link StrutsConstants#STRUTS_OGNL_EXPRESSION_CACHE_TYPE} instead. - */ - @Deprecated - public static final String STRUTS_OGNL_EXPRESSION_CACHE_LRU_MODE = "struts.ognl.expressionCacheLRUMode"; - /** * Enables evaluation of OGNL expressions * @since 6.0.0 diff --git a/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java b/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java index 51dded4cf2..3ea6dbabbc 100644 --- a/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java +++ b/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java @@ -25,10 +25,10 @@ import com.opensymphony.xwork2.inject.Context; import com.opensymphony.xwork2.inject.Factory; import com.opensymphony.xwork2.util.location.LocatableProperties; +import jakarta.servlet.ServletContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import jakarta.servlet.ServletContext; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; @@ -105,14 +105,6 @@ public StrutsXmlConfigurationProvider(String filename, ServletContext ctx) { } } - /** - * @deprecated since 6.2.0, use {@link #StrutsXmlConfigurationProvider(String, ServletContext)} - */ - @Deprecated - public StrutsXmlConfigurationProvider(String filename, @Deprecated boolean errorIfMissing, ServletContext ctx) { - this(filename, ctx); - } - /* (non-Javadoc) * @see com.opensymphony.xwork2.config.providers.XmlConfigurationProvider#register(com.opensymphony.xwork2.inject.ContainerBuilder, java.util.Properties) */ diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java index 6d21ef693d..4f161e3906 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java @@ -48,6 +48,10 @@ import com.opensymphony.xwork2.util.location.LocatableProperties; import com.opensymphony.xwork2.util.location.Location; import com.opensymphony.xwork2.util.location.LocationUtils; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.LocaleUtils; import org.apache.commons.lang3.StringUtils; @@ -72,10 +76,6 @@ import org.apache.struts2.util.ObjectFactoryDestroyable; import org.apache.struts2.util.fs.JBossFileManager; -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.util.Arrays; @@ -331,14 +331,6 @@ public void setMultipartSaveDir(String val) { multipartSaveDir = val; } - /** - * @deprecated since 6.4.0, no replacement. - */ - @Deprecated(since = "6.4.0", forRemoval = true) - public void setMultipartHandler(String val) { - // no-op - } - @Inject(value = StrutsConstants.STRUTS_MULTIPART_ENABLED, required = false) public void setMultipartSupportEnabled(String multipartSupportEnabled) { this.multipartSupportEnabled = Boolean.parseBoolean(multipartSupportEnabled); @@ -551,14 +543,6 @@ protected XmlConfigurationProvider createStrutsXmlConfigurationProvider(String f return new StrutsXmlConfigurationProvider(filename, ctx); } - /** - * @deprecated since 6.2.0, use {@link #createStrutsXmlConfigurationProvider(String, ServletContext)} - */ - @Deprecated - protected XmlConfigurationProvider createStrutsXmlConfigurationProvider(String filename, boolean errorIfMissing, ServletContext ctx) { - return createStrutsXmlConfigurationProvider(filename, ctx); - } - private void init_JavaConfigurations() { String configClasses = initParams.get("javaConfigClasses"); if (configClasses != null) { diff --git a/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java b/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java index f5cf21a916..6f37a6392e 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java @@ -22,9 +22,7 @@ import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; -import java.util.regex.Pattern; /** * Contains initialization operations @@ -90,18 +88,4 @@ protected Dispatcher createDispatcher(HostConfig filterConfig) { public void cleanup() { ActionContext.clear(); } - - /** - * Extract a list of patterns to exclude from request filtering - * - * @param dispatcher The dispatcher to check for exclude pattern configuration - * @return a List of Patterns for request to exclude if apply, or null - * @see org.apache.struts2.StrutsConstants#STRUTS_ACTION_EXCLUDE_PATTERN - * @deprecated since 6.4.0, use {@link Dispatcher#getActionExcludedPatterns()} instead. - */ - @Deprecated - public List buildExcludedPatternsList(Dispatcher dispatcher) { - return dispatcher.getActionExcludedPatterns(); - } - } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java b/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java index 01c04d6aa6..e3262221b8 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java @@ -20,6 +20,9 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.util.ValueStack; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.RequestUtils; @@ -27,13 +30,8 @@ import org.apache.struts2.StrutsException; import org.apache.struts2.dispatcher.mapper.ActionMapping; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.HashMap; -import java.util.List; -import java.util.regex.Pattern; /** * Contains preparation operations for a request before execution @@ -230,18 +228,6 @@ public boolean isUrlExcluded(HttpServletRequest request) { return dispatcher.getActionExcludedPatterns().stream().anyMatch(pattern -> pattern.matcher(uri).matches()); } - /** - * @deprecated since 6.4.0, use {@link #isUrlExcluded(HttpServletRequest)} instead. - */ - @Deprecated - public boolean isUrlExcluded(HttpServletRequest request, List excludedPatterns) { - if (excludedPatterns == null) { - return false; - } - String uri = RequestUtils.getUri(request); - return excludedPatterns.stream().anyMatch(pattern -> pattern.matcher(uri).matches()); - } - /** * Set an override of the static devMode value. Do not set this via a * request parameter or any other unprotected method. Using a signed diff --git a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java index 25b4598129..c954f1c384 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java @@ -18,6 +18,14 @@ */ package org.apache.struts2.dispatcher.filter; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.RequestUtils; @@ -28,17 +36,7 @@ import org.apache.struts2.dispatcher.PrepareOperations; import org.apache.struts2.dispatcher.mapper.ActionMapping; -import jakarta.servlet.Filter; -import jakarta.servlet.FilterChain; -import jakarta.servlet.FilterConfig; -import jakarta.servlet.ServletException; -import jakarta.servlet.ServletRequest; -import jakarta.servlet.ServletResponse; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.List; -import java.util.regex.Pattern; /** * Handles both the preparation and execution phases of the Struts dispatching process. This filter is better to use @@ -51,13 +49,6 @@ public class StrutsPrepareAndExecuteFilter implements StrutsStatics, Filter { protected PrepareOperations prepare; protected ExecuteOperations execute; - /** - * @deprecated since 6.4.0, use {@link Dispatcher#getActionExcludedPatterns} or - * {@link PrepareOperations#isUrlExcluded(HttpServletRequest)} instead. - */ - @Deprecated - protected List excludedPatterns; - public void init(FilterConfig filterConfig) throws ServletException { InitOperations init = createInitOperations(); Dispatcher dispatcher = null; @@ -69,8 +60,6 @@ public void init(FilterConfig filterConfig) throws ServletException { prepare = createPrepareOperations(dispatcher); execute = createExecuteOperations(dispatcher); - this.excludedPatterns = init.buildExcludedPatternsList(dispatcher); - postInit(dispatcher, filterConfig); } finally { if (dispatcher != null) { diff --git a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java index 0969617d72..02b4120d06 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java @@ -18,11 +18,6 @@ */ package org.apache.struts2.dispatcher.filter; -import org.apache.struts2.StrutsStatics; -import org.apache.struts2.dispatcher.Dispatcher; -import org.apache.struts2.dispatcher.InitOperations; -import org.apache.struts2.dispatcher.PrepareOperations; - import jakarta.servlet.Filter; import jakarta.servlet.FilterChain; import jakarta.servlet.FilterConfig; @@ -31,9 +26,12 @@ import jakarta.servlet.ServletResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.apache.struts2.StrutsStatics; +import org.apache.struts2.dispatcher.Dispatcher; +import org.apache.struts2.dispatcher.InitOperations; +import org.apache.struts2.dispatcher.PrepareOperations; + import java.io.IOException; -import java.util.List; -import java.util.regex.Pattern; /** * Prepares the request for execution by a later {@link org.apache.struts2.dispatcher.filter.StrutsExecuteFilter} filter instance. @@ -44,13 +42,6 @@ public class StrutsPrepareFilter implements StrutsStatics, Filter { protected PrepareOperations prepare; - /** - * @deprecated since 6.4.0, use {@link Dispatcher#getActionExcludedPatterns} or - * {@link PrepareOperations#isUrlExcluded(HttpServletRequest)} instead. - */ - @Deprecated - protected List excludedPatterns; - public void init(FilterConfig filterConfig) throws ServletException { InitOperations init = createInitOperations(); Dispatcher dispatcher = null; @@ -60,8 +51,6 @@ public void init(FilterConfig filterConfig) throws ServletException { prepare = createPrepareOperations(dispatcher); - this.excludedPatterns = init.buildExcludedPatternsList(dispatcher); - postInit(dispatcher, filterConfig); } finally { if (dispatcher != null) { diff --git a/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInterceptor.java index ecb1f7f9f1..4d52c5f9a5 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInterceptor.java @@ -55,7 +55,7 @@ *

* The best way to add behavior to this interceptor is to utilize the {@link ParameterNameAware} interface in your * actions. However, if you wish to apply a global rule that isn't implemented in your action, then you could extend - * this interceptor and override the {@link #acceptableName(String)} method. + * this interceptor and override the {@link #isAcceptableName(String)} method. *

* * diff --git a/core/src/main/java/org/apache/struts2/interceptor/ApplicationAware.java b/core/src/main/java/org/apache/struts2/interceptor/ApplicationAware.java deleted file mode 100644 index 166f484c9c..0000000000 --- a/core/src/main/java/org/apache/struts2/interceptor/ApplicationAware.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 java.util.Map; - -@Deprecated -public interface ApplicationAware extends org.apache.struts2.action.ApplicationAware { - - void setApplication(Map application); - - @Override - default void withApplication(Map application) { - setApplication(application); - } -} diff --git a/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java index 650c79f30f..9f40efdf17 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/CookieInterceptor.java @@ -26,11 +26,12 @@ import com.opensymphony.xwork2.security.ExcludedPatternsChecker; import com.opensymphony.xwork2.util.TextParseUtil; import com.opensymphony.xwork2.util.ValueStack; +import jakarta.servlet.http.Cookie; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.ServletActionContext; +import org.apache.struts2.action.CookiesAware; -import jakarta.servlet.http.Cookie; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -357,7 +358,7 @@ else if (cookiesValueSet.contains("*")) protected void injectIntoCookiesAwareAction(Object action, Map cookiesMap) { if (action instanceof CookiesAware) { LOG.debug("Action [{}] implements CookiesAware, injecting cookies map [{}]", action, cookiesMap); - ((CookiesAware)action).setCookiesMap(cookiesMap); + ((CookiesAware)action).withCookies(cookiesMap); } if (action instanceof org.apache.struts2.action.CookiesAware) { LOG.debug("Action [{}] implements CookiesAware, injecting cookies map [{}]", action, cookiesMap); diff --git a/core/src/main/java/org/apache/struts2/interceptor/CookiesAware.java b/core/src/main/java/org/apache/struts2/interceptor/CookiesAware.java deleted file mode 100644 index d3a0a02b13..0000000000 --- a/core/src/main/java/org/apache/struts2/interceptor/CookiesAware.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 java.util.Map; - -/** - * Actions implementing the CookiesAware interface will receive - * a Map of filtered cookies via the setCookiesMap method. - * - * Please note that the {@link CookieInterceptor} needs to be - * activated to receive a cookies map. - * - * @deprecated please use {@link org.apache.struts2.action.CookiesAware} instead - */ -@Deprecated -public interface CookiesAware { - /** - * Sets a map of filtered cookies. - * @param cookies the cookies - * @deprecated please use {@link org.apache.struts2.action.CookiesAware#withCookies(Map)} instead - */ - void setCookiesMap(Map cookies); -} \ No newline at end of file diff --git a/core/src/main/java/org/apache/struts2/interceptor/HttpParametersAware.java b/core/src/main/java/org/apache/struts2/interceptor/HttpParametersAware.java deleted file mode 100644 index 1c4b758f76..0000000000 --- a/core/src/main/java/org/apache/struts2/interceptor/HttpParametersAware.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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; - -@Deprecated -public interface HttpParametersAware extends org.apache.struts2.action.ParametersAware { - - void setParameters(HttpParameters parameters); - - @Override - default void withParameters(HttpParameters parameters) { - setParameters(parameters); - } -} diff --git a/core/src/main/java/org/apache/struts2/interceptor/ParameterAware.java b/core/src/main/java/org/apache/struts2/interceptor/ParameterAware.java deleted file mode 100644 index 561542376b..0000000000 --- a/core/src/main/java/org/apache/struts2/interceptor/ParameterAware.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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; - -import java.util.Map; - -import static java.util.stream.Collectors.toMap; - -@Deprecated -public interface ParameterAware extends org.apache.struts2.action.ParametersAware { - - void setParameters(Map map); - - @Override - default void withParameters(HttpParameters parameters) { - setParameters(parameters.entrySet().stream().collect(toMap(Map.Entry::getKey, e -> e.getValue().getMultipleValues()))); - } -} diff --git a/core/src/main/java/org/apache/struts2/interceptor/PrincipalAware.java b/core/src/main/java/org/apache/struts2/interceptor/PrincipalAware.java deleted file mode 100644 index dfe4203ffb..0000000000 --- a/core/src/main/java/org/apache/struts2/interceptor/PrincipalAware.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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; - -@Deprecated -public interface PrincipalAware extends org.apache.struts2.action.PrincipalAware { - - void setPrincipalProxy(PrincipalProxy principalProxy); - - @Override - default void withPrincipalProxy(PrincipalProxy principalProxy) { - setPrincipalProxy(principalProxy); - } -} diff --git a/core/src/main/java/org/apache/struts2/interceptor/RequestAware.java b/core/src/main/java/org/apache/struts2/interceptor/RequestAware.java deleted file mode 100644 index 5e24e8dfb1..0000000000 --- a/core/src/main/java/org/apache/struts2/interceptor/RequestAware.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.RequestMap; - -import jakarta.servlet.http.HttpServletRequest; -import java.util.Map; - -@Deprecated -public interface RequestAware extends ServletRequestAware { - - @Override - default void setServletRequest(HttpServletRequest httpServletRequest) { - // default no-op - } - - @Override - default void withServletRequest(HttpServletRequest request) { - ServletRequestAware.super.withServletRequest(request); - setRequest(new RequestMap(request)); - } - - void setRequest(Map request); -} diff --git a/core/src/main/java/org/apache/struts2/interceptor/ServletConfigInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/ServletConfigInterceptor.java index e26c1247da..e09e97d670 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/ServletConfigInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/ServletConfigInterceptor.java @@ -18,10 +18,12 @@ */ package org.apache.struts2.interceptor; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.interceptor.AbstractInterceptor; import jakarta.servlet.ServletContext; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; - import org.apache.struts2.StrutsStatics; import org.apache.struts2.action.ApplicationAware; import org.apache.struts2.action.ParametersAware; @@ -32,15 +34,11 @@ import org.apache.struts2.action.SessionAware; import org.apache.struts2.interceptor.servlet.ServletPrincipalProxy; -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.interceptor.AbstractInterceptor; - /** * *

* An interceptor which sets action properties based on the interfaces an action implements. For example, if the action - * implements {@link ParameterAware} then the action context's parameter map will be set on it. + * implements {@link ParametersAware} then the action context's parameter map will be set on it. *

* *

This interceptor is designed to set all properties an action needs if it's aware of servlet parameters, the diff --git a/core/src/main/java/org/apache/struts2/interceptor/ServletRequestAware.java b/core/src/main/java/org/apache/struts2/interceptor/ServletRequestAware.java deleted file mode 100644 index 8f059d4793..0000000000 --- a/core/src/main/java/org/apache/struts2/interceptor/ServletRequestAware.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 jakarta.servlet.http.HttpServletRequest; - -@Deprecated -public interface ServletRequestAware extends org.apache.struts2.action.ServletRequestAware { - - void setServletRequest(HttpServletRequest httpServletRequest); - - @Override - default void withServletRequest(HttpServletRequest request) { - setServletRequest(request); - } -} diff --git a/core/src/main/java/org/apache/struts2/interceptor/ServletResponseAware.java b/core/src/main/java/org/apache/struts2/interceptor/ServletResponseAware.java deleted file mode 100644 index de054878a4..0000000000 --- a/core/src/main/java/org/apache/struts2/interceptor/ServletResponseAware.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 jakarta.servlet.http.HttpServletResponse; - -@Deprecated -public interface ServletResponseAware extends org.apache.struts2.action.ServletResponseAware { - - void setServletResponse(HttpServletResponse httpServletResponse); - - @Override - default void withServletResponse(HttpServletResponse response) { - setServletResponse(response); - } -} diff --git a/core/src/main/java/org/apache/struts2/interceptor/SessionAware.java b/core/src/main/java/org/apache/struts2/interceptor/SessionAware.java deleted file mode 100644 index 828284d534..0000000000 --- a/core/src/main/java/org/apache/struts2/interceptor/SessionAware.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 java.util.Map; - -@Deprecated -public interface SessionAware extends org.apache.struts2.action.SessionAware { - - void setSession(Map session); - - @Override - default void withSession(Map session) { - setSession(session); - } -} diff --git a/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java index 239bc6d6ca..75bc44abe4 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java @@ -195,7 +195,7 @@ public String doIntercept(ActionInvocation invocation) throws Exception { Map contextMap = actionContext.getContextMap(); batchApplyReflectionContextState(contextMap, true); try { - setParameters(action, actionContext.getValueStack(), parameters); + applyParameters(action, actionContext.getValueStack(), parameters); } finally { batchApplyReflectionContextState(contextMap, false); } @@ -226,14 +226,6 @@ protected HttpParameters retrieveParameters(ActionContext actionContext) { protected void addParametersToContext(ActionContext ac, Map newParams) { } - /** - * @deprecated since 6.4.0, use {@link #applyParameters} - */ - @Deprecated - protected void setParameters(final Object action, ValueStack stack, HttpParameters parameters) { - applyParameters(action, stack, parameters); - } - protected void applyParameters(final Object action, ValueStack stack, HttpParameters parameters) { Map acceptableParameters = toAcceptableParameters(parameters, action); @@ -328,7 +320,7 @@ protected void notifyDeveloperParameterException(Object action, String property, * @return true if parameter is accepted */ protected boolean isAcceptableParameter(String name, Object action) { - return acceptableName(name) && isAcceptableParameterNameAware(name, action) && isParameterAnnotatedAndAllowlist(name, action); + return isAcceptableName(name) && isAcceptableParameterNameAware(name, action) && isParameterAnnotatedAndAllowlist(name, action); } protected boolean isAcceptableParameterNameAware(String name, Object action) { @@ -517,7 +509,7 @@ protected BeanInfo getBeanInfo(Object action) { * @return true if parameter is accepted */ protected boolean isAcceptableParameterValue(Parameter param, Object action) { - return isAcceptableParameterValueAware(param, action) && acceptableValue(param.getName(), param.getValue()); + return isAcceptableParameterValueAware(param, action) && isAcceptableValue(param.getName(), param.getValue()); } protected boolean isAcceptableParameterValueAware(Parameter param, Object action) { @@ -544,13 +536,6 @@ protected String getParameterLogMap(HttpParameters parameters) { .collect(joining()); } - /** - * @deprecated since 6.4.0, use {@link #isAcceptableName} - */ - protected boolean acceptableName(String name) { - return isAcceptableName(name); - } - /** * Validates the name passed is: * * Within the max length of a parameter name @@ -579,13 +564,6 @@ private boolean isIgnoredDMI(String name) { return DMI_IGNORED_PATTERN.matcher(name).matches(); } - /** - * @deprecated since 6.4.0, use {@link #isAcceptableValue} - */ - protected boolean acceptableValue(String name, String value) { - return isAcceptableValue(name, value); - } - /** * Validates: * * Value is null/blank diff --git a/core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java b/core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java index e099a060a6..bc5eb14f9f 100644 --- a/core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/DefaultActionInvocationTest.java @@ -26,14 +26,10 @@ import com.opensymphony.xwork2.mock.MockActionProxy; import com.opensymphony.xwork2.mock.MockInterceptor; import com.opensymphony.xwork2.mock.MockResult; -import com.opensymphony.xwork2.ognl.DefaultOgnlBeanInfoCacheFactory; -import com.opensymphony.xwork2.ognl.DefaultOgnlExpressionCacheFactory; -import com.opensymphony.xwork2.ognl.OgnlUtil; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.ValueStackFactory; import org.apache.struts2.config.StrutsXmlConfigurationProvider; import org.apache.struts2.dispatcher.HttpParameters; -import org.apache.struts2.ognl.StrutsOgnlGuard; import java.util.ArrayList; import java.util.HashMap; @@ -42,6 +38,8 @@ import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; +import static com.opensymphony.xwork2.ognl.OgnlUtilTest.createOgnlUtil; + /** * A partial test of DefaultActionInvocation. @@ -531,14 +529,6 @@ protected void setUp() throws Exception { loadConfigurationProviders(configurationProvider); } - private OgnlUtil createOgnlUtil() { - return new OgnlUtil( - new DefaultOgnlExpressionCacheFactory<>(), - new DefaultOgnlBeanInfoCacheFactory<>(), - new StrutsOgnlGuard() - ); - } - private static class SimpleActionEventListener implements ActionEventListener { private final String name; diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java index 27a0d0f330..255677d002 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java @@ -63,6 +63,8 @@ import java.util.Locale; import java.util.Map; +import static com.opensymphony.xwork2.ognl.OgnlCacheFactory.CacheType.BASIC; +import static com.opensymphony.xwork2.ognl.OgnlCacheFactory.CacheType.LRU; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertThrows; @@ -1343,13 +1345,13 @@ public void testCallMethod() { public void testDefaultOgnlUtilAlternateConstructorArguments() { // Code coverage test for the OgnlUtil alternate constructor method, and verify expected behaviour. try { - OgnlUtil basicOgnlUtil = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<>(), null, null); + new OgnlUtil(createDefaultOgnlExpressionCacheFactory(), null, null); fail("null beanInfoCacheFactory should result in exception"); } catch (NullPointerException iaex) { // expected result } try { - OgnlUtil basicOgnlUtil = new OgnlUtil(null, new DefaultOgnlBeanInfoCacheFactory<>(), null); + new OgnlUtil(null, createDefaultOgnlBeanInfoCacheFactory(), null); fail("null expressionCacheFactory should result in exception"); } catch (NullPointerException iaex) { // expected result @@ -1614,23 +1616,24 @@ public void testOgnlUtilLRUCacheClass() throws OgnlException { */ public void testOgnlDefaultCacheFactoryCoverage() { OgnlCache ognlCache; - DefaultOgnlCacheFactory defaultOgnlCacheFactory = new DefaultOgnlCacheFactory(); + // Normal cache - defaultOgnlCacheFactory.setCacheMaxSize("12"); - defaultOgnlCacheFactory.setUseLRUCache("false"); + DefaultOgnlCacheFactory defaultOgnlCacheFactory = new DefaultOgnlCacheFactory<>(12, BASIC); ognlCache = defaultOgnlCacheFactory.buildOgnlCache(); assertNotNull("No param build method result null ?", ognlCache); assertEquals("Eviction limit for cache mismatches limit for factory ?", 12, ognlCache.getEvictionLimit()); - ognlCache = defaultOgnlCacheFactory.buildOgnlCache(6, 6, 0.75f, false); + + ognlCache = defaultOgnlCacheFactory.buildOgnlCache(6, 6, 0.75f, BASIC); assertNotNull("No param build method result null ?", ognlCache); assertEquals("Eviction limit for cache mismatches limit for factory ?", 6, ognlCache.getEvictionLimit()); + // LRU cache - defaultOgnlCacheFactory.setCacheMaxSize("30"); - defaultOgnlCacheFactory.setUseLRUCache("true"); + defaultOgnlCacheFactory = new DefaultOgnlCacheFactory<>(30, LRU); ognlCache = defaultOgnlCacheFactory.buildOgnlCache(); assertNotNull("No param build method result null ?", ognlCache); assertEquals("Eviction limit for cache mismatches limit for factory ?", 30, ognlCache.getEvictionLimit()); - ognlCache = defaultOgnlCacheFactory.buildOgnlCache(15, 15, 0.75f, true); + + ognlCache = defaultOgnlCacheFactory.buildOgnlCache(15, 15, 0.75f, LRU); assertNotNull("No param build method result null ?", ognlCache); assertEquals("Eviction limit for cache mismatches limit for factory ?", 15, ognlCache.getEvictionLimit()); } @@ -1653,12 +1656,8 @@ public void testCustomOgnlMapBlocked() throws Exception { */ private OgnlUtil generateOgnlUtilInstanceWithDefaultLRUCacheFactories() { final OgnlUtil result; - final DefaultOgnlExpressionCacheFactory expressionFactory = new DefaultOgnlExpressionCacheFactory<>(); - final DefaultOgnlBeanInfoCacheFactory, BeanInfo> beanInfoFactory = new DefaultOgnlBeanInfoCacheFactory<>(); - expressionFactory.setUseLRUCache("true"); - expressionFactory.setCacheMaxSize("25"); - beanInfoFactory.setUseLRUCache("true"); - beanInfoFactory.setCacheMaxSize("25"); + final DefaultOgnlExpressionCacheFactory expressionFactory = new DefaultOgnlExpressionCacheFactory<>(String.valueOf(25), LRU.toString()); + final DefaultOgnlBeanInfoCacheFactory, BeanInfo> beanInfoFactory = new DefaultOgnlBeanInfoCacheFactory<>(String.valueOf(25), LRU.toString()); result = new OgnlUtil(expressionFactory, beanInfoFactory, new StrutsOgnlGuard()); return result; } @@ -1806,4 +1805,19 @@ public void setTestBeanProperty(String testBeanProperty) { } } + public static OgnlUtil createOgnlUtil() { + return new OgnlUtil( + createDefaultOgnlExpressionCacheFactory(), + createDefaultOgnlBeanInfoCacheFactory(), + new StrutsOgnlGuard() + ); + } + + public static DefaultOgnlExpressionCacheFactory createDefaultOgnlExpressionCacheFactory() { + return new DefaultOgnlExpressionCacheFactory<>(String.valueOf(10_000), BASIC.toString()); + } + + public static DefaultOgnlBeanInfoCacheFactory createDefaultOgnlBeanInfoCacheFactory() { + return new DefaultOgnlBeanInfoCacheFactory<>(String.valueOf(10_000), BASIC.toString()); + } } diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java index 7fb560c5b0..a983b5d261 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java @@ -1061,7 +1061,7 @@ public void testConstructorWithAStack() { OgnlValueStack stack2 = new OgnlValueStack(vs, container.getInstance(XWorkConverter.class), - (CompoundRootAccessor) container.getInstance(RootAccessor.class), true); + (CompoundRootAccessor) container.getInstance(RootAccessor.class), new SecurityMemberAccess(true)); container.inject(stack2); assertEquals(vs.getRoot(), stack2.getRoot()); diff --git a/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java index ab4fdaf84a..3cd0e57ab4 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/CookieInterceptorTest.java @@ -25,11 +25,12 @@ import com.opensymphony.xwork2.mock.MockActionInvocation; import com.opensymphony.xwork2.security.DefaultAcceptedPatternsChecker; import com.opensymphony.xwork2.security.DefaultExcludedPatternsChecker; +import jakarta.servlet.http.Cookie; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsInternalTestCase; +import org.apache.struts2.action.CookiesAware; import org.springframework.mock.web.MockHttpServletRequest; -import jakarta.servlet.http.Cookie; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -451,49 +452,6 @@ protected boolean isAcceptableName(String name) { assertFalse(excludedName.get(reqCookieName)); } - public void testActionCookieAwareWithStrutsInternalsAccess() throws Exception { - MockHttpServletRequest request = new MockHttpServletRequest(); - String sessionCookieName = "session.userId"; - String sessionCookieValue = "session.userId=1"; - String appCookieName = "application.userId"; - String appCookieValue = "application.userId=1"; - String reqCookieName = "request.userId"; - String reqCookieValue = "request.userId=1"; - - request.setCookies( - new Cookie(sessionCookieName, "1"), - new Cookie("1", sessionCookieValue), - new Cookie(appCookieName, "1"), - new Cookie("1", appCookieValue), - new Cookie(reqCookieName, "1"), - new Cookie("1", reqCookieValue) - ); - ServletActionContext.setRequest(request); - - final Map excludedName = new HashMap<>(); - - CookieInterceptor interceptor = new CookieInterceptor() { - @Override - protected boolean isAcceptableName(String name) { - boolean accepted = super.isAcceptableName(name); - excludedName.put(name, accepted); - return accepted; - } - }; - interceptor.setExcludedPatternsChecker(new DefaultExcludedPatternsChecker()); - interceptor.setAcceptedPatternsChecker(new DefaultAcceptedPatternsChecker()); - interceptor.setCookiesName("*"); - - MockActionInvocation invocation = new MockActionInvocation(); - invocation.setAction(new MockActionWithActionCookieAware()); - - interceptor.intercept(invocation); - - assertFalse(excludedName.get(sessionCookieName)); - assertFalse(excludedName.get(appCookieName)); - assertFalse(excludedName.get(reqCookieName)); - } - public static class MockActionWithCookieAware extends ActionSupport implements CookiesAware { private static final long serialVersionUID = -6202290616812813386L; @@ -503,46 +461,7 @@ public static class MockActionWithCookieAware extends ActionSupport implements C private String cookie2; private String cookie3; - public void setCookiesMap(Map cookies) { - this.cookies = cookies; - } - - public Map getCookiesMap() { - return this.cookies; - } - - public String getCookie1() { - return cookie1; - } - - public void setCookie1(String cookie1) { - this.cookie1 = cookie1; - } - - public String getCookie2() { - return cookie2; - } - - public void setCookie2(String cookie2) { - this.cookie2 = cookie2; - } - - public String getCookie3() { - return cookie3; - } - - public void setCookie3(String cookie3) { - this.cookie3 = cookie3; - } - } - - public static class MockActionWithActionCookieAware extends ActionSupport implements org.apache.struts2.action.CookiesAware { - - private Map cookies = Collections.EMPTY_MAP; - private String cookie1; - private String cookie2; - private String cookie3; - + @Override public void withCookies(Map cookies) { this.cookies = cookies; } diff --git a/core/src/test/java/org/apache/struts2/interceptor/parameter/ParametersInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/parameter/ParametersInterceptorTest.java index b15594f956..9bcc70ae00 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/parameter/ParametersInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/parameter/ParametersInterceptorTest.java @@ -36,6 +36,7 @@ import com.opensymphony.xwork2.mock.MockActionInvocation; import com.opensymphony.xwork2.ognl.OgnlValueStack; import com.opensymphony.xwork2.ognl.OgnlValueStackFactory; +import com.opensymphony.xwork2.ognl.SecurityMemberAccess; import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor; import com.opensymphony.xwork2.ognl.accessor.RootAccessor; import com.opensymphony.xwork2.util.ValueStack; @@ -90,7 +91,7 @@ public void testParameterNameAware() { put("test%test", "test%test"); } }; - pi.setParameters(a, stack, HttpParameters.create(parameters).build()); + pi.applyParameters(a, stack, HttpParameters.create(parameters).build()); assertEquals(expected, actual); } @@ -113,7 +114,7 @@ public void testInsecureParameters() throws Exception { // when ValidateAction action = new ValidateAction(); - pi.setParameters(action, vs, HttpParameters.create(params).build()); + pi.applyParameters(action, vs, HttpParameters.create(params).build()); // then assertEquals(3, action.getActionErrors().size()); @@ -160,7 +161,7 @@ protected boolean isExcluded(String paramName) { // when ValidateAction action = new ValidateAction(); - pi.setParameters(action, vs, HttpParameters.create(params).build()); + pi.applyParameters(action, vs, HttpParameters.create(params).build()); // then assertEquals(0, action.getActionMessages().size()); @@ -200,7 +201,7 @@ protected boolean isExcluded(String paramName) { // when ValidateAction action = new ValidateAction(); - pi.setParameters(action, vs, HttpParameters.create(params).build()); + pi.applyParameters(action, vs, HttpParameters.create(params).build()); // then assertEquals(3, action.getActionErrors().size()); @@ -320,7 +321,7 @@ protected boolean isExcluded(String paramName) { // when ValidateAction action = new ValidateAction(); - pi.setParameters(action, vs, HttpParameters.create(params).build()); + pi.applyParameters(action, vs, HttpParameters.create(params).build()); // then assertEquals(0, action.getActionMessages().size()); @@ -435,7 +436,7 @@ private void doTestParameterNameLengthRestriction(ParametersInterceptor paramete parameters.put("huuhaa", ""); Action action = new SimpleAction(); - parametersInterceptor.setParameters(action, stack, HttpParameters.create(parameters).build()); + parametersInterceptor.applyParameters(action, stack, HttpParameters.create(parameters).build()); assertEquals(1, actual.size()); } @@ -629,7 +630,7 @@ public void testNoOrdered() throws Exception { parameters.put("user.name", "Superman"); Action action = new SimpleAction(); - pi.setParameters(action, stack, HttpParameters.create(parameters).build()); + pi.applyParameters(action, stack, HttpParameters.create(parameters).build()); assertEquals("ordered should be false by default", false, pi.isOrdered()); assertEquals(2, actual.size()); @@ -656,7 +657,7 @@ public void testOrdered() throws Exception { parameters.put("user.name", "Superman"); Action action = new SimpleAction(); - pi.setParameters(action, stack, HttpParameters.create(parameters).build()); + pi.applyParameters(action, stack, HttpParameters.create(parameters).build()); assertEquals(true, pi.isOrdered()); assertEquals(3, actual.size()); @@ -696,7 +697,7 @@ public void testExcludedParametersAreIgnored() throws Exception { put("fooKey", "fooValue"); } }; - pi.setParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); + pi.applyParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); assertEquals(expected, actual); } @@ -727,7 +728,7 @@ public void testInternalParametersAreIgnored() throws Exception { }; // when - interceptor.setParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); + interceptor.applyParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); // then assertEquals(expected, actual); @@ -754,7 +755,7 @@ public void testDMIMethodsAreIgnored() throws Exception { }; // when - interceptor.setParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); + interceptor.applyParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); // then assertEquals(expected, actual); @@ -806,7 +807,7 @@ public void testExcludedParametersValuesAreIgnored() throws Exception { put("fooKey2", ""); } }; - pi.setParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); + pi.applyParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); assertEquals(expected, actual); } @@ -843,7 +844,7 @@ public void testAcceptedParametersValuesAreIgnored() throws Exception { put("fooKey2", ""); } }; - pi.setParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); + pi.applyParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); assertEquals(expected, actual); } @@ -882,7 +883,7 @@ public void testAcceptedAndExcludedParametersValuesAreIgnored() throws Exception put("fooKey2", ""); } }; - pi.setParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); + pi.applyParameters(new NoParametersAction(), stack, HttpParameters.create(parameters).build()); assertEquals(expected, actual); } @@ -926,7 +927,7 @@ public boolean acceptableParameterValue(String parameterValue) { put("fooKey3", ""); } }; - pi.setParameters(a, stack, HttpParameters.create(parameters).build()); + pi.applyParameters(a, stack, HttpParameters.create(parameters).build()); assertEquals(expected, actual); } @@ -964,7 +965,7 @@ private ValueStack createStubValueStack(final Map actual) { ValueStack stack = new OgnlValueStack( container.getInstance(XWorkConverter.class), (CompoundRootAccessor) container.getInstance(RootAccessor.class), - container.getInstance(TextProvider.class, "system"), true) { + container.getInstance(TextProvider.class, "system"), new SecurityMemberAccess(true)) { @Override public void setValue(String expr, Object value) { actual.put(expr, value); diff --git a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java index 9c5a7de64e..b567801c72 100644 --- a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java +++ b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java @@ -28,20 +28,24 @@ import com.opensymphony.xwork2.config.entities.ResultConfig; import com.opensymphony.xwork2.mock.MockActionProxy; import com.opensymphony.xwork2.mock.MockInterceptor; +import com.opensymphony.xwork2.ognl.DefaultOgnlBeanInfoCacheFactory; +import com.opensymphony.xwork2.ognl.DefaultOgnlExpressionCacheFactory; import com.opensymphony.xwork2.ognl.OgnlUtil; import com.opensymphony.xwork2.util.XWorkTestCaseHelper; +import jakarta.servlet.http.HttpServletResponse; import junit.framework.TestCase; import org.apache.struts2.ServletActionContext; +import org.apache.struts2.ognl.StrutsOgnlGuard; import org.apache.struts2.result.HttpHeaderResult; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; -import jakarta.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import static com.opensymphony.xwork2.ognl.OgnlCacheFactory.CacheType.BASIC; import static jakarta.servlet.http.HttpServletResponse.SC_NOT_MODIFIED; public class RestActionInvocationTest extends TestCase { @@ -53,7 +57,7 @@ public class RestActionInvocationTest extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - + restActionInvocation = new RestActionInvocationTester(); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); @@ -61,7 +65,7 @@ protected void setUp() throws Exception { ServletActionContext.setResponse(response); } - + /** * Test the correct action results: null, String, HttpHeaders, Result * @throws Exception @@ -71,12 +75,12 @@ public void testSaveResult() throws Exception { Object methodResult = "index"; ActionConfig actionConfig = restActionInvocation.getProxy().getConfig(); assertEquals("index", restActionInvocation.saveResult(actionConfig, methodResult)); - + setUp(); methodResult = new DefaultHttpHeaders("show"); assertEquals("show", restActionInvocation.saveResult(actionConfig, methodResult)); assertEquals(methodResult, restActionInvocation.httpHeaders); - + setUp(); methodResult = new HttpHeaderResult(HttpServletResponse.SC_ACCEPTED); assertEquals(null, restActionInvocation.saveResult(actionConfig, methodResult)); @@ -89,18 +93,18 @@ public void testSaveResult() throws Exception { // ko assertFalse(true); - + } catch (ConfigurationException c) { // ok, object not allowed } } - + /** * Test the target selection: exception, error messages, model and null * @throws Exception */ public void testSelectTarget() throws Exception { - + // Exception Exception e = new Exception(); restActionInvocation.getStack().set("exception", e); @@ -118,7 +122,7 @@ public void testSelectTarget() throws Exception { errors.put("actionErrors", list); restActionInvocation.selectTarget(); assertEquals(errors, restActionInvocation.target); - + // Model with get and no content in post, put, delete setUp(); RestAction restAction = (RestAction)restActionInvocation.getAction(); @@ -168,18 +172,18 @@ public int hashCode() { }; model.add("Item"); restAction.model = model; - + restActionInvocation.processResult(); assertEquals(SC_NOT_MODIFIED, response.getStatus()); - + } - + /** * Test the default error result. * @throws Exception */ public void testDefaultErrorResult() throws Exception { - + // Exception Exception e = new Exception(); restActionInvocation.getStack().set("exception", e); @@ -189,24 +193,24 @@ public void testDefaultErrorResult() throws Exception { List model = new ArrayList(); model.add("Item"); restAction.model = model; - + restActionInvocation.setDefaultErrorResultName("default-error"); - ResultConfig resultConfig = new ResultConfig.Builder("default-error", + ResultConfig resultConfig = new ResultConfig.Builder("default-error", "org.apache.struts2.result.HttpHeaderResult") .addParam("status", "123").build(); - ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", + ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", "RestAction", "org.apache.rest.RestAction") .addResultConfig(resultConfig) .build(); ((MockActionProxy)restActionInvocation.getProxy()).setConfig(actionConfig); - + restActionInvocation.processResult(); assertEquals(123, response.getStatus()); - + } - + public void testNoResult() throws Exception { - + RestAction restAction = (RestAction)restActionInvocation.getAction(); List model = new ArrayList(); model.add("Item"); @@ -219,35 +223,39 @@ public void testNoResult() throws Exception { // ko assertFalse(true); - + } catch (ConfigurationException c) { // ok, no result } } - + /** * Test the global execution * @throws Exception */ public void testInvoke() throws Exception { - + // Default index method return 'success' ((MockActionProxy)restActionInvocation.getProxy()).setMethod("index"); // Define result 'success' - ResultConfig resultConfig = new ResultConfig.Builder("success", + ResultConfig resultConfig = new ResultConfig.Builder("success", "org.apache.struts2.result.HttpHeaderResult") .addParam("status", "123").build(); - ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", + ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", "RestAction", "org.apache.rest.RestAction") .addResultConfig(resultConfig) .build(); ((MockActionProxy)restActionInvocation.getProxy()).setConfig(actionConfig); request.setMethod("GET"); - - restActionInvocation.setOgnlUtil(new OgnlUtil()); + + restActionInvocation.setOgnlUtil(new OgnlUtil( + new DefaultOgnlExpressionCacheFactory<>(String.valueOf(10_000), BASIC.toString()), + new DefaultOgnlBeanInfoCacheFactory<>(String.valueOf(10_000), BASIC.toString()), + new StrutsOgnlGuard() + )); restActionInvocation.invoke(); assertEquals(123, response.getStatus()); @@ -264,7 +272,7 @@ class RestActionInvocationTester extends RestActionInvocation { interceptorMappings.add(new InterceptorMapping("interceptor", mockInterceptor)); interceptors = interceptorMappings.iterator(); MockActionProxy actionProxy = new MockActionProxy(); - ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", + ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", "RestAction", "org.apache.rest.RestAction").build(); actionProxy.setConfig(actionConfig); proxy = actionProxy; @@ -280,18 +288,18 @@ class RestActionInvocationTester extends RestActionInvocation { container = ActionContext.getContext().getContainer(); stack = ActionContext.getContext().getValueStack(); objectFactory = container.getInstance(ObjectFactory.class); - + } - + } class RestAction extends RestActionSupport implements ModelDriven> { List model; - + public List getModel() { return model; } - + } } diff --git a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsVelocityDecorator.java b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsVelocityDecorator.java index 6168b29c09..d51745fa0e 100644 --- a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsVelocityDecorator.java +++ b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsVelocityDecorator.java @@ -23,16 +23,15 @@ import com.opensymphony.sitemesh.compatability.Content2HTMLPage; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.inject.Inject; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.struts2.views.velocity.VelocityManager; import org.apache.struts2.views.velocity.VelocityManagerInterface; import org.apache.velocity.context.Context; -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; @@ -49,14 +48,6 @@ public static void setVelocityManager(VelocityManagerInterface mgr) { velocityManager = mgr; } - /** - * @deprecated since 6.4.0 - */ - @Deprecated - public static void setVelocityManager(VelocityManager mgr) { - setVelocityManager((VelocityManagerInterface) mgr); - } - public OldDecorator2NewStrutsVelocityDecorator(com.opensymphony.module.sitemesh.Decorator oldDecorator) { this.oldDecorator = oldDecorator; } diff --git a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java index 71e04b329a..c2549801b3 100644 --- a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java +++ b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java @@ -24,29 +24,19 @@ import com.opensymphony.sitemesh.webapp.SiteMeshFilter; import com.opensymphony.sitemesh.webapp.SiteMeshWebAppContext; import com.opensymphony.xwork2.inject.Inject; -import org.apache.struts2.views.velocity.VelocityManager; +import jakarta.servlet.FilterConfig; import org.apache.struts2.views.velocity.VelocityManagerInterface; -import jakarta.servlet.*; - /** * Core Filter for integrating SiteMesh into a Java web application. */ public class VelocityPageFilter extends SiteMeshFilter { - @Inject(required=false) + @Inject(required = false) public static void setVelocityManager(VelocityManagerInterface mgr) { OldDecorator2NewStrutsVelocityDecorator.setVelocityManager(mgr); } - /** - * @deprecated since 6.4.0 - */ - @Deprecated - public static void setVelocityManager(VelocityManager mgr) { - setVelocityManager((VelocityManagerInterface) mgr); - } - private FilterConfig filterConfig; public void init(FilterConfig filterConfig) { diff --git a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/result/VelocityResult.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/result/VelocityResult.java index cb7a1f56d9..a89ad6ce31 100644 --- a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/result/VelocityResult.java +++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/result/VelocityResult.java @@ -22,24 +22,23 @@ import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.ValueStack; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContext; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.jsp.JspFactory; +import jakarta.servlet.jsp.PageContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsConstants; import org.apache.struts2.result.StrutsResultSupport; import org.apache.struts2.views.JspSupportServlet; -import org.apache.struts2.views.velocity.VelocityManager; import org.apache.struts2.views.velocity.VelocityManagerInterface; import org.apache.velocity.Template; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.context.Context; -import jakarta.servlet.Servlet; -import jakarta.servlet.ServletContext; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.servlet.jsp.JspFactory; -import jakarta.servlet.jsp.PageContext; import java.io.OutputStreamWriter; import java.io.Writer; @@ -109,14 +108,6 @@ public void setVelocityManager(VelocityManagerInterface mgr) { this.velocityManager = mgr; } - /** - * @deprecated since 6.4.0 - */ - @Deprecated - public void setVelocityManager(VelocityManager mgr) { - setVelocityManager((VelocityManagerInterface) mgr); - } - /** * Creates a Velocity context from the action, loads a Velocity template and executes the * template. Output is written to the servlet output stream. @@ -248,16 +239,4 @@ protected Context createContext(VelocityManagerInterface velocityManager, String location) { return velocityManager.createContext(stack, request, response); } - - /** - * @deprecated since 6.4.0 - */ - @Deprecated - protected Context createContext(VelocityManager velocityManager, - ValueStack stack, - HttpServletRequest request, - HttpServletResponse response, - String location) { - return createContext((VelocityManagerInterface) velocityManager, stack, request, response, location); - } } diff --git a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/template/VelocityTemplateEngine.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/template/VelocityTemplateEngine.java index f6e0481f8f..bc0bb4268c 100644 --- a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/template/VelocityTemplateEngine.java +++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/template/VelocityTemplateEngine.java @@ -19,20 +19,19 @@ package org.apache.struts2.views.velocity.template; import com.opensymphony.xwork2.inject.Inject; +import jakarta.servlet.ServletContext; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.ServletActionContext; import org.apache.struts2.components.template.BaseTemplateEngine; import org.apache.struts2.components.template.Template; import org.apache.struts2.components.template.TemplateRenderingContext; -import org.apache.struts2.views.velocity.VelocityManager; import org.apache.struts2.views.velocity.VelocityManagerInterface; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.context.Context; -import jakarta.servlet.ServletContext; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import java.io.Writer; import java.util.List; import java.util.Map; @@ -50,14 +49,6 @@ public void setVelocityManager(VelocityManagerInterface mgr) { this.velocityManager = mgr; } - /** - * @deprecated since 6.4.0 - */ - @Deprecated - public void setVelocityManager(VelocityManager mgr) { - setVelocityManager((VelocityManagerInterface) mgr); - } - public void renderTemplate(TemplateRenderingContext templateContext) throws Exception { // get the various items required from the stack Map actionContext = templateContext.getStack().getContext();