This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/main by this push: new e32679953 WW-5544 Marks ReflectionContextFactory as deprecated and uses ActionContext instead (#1254) (#1255) e32679953 is described below commit e3267995328bfa4f77514f821069b3b0ed06a7ca Author: Lukasz Lenart <lukaszlen...@apache.org> AuthorDate: Sun Apr 27 18:43:36 2025 +0200 WW-5544 Marks ReflectionContextFactory as deprecated and uses ActionContext instead (#1254) (#1255) --- .../apache/struts2/ognl/OgnlReflectionContextFactory.java | 4 ++++ .../struts2/util/reflection/ReflectionContextFactory.java | 4 ++++ .../struts2/config_browser/ShowValidatorAction.java | 15 +++++---------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/ognl/OgnlReflectionContextFactory.java b/core/src/main/java/org/apache/struts2/ognl/OgnlReflectionContextFactory.java index 92f079335..4b32e7602 100644 --- a/core/src/main/java/org/apache/struts2/ognl/OgnlReflectionContextFactory.java +++ b/core/src/main/java/org/apache/struts2/ognl/OgnlReflectionContextFactory.java @@ -23,6 +23,10 @@ import ognl.Ognl; import java.util.Map; +/** + * @deprecated since 6.8.0, to be removed, see {@link ReflectionContextFactory} + */ +@Deprecated(since = "6.8.0", forRemoval = true) public class OgnlReflectionContextFactory implements ReflectionContextFactory { @Override diff --git a/core/src/main/java/org/apache/struts2/util/reflection/ReflectionContextFactory.java b/core/src/main/java/org/apache/struts2/util/reflection/ReflectionContextFactory.java index 5b0075f3b..e33c50a8f 100644 --- a/core/src/main/java/org/apache/struts2/util/reflection/ReflectionContextFactory.java +++ b/core/src/main/java/org/apache/struts2/util/reflection/ReflectionContextFactory.java @@ -20,6 +20,10 @@ package org.apache.struts2.util.reflection; import java.util.Map; +/** + * @deprecated since 6.8.0, avoid using this interface and any of its implementation, it's going to be removed soon + */ +@Deprecated(since = "6.8.0", forRemoval = true) public interface ReflectionContextFactory { /** * Creates and returns a new standard naming context for evaluating an OGNL diff --git a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java index 8a84f6a56..08f38d34d 100644 --- a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java +++ b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowValidatorAction.java @@ -25,6 +25,7 @@ import org.apache.struts2.util.reflection.ReflectionProvider; import org.apache.struts2.validator.Validator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.struts2.ActionContext; import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.beans.BeanInfo; @@ -49,19 +50,13 @@ public class ShowValidatorAction extends ListValidatorsAction { private Set<PropertyInfo> properties = Collections.emptySet(); private int selected = 0; - ReflectionProvider reflectionProvider; - ReflectionContextFactory reflectionContextFactory; + private ReflectionProvider reflectionProvider; @Inject public void setReflectionProvider(ReflectionProvider prov) { this.reflectionProvider = prov; } - @Inject - public void setReflectionContextFactory(ReflectionContextFactory fac) { - this.reflectionContextFactory = fac; - } - public int getSelected() { return selected; } @@ -85,7 +80,6 @@ public class ShowValidatorAction extends ListValidatorsAction { Validator validator = getSelectedValidator(); properties = new TreeSet<>(); try { - Map<String, Object> context = reflectionContextFactory.createDefaultContext(validator); BeanInfo beanInfoFrom; try { beanInfoFrom = Introspector.getBeanInfo(validator.getClass(), Object.class); @@ -97,6 +91,7 @@ public class ShowValidatorAction extends ListValidatorsAction { PropertyDescriptor[] pds = beanInfoFrom.getPropertyDescriptors(); + Map<String, Object> context = ActionContext.getContext().getContextMap(); for (PropertyDescriptor pd : pds) { String name = pd.getName(); Object value = null; @@ -113,9 +108,9 @@ public class ShowValidatorAction extends ListValidatorsAction { } } catch (Exception e) { if (LOG.isWarnEnabled()) { - LOG.warn("Unable to retrieve properties.", e); + LOG.warn("Unable to retrieve properties.", e); } - addActionError("Unable to retrieve properties: " + e.toString()); + addActionError("Unable to retrieve properties: " + e); } if (hasErrors()) {