mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
Adding new settings to disable classpath action scanning for the codebehind and rest plugins
WW-2506 git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@649873 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+22
-5
@@ -61,7 +61,7 @@ public class ClasspathPackageProvider implements PackageProvider {
|
||||
* The default page prefix (or "path").
|
||||
* Some applications may place pages under "/WEB-INF" as an extreme security precaution.
|
||||
*/
|
||||
private static final String DEFAULT_PAGE_PREFIX = "struts.configuration.classpath.defaultPagePrefix";
|
||||
protected static final String DEFAULT_PAGE_PREFIX = "struts.configuration.classpath.defaultPagePrefix";
|
||||
|
||||
/**
|
||||
* The default page prefix (none).
|
||||
@@ -71,7 +71,7 @@ public class ClasspathPackageProvider implements PackageProvider {
|
||||
/**
|
||||
* The default page extension, to use in place of ".jsp".
|
||||
*/
|
||||
private static final String DEFAULT_PAGE_EXTENSION = "struts.configuration.classpath.defaultPageExtension";
|
||||
protected static final String DEFAULT_PAGE_EXTENSION = "struts.configuration.classpath.defaultPageExtension";
|
||||
|
||||
/**
|
||||
* The defacto default page extension, usually associated with JavaServer Pages.
|
||||
@@ -82,7 +82,12 @@ public class ClasspathPackageProvider implements PackageProvider {
|
||||
* A setting to indicate a custom default parent package,
|
||||
* to use in place of "struts-default".
|
||||
*/
|
||||
private static final String DEFAULT_PARENT_PACKAGE = "struts.configuration.classpath.defaultParentPackage";
|
||||
protected static final String DEFAULT_PARENT_PACKAGE = "struts.configuration.classpath.defaultParentPackage";
|
||||
|
||||
/**
|
||||
* A setting to disable action scanning.
|
||||
*/
|
||||
protected static final String DISABLE_ACTION_SCANNING = "struts.configuration.classpath.disableActionScanning";
|
||||
|
||||
/**
|
||||
* Name of the framework's default configuration package,
|
||||
@@ -94,7 +99,7 @@ public class ClasspathPackageProvider implements PackageProvider {
|
||||
* The default page prefix (or "path").
|
||||
* Some applications may place pages under "/WEB-INF" as an extreme security precaution.
|
||||
*/
|
||||
private static final String FORCE_LOWER_CASE = "struts.configuration.classpath.forceLowerCase";
|
||||
protected static final String FORCE_LOWER_CASE = "struts.configuration.classpath.forceLowerCase";
|
||||
|
||||
/**
|
||||
* Whether to use a lowercase letter as the initial letter of an action.
|
||||
@@ -120,6 +125,8 @@ public class ClasspathPackageProvider implements PackageProvider {
|
||||
* @see #needsReload
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
private boolean disableActionScanning = false;
|
||||
|
||||
private PackageLoader packageLoader;
|
||||
|
||||
@@ -167,6 +174,16 @@ public class ClasspathPackageProvider implements PackageProvider {
|
||||
this.servletContext = ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables action scanning.
|
||||
*
|
||||
* @param disableActionScanning True to disable
|
||||
*/
|
||||
@Inject(value=DISABLE_ACTION_SCANNING, required=false)
|
||||
public void setDisableActionScanning(String disableActionScanning) {
|
||||
this.disableActionScanning = "true".equals(disableActionScanning);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a default parent package for the actions.
|
||||
*
|
||||
@@ -437,7 +454,7 @@ public class ClasspathPackageProvider implements PackageProvider {
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
if (actionPackages != null) {
|
||||
if (actionPackages != null && !disableActionScanning) {
|
||||
String[] names = actionPackages.split("\\s*[,]\\s*");
|
||||
// Initialize the classloader scanner with the configured packages
|
||||
if (names.length > 0) {
|
||||
|
||||
+11
@@ -74,6 +74,17 @@ public class ClasspathPackageProviderTest extends TestCase {
|
||||
ActionConfig actionConfig = (ActionConfig) configs.get("customParentPackage");
|
||||
assertNotNull(actionConfig);
|
||||
}
|
||||
|
||||
public void testDisableScanning() {
|
||||
provider = new ClasspathPackageProvider();
|
||||
provider.setActionPackages("org.apache.struts2.config");
|
||||
provider.setDisableActionScanning("true");
|
||||
config = new DefaultConfiguration();
|
||||
provider.init(config);
|
||||
provider.loadPackages();
|
||||
|
||||
assertEquals(0, config.getPackageConfigs().size());
|
||||
}
|
||||
|
||||
public void testParentPackage() {
|
||||
PackageConfig pkg = config.getPackageConfig("org.apache.struts2.config");
|
||||
|
||||
+27
@@ -22,6 +22,7 @@ package org.apache.struts2.rest;
|
||||
|
||||
import org.apache.struts2.config.ClasspathPackageProvider;
|
||||
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ResolverUtil.ClassTest;
|
||||
|
||||
/**
|
||||
@@ -29,6 +30,11 @@ import com.opensymphony.xwork2.util.ResolverUtil.ClassTest;
|
||||
*/
|
||||
public class ControllerClasspathPackageProvider extends ClasspathPackageProvider {
|
||||
|
||||
/**
|
||||
* A setting to disable action scanning.
|
||||
*/
|
||||
protected static final String DISABLE_REST_CONTROLLER_SCANNING = "struts.configuration.rest.disableControllerScanning";
|
||||
|
||||
@Override
|
||||
protected ClassTest createActionClassTest() {
|
||||
return new ClassTest() {
|
||||
@@ -43,5 +49,26 @@ public class ControllerClasspathPackageProvider extends ClasspathPackageProvider
|
||||
protected String getClassSuffix() {
|
||||
return "Controller";
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore setting to disable action scanning from the codebehind plugin.
|
||||
*
|
||||
* @param disableActionScanning True to disable
|
||||
*/
|
||||
@Override
|
||||
@Inject(value=DISABLE_ACTION_SCANNING, required=false)
|
||||
public void setDisableActionScanning(String disableActionScanning) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables controller scanning.
|
||||
*
|
||||
* @param disableActionScanning True to disable
|
||||
*/
|
||||
@Inject(value=DISABLE_REST_CONTROLLER_SCANNING, required=false)
|
||||
public void setDisableRestControllerScanning(String disableActionScanning) {
|
||||
super.setDisableActionScanning(disableActionScanning);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
<constant name="struts.mapper.class" value="rest" />
|
||||
<constant name="struts.mapper.idParameterName" value="id" />
|
||||
<constant name="struts.action.extension" value="xhtml,,xml,json" />
|
||||
|
||||
<!-- Disable the scanning by the codebehind plugin to prevent duplicates -->
|
||||
<constant name="struts.configuration.classpath.disableActionScanning" value="true" />
|
||||
|
||||
<constant name="struts.configuration.rest.disableControllerScanning" value="false" />
|
||||
<constant name="struts.configuration.classpath.defaultParentPackage" value="rest-default" />
|
||||
|
||||
<package name="rest-default" extends="struts-default">
|
||||
|
||||
Reference in New Issue
Block a user