WW-4129 Removes checking if configuration changed in ContainerHolder and allows to explicit set reload/cache options independent from devMode

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1534087 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Lukasz Lenart
2013-10-21 10:43:53 +00:00
parent ade9fb151c
commit 666e14bee8
3 changed files with 31 additions and 22 deletions
@@ -409,16 +409,7 @@ public class BeanSelectionProvider implements ConfigurationProvider {
alias(SecurityGate.class, StrutsConstants.STRUTS_SECURITY_GATE, builder, props);
if ("true".equalsIgnoreCase(props.getProperty(StrutsConstants.STRUTS_DEVMODE))) {
props.setProperty(StrutsConstants.STRUTS_I18N_RELOAD, "true");
props.setProperty(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, "true");
props.setProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE, "false");
props.setProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY, "0");
// Convert struts properties into ones that xwork expects
props.setProperty(XWorkConstants.DEV_MODE, "true");
} else {
props.setProperty(XWorkConstants.DEV_MODE, "false");
}
switchDevMode(props);
// Convert Struts properties into XWork properties
convertIfExist(props, StrutsConstants.STRUTS_LOG_MISSING_PROPERTIES, XWorkConstants.LOG_MISSING_PROPERTIES);
@@ -431,6 +422,32 @@ public class BeanSelectionProvider implements ConfigurationProvider {
loadCustomResourceBundles(props);
}
/**
* Enables/disables devMode and related settings if they aren't explicit set in struts.xml/struts.properties
*
* @param props configured properties
*/
private void switchDevMode(LocatableProperties props) {
if ("true".equalsIgnoreCase(props.getProperty(StrutsConstants.STRUTS_DEVMODE))) {
if (props.getProperty(StrutsConstants.STRUTS_I18N_RELOAD) == null) {
props.setProperty(StrutsConstants.STRUTS_I18N_RELOAD, "true");
}
if (props.getProperty(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD) == null) {
props.setProperty(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, "true");
}
if (props.getProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE) == null) {
props.setProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE, "false");
}
if (props.getProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY) == null) {
props.setProperty(StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY, "0");
}
// Convert struts properties into ones that xwork expects
props.setProperty(XWorkConstants.DEV_MODE, "true");
} else {
props.setProperty(XWorkConstants.DEV_MODE, "false");
}
}
private void convertIfExist(LocatableProperties props, String fromKey, String toKey) {
if (props.containsKey(fromKey)) {
props.setProperty(toKey, props.getProperty(fromKey));
@@ -1,25 +1,21 @@
package org.apache.struts2.dispatcher;
import com.opensymphony.xwork2.inject.Container;
import org.apache.struts2.StrutsConstants;
/**
* Simple class to hold Container instance per thread to minimise number of attempts
* to read configuration and build each time a new configuration.
*
* Thus depends on {@link StrutsConstants#STRUTS_CONFIGURATION_XML_RELOAD} flag,
* if set to false just use stored container, configuration will do not change.
* As ContainerHolder operates just per thread (which means per request) there is no need
* to check if configuration changed during the same request. If changed between requests,
* first call to store Container in ContainerHolder will be with the new configuration.
*/
class ContainerHolder {
private static ThreadLocal<Container> instance = new ThreadLocal<Container>();
public static void store(Container instance) {
boolean reloadConfigs = Boolean.valueOf(instance.getInstance(String.class, StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD));
if (!reloadConfigs) {
// reloadConfigs is false, configuration will do not change, just keep it
ContainerHolder.instance.set(instance);
}
ContainerHolder.instance.set(instance);
}
public static Container get() {
@@ -194,8 +194,6 @@ public class DispatcherTest extends StrutsTestCase {
Mock mockContainer = new Mock(Container.class);
String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD)),
reloadConfigs);
mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
reloadConfigs);
mockContainer.expectAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), destroyedObjectFactory);
@@ -230,8 +228,6 @@ public class DispatcherTest extends StrutsTestCase {
Mock mockContainer = new Mock(Container.class);
mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new ObjectFactory());
String reloadConfigs = container.getInstance(String.class, XWorkConstants.RELOAD_XML_CONFIGURATION);
mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD)),
reloadConfigs);
mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(XWorkConstants.RELOAD_XML_CONFIGURATION)),
reloadConfigs);