mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
Merge remote-tracking branch 'origin/master' into 7.0.x/merge-master-2024-07-20
This commit is contained in:
+2
@@ -19,6 +19,7 @@
|
||||
package org.apache.struts.beanvalidation.actions;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.parameter.StrutsParameter;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
public class FieldAction extends ActionSupport {
|
||||
@@ -30,6 +31,7 @@ public class FieldAction extends ActionSupport {
|
||||
return test;
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setTest(String test) {
|
||||
this.test = test;
|
||||
}
|
||||
|
||||
+5
@@ -20,6 +20,7 @@ package org.apache.struts.beanvalidation.actions;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts.beanvalidation.constraints.FieldMatch;
|
||||
import org.apache.struts2.interceptor.parameter.StrutsParameter;
|
||||
import org.hibernate.validator.constraints.Email;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
@@ -48,6 +49,7 @@ public class FieldMatchAction extends ActionSupport {
|
||||
return password;
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
@@ -56,6 +58,7 @@ public class FieldMatchAction extends ActionSupport {
|
||||
return confirmPassword;
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setConfirmPassword(String confirmPassword) {
|
||||
this.confirmPassword = confirmPassword;
|
||||
}
|
||||
@@ -64,6 +67,7 @@ public class FieldMatchAction extends ActionSupport {
|
||||
return email;
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
@@ -72,6 +76,7 @@ public class FieldMatchAction extends ActionSupport {
|
||||
return confirmEmail;
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setConfirmEmail(String confirmEmail) {
|
||||
this.confirmEmail = confirmEmail;
|
||||
}
|
||||
|
||||
+4
-1
@@ -21,14 +21,17 @@ package org.apache.struts.beanvalidation.actions;
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.ModelDriven;
|
||||
import org.apache.struts.beanvalidation.models.Person;
|
||||
import org.apache.struts2.interceptor.parameter.StrutsParameter;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
public class ModelDrivenAction extends ActionSupport implements ModelDriven<Person>, ModelDrivenActionInterface {
|
||||
|
||||
@Valid
|
||||
private Person model = new Person();
|
||||
private final Person model = new Person();
|
||||
|
||||
@StrutsParameter(depth = 2)
|
||||
@Override
|
||||
public Person getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
+5
-2
@@ -22,14 +22,17 @@ import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.ModelDriven;
|
||||
import org.apache.struts.beanvalidation.constraints.ValidationGroup;
|
||||
import org.apache.struts.beanvalidation.models.Person;
|
||||
import org.apache.struts2.interceptor.parameter.StrutsParameter;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
public class ValidateGroupAction extends ActionSupport implements ModelDriven<Person> {
|
||||
|
||||
@Valid
|
||||
private Person model = new Person();
|
||||
private final Person model = new Person();
|
||||
|
||||
@StrutsParameter(depth = 2)
|
||||
@Override
|
||||
public Person getModel() {
|
||||
return model;
|
||||
}
|
||||
@@ -67,4 +70,4 @@ public class ValidateGroupAction extends ActionSupport implements ModelDriven<Pe
|
||||
public String actionLongNameChecks() {
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -23,6 +23,7 @@ import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.interceptor.parameter.StrutsParameter;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
@@ -54,6 +55,7 @@ public class ActionNamesAction extends ActionSupport {
|
||||
return StringEscapeUtils.escapeHtml4(namespace);
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
@@ -81,9 +83,10 @@ public class ActionNamesAction extends ActionSupport {
|
||||
return extension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute() throws Exception {
|
||||
namespaces = configHelper.getNamespaces();
|
||||
if (namespaces.size() == 0) {
|
||||
if (namespaces.isEmpty()) {
|
||||
addActionError("There are no namespaces in this configuration");
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
+6
-2
@@ -26,6 +26,7 @@ import com.opensymphony.xwork2.validator.ActionValidatorManager;
|
||||
import com.opensymphony.xwork2.validator.Validator;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.interceptor.parameter.StrutsParameter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -43,16 +44,17 @@ public class ListValidatorsAction extends ActionSupport {
|
||||
List<Validator> validators = Collections.emptyList();
|
||||
private ActionValidatorManager actionValidatorManager;
|
||||
|
||||
|
||||
|
||||
@Inject
|
||||
public void setActionValidatorManager(ActionValidatorManager mgr) {
|
||||
this.actionValidatorManager = mgr;
|
||||
}
|
||||
|
||||
|
||||
public String getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setClazz(String clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
@@ -69,6 +71,7 @@ public class ListValidatorsAction extends ActionSupport {
|
||||
return context;
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setContext(String context) {
|
||||
this.context = context;
|
||||
}
|
||||
@@ -77,6 +80,7 @@ public class ListValidatorsAction extends ActionSupport {
|
||||
return validators;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute() throws Exception {
|
||||
loadValidators();
|
||||
return super.execute();
|
||||
|
||||
+2
@@ -46,6 +46,7 @@ public class ShowBeansAction extends ActionNamesAction {
|
||||
Map<String, Set<Binding>> bindings;
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setContainer(Container container) {
|
||||
super.setContainer(container);
|
||||
bindings = new TreeMap<>();
|
||||
@@ -123,6 +124,7 @@ public class ShowBeansAction extends ActionNamesAction {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Binding b2) {
|
||||
int ret;
|
||||
if (isDefault) {
|
||||
|
||||
+16
-9
@@ -21,10 +21,11 @@ package org.apache.struts2.config_browser;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.interceptor.parameter.StrutsParameter;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.Set;
|
||||
@@ -43,8 +44,8 @@ public class ShowConfigAction extends ActionNamesAction {
|
||||
private Set<String> actionNames;
|
||||
private String detailView = "results";
|
||||
private PropertyDescriptor[] properties;
|
||||
private static Logger LOG = LogManager.getLogger(ShowConfigAction.class);
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(ShowConfigAction.class);
|
||||
|
||||
private ObjectFactory objectFactory;
|
||||
private ReflectionProvider reflectionProvider;
|
||||
|
||||
@@ -52,23 +53,26 @@ public class ShowConfigAction extends ActionNamesAction {
|
||||
return detailView;
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setDetailView(String detailView) {
|
||||
this.detailView = detailView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getActionNames() {
|
||||
return actionNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return StringEscapeUtils.escapeHtml4(namespace);
|
||||
}
|
||||
|
||||
|
||||
@Inject
|
||||
public void setObjectFactory(ObjectFactory fac) {
|
||||
this.objectFactory = fac;
|
||||
}
|
||||
|
||||
|
||||
@Inject
|
||||
public void setReflectionProvider(ReflectionProvider prov) {
|
||||
this.reflectionProvider = prov;
|
||||
@@ -78,6 +82,7 @@ public class ShowConfigAction extends ActionNamesAction {
|
||||
return clazz.getName().substring(clazz.getName().lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
@@ -86,6 +91,7 @@ public class ShowConfigAction extends ActionNamesAction {
|
||||
return actionName;
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setActionName(String actionName) {
|
||||
this.actionName = actionName;
|
||||
}
|
||||
@@ -98,16 +104,17 @@ public class ShowConfigAction extends ActionNamesAction {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute() throws Exception {
|
||||
super.execute();
|
||||
config = configHelper.getActionConfig(namespace, actionName);
|
||||
actionNames = new TreeSet<String>(configHelper.getActionNames(namespace));
|
||||
actionNames = new TreeSet<>(configHelper.getActionNames(namespace));
|
||||
try {
|
||||
Object action = objectFactory.buildAction(actionName, namespace, config, null);
|
||||
properties = reflectionProvider.getPropertyDescriptors(action);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Unable to get properties for action " + actionName, e);
|
||||
addActionError("Unable to retrieve action properties: " + e.toString());
|
||||
LOG.error("Unable to get properties for action {}", actionName, e);
|
||||
addActionError("Unable to retrieve action properties: " + e);
|
||||
}
|
||||
|
||||
if (hasErrors()) //super might have set some :)
|
||||
|
||||
+15
-9
@@ -19,12 +19,13 @@
|
||||
package org.apache.struts2.config_browser;
|
||||
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextFactory;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionException;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
|
||||
import com.opensymphony.xwork2.validator.Validator;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.interceptor.parameter.StrutsParameter;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
@@ -32,6 +33,7 @@ import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@@ -42,11 +44,11 @@ import java.util.TreeSet;
|
||||
public class ShowValidatorAction extends ListValidatorsAction {
|
||||
private static final long serialVersionUID = 4061534149317835177L;
|
||||
|
||||
private static Logger LOG = LogManager.getLogger(ShowValidatorAction.class);
|
||||
private static final Logger LOG = LogManager.getLogger(ShowValidatorAction.class);
|
||||
|
||||
private Set<PropertyInfo> properties = Collections.emptySet();
|
||||
private int selected = 0;
|
||||
|
||||
|
||||
ReflectionProvider reflectionProvider;
|
||||
ReflectionContextFactory reflectionContextFactory;
|
||||
|
||||
@@ -54,16 +56,17 @@ public class ShowValidatorAction extends ListValidatorsAction {
|
||||
public void setReflectionProvider(ReflectionProvider prov) {
|
||||
this.reflectionProvider = prov;
|
||||
}
|
||||
|
||||
|
||||
@Inject
|
||||
public void setReflectionContextFactory(ReflectionContextFactory fac) {
|
||||
this.reflectionContextFactory = fac;
|
||||
}
|
||||
|
||||
|
||||
public int getSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
@StrutsParameter
|
||||
public void setSelected(int selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
@@ -76,10 +79,11 @@ public class ShowValidatorAction extends ListValidatorsAction {
|
||||
return validators.get(selected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute() throws Exception {
|
||||
loadValidators();
|
||||
Validator validator = getSelectedValidator();
|
||||
properties = new TreeSet<PropertyInfo>();
|
||||
properties = new TreeSet<>();
|
||||
try {
|
||||
Map<String, Object> context = reflectionContextFactory.createDefaultContext(validator);
|
||||
BeanInfo beanInfoFrom;
|
||||
@@ -162,6 +166,7 @@ public class ShowValidatorAction extends ListValidatorsAction {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof PropertyInfo)) return false;
|
||||
@@ -170,11 +175,11 @@ public class ShowValidatorAction extends ListValidatorsAction {
|
||||
|
||||
if (!name.equals(propertyInfo.name)) return false;
|
||||
if (!type.equals(propertyInfo.type)) return false;
|
||||
if (value != null ? !value.equals(propertyInfo.value) : propertyInfo.value != null) return false;
|
||||
|
||||
return true;
|
||||
return Objects.equals(value, propertyInfo.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = name.hashCode();
|
||||
@@ -183,6 +188,7 @@ public class ShowValidatorAction extends ListValidatorsAction {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
PropertyInfo other = (PropertyInfo) o;
|
||||
return this.name.compareTo(other.name);
|
||||
|
||||
+9
-2
@@ -36,7 +36,7 @@ import org.apache.struts2.dispatcher.DispatcherListener;
|
||||
* </p>
|
||||
*/
|
||||
public class ClasspathConfigurationProvider implements ConfigurationProvider, DispatcherListener {
|
||||
private ActionConfigBuilder actionConfigBuilder;
|
||||
private final ActionConfigBuilder actionConfigBuilder;
|
||||
private boolean devMode;
|
||||
private boolean reload;
|
||||
private boolean listeningToDispatcher;
|
||||
@@ -59,6 +59,7 @@ public class ClasspathConfigurationProvider implements ConfigurationProvider, Di
|
||||
/**
|
||||
* Not used.
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (this.listeningToDispatcher) {
|
||||
Dispatcher.removeDispatcherListener(this);
|
||||
@@ -71,6 +72,7 @@ public class ClasspathConfigurationProvider implements ConfigurationProvider, Di
|
||||
*
|
||||
* @param configuration configuration
|
||||
*/
|
||||
@Override
|
||||
public void init(Configuration configuration) {
|
||||
if (devMode && reload && !listeningToDispatcher) {
|
||||
//this is the only way I found to be able to get added to to ConfigurationProvider list
|
||||
@@ -88,6 +90,7 @@ public class ClasspathConfigurationProvider implements ConfigurationProvider, Di
|
||||
*
|
||||
* @throws ConfigurationException in case of configuration errors
|
||||
*/
|
||||
@Override
|
||||
public void register(ContainerBuilder containerBuilder, LocatableProperties locatableProperties)
|
||||
throws ConfigurationException {
|
||||
}
|
||||
@@ -97,20 +100,24 @@ public class ClasspathConfigurationProvider implements ConfigurationProvider, Di
|
||||
*
|
||||
* @throws ConfigurationException in case of configuration errors
|
||||
*/
|
||||
@Override
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if devMode, reload and actionConfigBuilder.needsReload()
|
||||
*/
|
||||
@Override
|
||||
public boolean needsReload() {
|
||||
return devMode && reload && actionConfigBuilder.needsReload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatcherInitialized(Dispatcher du) {
|
||||
du.getConfigurationManager().addContainerProvider(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatcherDestroyed(Dispatcher du) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -18,11 +18,11 @@
|
||||
*/
|
||||
package org.apache.struts2.convention;
|
||||
|
||||
import com.opensymphony.xwork2.config.PackageProvider;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.config.PackageProvider;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -34,20 +34,23 @@ import com.opensymphony.xwork2.inject.Container;
|
||||
* </p>
|
||||
*/
|
||||
public class ClasspathPackageProvider implements PackageProvider {
|
||||
private ActionConfigBuilder actionConfigBuilder;
|
||||
private final ActionConfigBuilder actionConfigBuilder;
|
||||
|
||||
@Inject
|
||||
public ClasspathPackageProvider(Container container) {
|
||||
this.actionConfigBuilder = container.getInstance(ActionConfigBuilder.class, container.getInstance(String.class, ConventionConstants.CONVENTION_ACTION_CONFIG_BUILDER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsReload() {
|
||||
return actionConfigBuilder.needsReload();
|
||||
return actionConfigBuilder.needsReload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
actionConfigBuilder.buildActionConfigs();
|
||||
}
|
||||
|
||||
+43
-22
@@ -24,6 +24,7 @@ import com.opensymphony.xwork2.FileManagerFactory;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.ConfigurationUtil;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
|
||||
@@ -57,6 +58,7 @@ import org.apache.struts2.convention.annotation.ExceptionMappings;
|
||||
import org.apache.struts2.convention.annotation.Namespace;
|
||||
import org.apache.struts2.convention.annotation.Namespaces;
|
||||
import org.apache.struts2.convention.annotation.ParentPackage;
|
||||
import org.apache.struts2.ognl.ProviderAllowlist;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -125,6 +127,9 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
private FileManager fileManager;
|
||||
private ClassFinderFactory classFinderFactory;
|
||||
|
||||
private final Set<Class<?>> allowlistClasses = new HashSet<>();
|
||||
private ProviderAllowlist providerAllowlist;
|
||||
|
||||
/**
|
||||
* Constructs actions based on a list of packages.
|
||||
*
|
||||
@@ -167,6 +172,11 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
this.devMode = BooleanUtils.toBoolean(mode);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setProviderAllowlist(ProviderAllowlist providerAllowlist) {
|
||||
this.providerAllowlist = providerAllowlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reload Reload configuration when classes change. Defaults to "false" and should not be used
|
||||
* in production.
|
||||
@@ -345,33 +355,38 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
* annotation which is used to control the parent package for a specific action. Lastly, the
|
||||
* {@link ResultMapBuilder} is used to create ResultConfig instances of the action.
|
||||
*/
|
||||
@Override
|
||||
public void buildActionConfigs() {
|
||||
allowlistClasses.clear();
|
||||
|
||||
//setup reload class loader based on dev settings
|
||||
initReloadClassLoader();
|
||||
|
||||
if (!disableActionScanning) {
|
||||
if (actionPackages == null && packageLocators == null) {
|
||||
throw new ConfigurationException("At least a list of action packages or action package locators " +
|
||||
"must be given using one of the properties [struts.convention.action.packages] or " +
|
||||
"[struts.convention.package.locators]");
|
||||
}
|
||||
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("Loading action configurations");
|
||||
if (actionPackages != null) {
|
||||
LOG.trace("Actions being loaded from action packages: {}", (Object[]) actionPackages);
|
||||
}
|
||||
if (packageLocators != null) {
|
||||
LOG.trace("Actions being loaded using package locator's: {}", (Object[]) packageLocators);
|
||||
}
|
||||
if (excludePackages != null) {
|
||||
LOG.trace("Excluding actions from packages: {}", (Object[]) excludePackages);
|
||||
}
|
||||
}
|
||||
|
||||
Set<Class<?>> classes = findActions();
|
||||
buildConfiguration(classes);
|
||||
if (disableActionScanning) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (actionPackages == null && packageLocators == null) {
|
||||
throw new ConfigurationException("At least a list of action packages or action package locators " +
|
||||
"must be given using one of the properties [struts.convention.action.packages] or " +
|
||||
"[struts.convention.package.locators]");
|
||||
}
|
||||
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("Loading action configurations");
|
||||
if (actionPackages != null) {
|
||||
LOG.trace("Actions being loaded from action packages: {}", (Object[]) actionPackages);
|
||||
}
|
||||
if (packageLocators != null) {
|
||||
LOG.trace("Actions being loaded using package locator's: {}", (Object[]) packageLocators);
|
||||
}
|
||||
if (excludePackages != null) {
|
||||
LOG.trace("Excluding actions from packages: {}", (Object[]) excludePackages);
|
||||
}
|
||||
}
|
||||
|
||||
Set<Class<?>> classes = findActions();
|
||||
buildConfiguration(classes);
|
||||
}
|
||||
|
||||
protected ClassLoaderInterface getClassLoaderInterface() {
|
||||
@@ -765,7 +780,10 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
} else if (actionAnnotation != null)
|
||||
createActionConfig(defaultPackageConfig, actionClass, defaultActionName, methodName, actionAnnotation, allowedMethods);
|
||||
}
|
||||
|
||||
allowlistClasses.addAll(ConfigurationUtil.getAllClassTypes(actionClass));
|
||||
}
|
||||
providerAllowlist.registerAllowlist(this, allowlistClasses);
|
||||
|
||||
buildIndexActions(packageConfigs);
|
||||
|
||||
@@ -1153,10 +1171,13 @@ public class PackageBasedActionConfigBuilder implements ActionConfigBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
loadedFileUrls.clear();
|
||||
providerAllowlist.clearAllowlist(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsReload() {
|
||||
if (devMode && reload) {
|
||||
for (String url : loadedFileUrls) {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class MessageAction extends ActionSupport {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String execute() {
|
||||
message = "Hello World";
|
||||
return SUCCESS;
|
||||
|
||||
+45
-7
@@ -18,9 +18,21 @@
|
||||
*/
|
||||
package org.apache.struts2.convention;
|
||||
|
||||
import com.opensymphony.xwork2.*;
|
||||
import com.opensymphony.xwork2.ActionChainResult;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.FileManager;
|
||||
import com.opensymphony.xwork2.FileManagerFactory;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.entities.*;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ExceptionMappingConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorConfig;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorMapping;
|
||||
import com.opensymphony.xwork2.config.entities.InterceptorStackConfig;
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultTypeConfig;
|
||||
import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
|
||||
import com.opensymphony.xwork2.factory.DefaultInterceptorFactory;
|
||||
import com.opensymphony.xwork2.factory.DefaultResultFactory;
|
||||
@@ -32,12 +44,20 @@ import com.opensymphony.xwork2.util.fs.DefaultFileManager;
|
||||
import com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionException;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.struts2.convention.actions.DefaultResultPathAction;
|
||||
import org.apache.struts2.convention.actions.NoAnnotationAction;
|
||||
import org.apache.struts2.convention.actions.Skip;
|
||||
import org.apache.struts2.convention.actions.action.*;
|
||||
import org.apache.struts2.convention.actions.action.ActionNameAction;
|
||||
import org.apache.struts2.convention.actions.action.ActionNamesAction;
|
||||
import org.apache.struts2.convention.actions.action.ClassLevelAnnotationAction;
|
||||
import org.apache.struts2.convention.actions.action.ClassLevelAnnotationDefaultMethodAction;
|
||||
import org.apache.struts2.convention.actions.action.ClassLevelAnnotationsAction;
|
||||
import org.apache.struts2.convention.actions.action.ClassLevelAnnotationsDefaultMethodAction;
|
||||
import org.apache.struts2.convention.actions.action.ClassNameAction;
|
||||
import org.apache.struts2.convention.actions.action.SingleActionNameAction;
|
||||
import org.apache.struts2.convention.actions.action.TestAction;
|
||||
import org.apache.struts2.convention.actions.action.TestExtends;
|
||||
import org.apache.struts2.convention.actions.allowedmethods.ClassLevelAllowedMethodsAction;
|
||||
import org.apache.struts2.convention.actions.allowedmethods.PackageLevelAllowedMethodsAction;
|
||||
import org.apache.struts2.convention.actions.allowedmethods.sub.PackageLevelAllowedMethodsChildAction;
|
||||
@@ -61,7 +81,15 @@ import org.apache.struts2.convention.actions.parentpackage.ClassLevelParentPacka
|
||||
import org.apache.struts2.convention.actions.parentpackage.PackageLevelParentPackageAction;
|
||||
import org.apache.struts2.convention.actions.parentpackage.sub.ClassLevelParentPackageChildAction;
|
||||
import org.apache.struts2.convention.actions.parentpackage.sub.PackageLevelParentPackageChildAction;
|
||||
import org.apache.struts2.convention.actions.result.*;
|
||||
import org.apache.struts2.convention.actions.result.ActionLevelResultAction;
|
||||
import org.apache.struts2.convention.actions.result.ActionLevelResultsAction;
|
||||
import org.apache.struts2.convention.actions.result.ActionLevelResultsNamesAction;
|
||||
import org.apache.struts2.convention.actions.result.ClassLevelResultAction;
|
||||
import org.apache.struts2.convention.actions.result.ClassLevelResultsAction;
|
||||
import org.apache.struts2.convention.actions.result.GlobalResultAction;
|
||||
import org.apache.struts2.convention.actions.result.GlobalResultOverrideAction;
|
||||
import org.apache.struts2.convention.actions.result.InheritedResultExtends;
|
||||
import org.apache.struts2.convention.actions.result.OverrideResultAction;
|
||||
import org.apache.struts2.convention.actions.resultpath.ClassLevelResultPathAction;
|
||||
import org.apache.struts2.convention.actions.resultpath.PackageLevelResultPathAction;
|
||||
import org.apache.struts2.convention.actions.skip.Index;
|
||||
@@ -69,15 +97,24 @@ import org.apache.struts2.convention.actions.transactions.TransNameAction;
|
||||
import org.apache.struts2.convention.annotation.Action;
|
||||
import org.apache.struts2.convention.annotation.Actions;
|
||||
import org.apache.struts2.convention.dontfind.DontFindMeAction;
|
||||
import org.apache.struts2.ognl.ProviderAllowlist;
|
||||
import org.apache.struts2.result.ServletDispatcherResult;
|
||||
import org.easymock.EasyMock;
|
||||
|
||||
import jakarta.servlet.ServletContext;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.apache.struts2.convention.ReflectionTools.getAnnotation;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.checkOrder;
|
||||
import static org.easymock.EasyMock.createStrictMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -388,6 +425,7 @@ public class PackageBasedActionConfigBuilderTest extends TestCase {
|
||||
fileManagerFactory.setFileManager(new DefaultFileManager());
|
||||
builder.setFileManagerFactory(fileManagerFactory);
|
||||
builder.setPackageLocatorsBase("org.apache.struts2.convention.actions");
|
||||
builder.setProviderAllowlist(new ProviderAllowlist());
|
||||
builder.buildActionConfigs();
|
||||
verify(resultMapBuilder);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<dependency>
|
||||
<groupId>net.sf.jasperreports</groupId>
|
||||
<artifactId>jasperreports</artifactId>
|
||||
<version>6.21.0</version>
|
||||
<version>6.21.3</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<!-- not necessary to compile and it force dependency convergence issues -->
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.interceptor.parameter.StrutsParameter;
|
||||
import org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor;
|
||||
import org.apache.struts2.interceptor.validation.SkipValidation;
|
||||
import org.apache.struts2.junit.StrutsTestCase;
|
||||
@@ -214,6 +215,7 @@ public class JSONValidationInterceptorTest extends StrutsTestCase {
|
||||
private boolean executed = false;
|
||||
private String password;
|
||||
|
||||
@Override
|
||||
public String execute() {
|
||||
executed = true;
|
||||
return Action.SUCCESS;
|
||||
@@ -230,11 +232,13 @@ public class JSONValidationInterceptorTest extends StrutsTestCase {
|
||||
|
||||
@StringLengthFieldValidator(minLength = "2", message = "Too short")
|
||||
@EmailValidator(message = "This is no email")
|
||||
@StrutsParameter
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@RequiredStringValidator(message = "Password isn't correct")
|
||||
@StrutsParameter
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
@@ -248,6 +252,7 @@ public class JSONValidationInterceptorTest extends StrutsTestCase {
|
||||
}
|
||||
|
||||
@IntRangeFieldValidator(min = "-1", message = "Min value is -1")
|
||||
@StrutsParameter
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.opensymphony.xwork2.ActionSupport;
|
||||
public class SessionGetAction extends ActionSupport {
|
||||
private static final long serialVersionUID = 8366502863472148631L;
|
||||
|
||||
@Override
|
||||
public String execute() {
|
||||
return ActionSupport.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class SessionSetAction extends ActionSupport {
|
||||
public String SESSION_KEY = "sessionKey";
|
||||
public String SESSION_VALUE = "sessionValue";
|
||||
|
||||
@Override
|
||||
public String execute() {
|
||||
ActionContext.getContext().getSession().put(SESSION_KEY, SESSION_VALUE);
|
||||
return ActionSupport.SUCCESS;
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.opensymphony.xwork2.util.XWorkTestCaseHelper;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.interceptor.parameter.StrutsParameter;
|
||||
import org.apache.struts2.ognl.StrutsOgnlGuard;
|
||||
import org.apache.struts2.result.HttpHeaderResult;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -293,10 +294,12 @@ public class RestActionInvocationTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
class RestAction extends RestActionSupport implements ModelDriven<List<String>> {
|
||||
static class RestAction extends RestActionSupport implements ModelDriven<List<String>> {
|
||||
|
||||
List<String> model;
|
||||
|
||||
@StrutsParameter(depth = 1)
|
||||
@Override
|
||||
public List<String> getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
package com.opensymphony.xwork2;
|
||||
|
||||
|
||||
import org.apache.struts2.interceptor.parameter.StrutsParameter;
|
||||
|
||||
/**
|
||||
* ModelDrivenAction
|
||||
*
|
||||
@@ -28,9 +30,9 @@ package com.opensymphony.xwork2;
|
||||
public class ModelDrivenAction extends ActionSupport implements ModelDriven {
|
||||
|
||||
private String foo;
|
||||
private TestBean model = new TestBean();
|
||||
|
||||
private final TestBean model = new TestBean();
|
||||
|
||||
@StrutsParameter
|
||||
public void setFoo(String foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
@@ -42,6 +44,8 @@ public class ModelDrivenAction extends ActionSupport implements ModelDriven {
|
||||
/**
|
||||
* @return the model to be pushed onto the ValueStack after the Action itself
|
||||
*/
|
||||
@StrutsParameter(depth = 2)
|
||||
@Override
|
||||
public Object getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user