You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2025/04/27 14:04:10 UTC
(struts) 01/01: WW-5544 Marks ReflectionContextFactory as deprecated and uses ActionContext instead (#1254)
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch feature/WW-5544-context-factory-s7
in repository https://gitbox.apache.org/repos/asf/struts.git
commit dad1f3541abc97d70320d138ee24a133b1b2deac
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sun Apr 27 15:59:19 2025 +0200
WW-5544 Marks ReflectionContextFactory as deprecated and uses ActionContext instead (#1254)
---
.../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..6c0aabbf8 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
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..f9f26bad2 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
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()) {