Author: lukaszlenart Date: Tue Nov 6 06:19:04 2012 New Revision: 1406052 URL: http://svn.apache.org/viewvc?rev=1406052&view=rev Log: WW-3915 solves problem with reloading configs in devMode on each request
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/util/fs/JBossFileManager.java struts/struts2/trunk/core/src/main/resources/struts-default.xml struts/struts2/trunk/plugins/embeddedjsp/src/test/java/org/apache/struts2/EmbeddedJSPResultTest.java struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/FileManager.java struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/FileManagerFactory.java struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManager.java struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManagerFactory.java struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/ConfigurationManagerTest.java struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/util/DefaultFileManagerTest.java struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/util/fs/DefaultFileManagerFactoryTest.java struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManagerTest.java struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManagerTest.java Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java Tue Nov 6 06:19:04 2012 @@ -286,7 +286,7 @@ public class BeanSelectionProvider imple public void register(ContainerBuilder builder, LocatableProperties props) { alias(ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY, builder, props); - alias(FileManagerFactory.class, StrutsConstants.STRUTS_FILE_MANAGER_FACTORY, builder, props); + alias(FileManagerFactory.class, StrutsConstants.STRUTS_FILE_MANAGER_FACTORY, builder, props, Scope.SINGLETON); alias(XWorkConverter.class, StrutsConstants.STRUTS_XWORKCONVERTER, builder, props); alias(TextProvider.class, StrutsConstants.STRUTS_XWORKTEXTPROVIDER, builder, props, Scope.DEFAULT); alias(LocaleProvider.class, StrutsConstants.STRUTS_LOCALE_PROVIDER, builder, props); Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/util/fs/JBossFileManager.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/util/fs/JBossFileManager.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/util/fs/JBossFileManager.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/util/fs/JBossFileManager.java Tue Nov 6 06:19:04 2012 @@ -33,8 +33,8 @@ public class JBossFileManager extends De @Override public boolean support() { boolean supports = isJBoss7() || isJBoss5(); - if (supports && LOG.isInfoEnabled()) { - LOG.info("JBoss server detected, Struts 2 will use [#0] to support file system operations!", JBossFileManager.class.getSimpleName()); + if (supports && LOG.isDebugEnabled()) { + LOG.debug("JBoss server detected, Struts 2 will use [#0] to support file system operations!", JBossFileManager.class.getSimpleName()); } return supports; } @@ -61,13 +61,15 @@ public class JBossFileManager extends De @Override public void monitorFile(URL fileUrl) { - if (isReloadingConfigs()) { - if (isJBossUrl(fileUrl)) { - Revision revision = FileRevision.build(normalizeToFileProtocol(fileUrl)); - files.put(fileUrl.toString(), revision); - } else { - super.monitorFile(fileUrl); + if (isJBossUrl(fileUrl)) { + String fileName = fileUrl.toString(); + if (LOG.isDebugEnabled()) { + LOG.debug("Creating revision for URL: " + fileName); } + Revision revision = FileRevision.build(normalizeToFileProtocol(fileUrl)); + files.put(fileName, revision); + } else { + super.monitorFile(fileUrl); } } @@ -146,7 +148,7 @@ public class JBossFileManager extends De urls.add(url); } } catch (Exception e) { - LOG.warn("Error calling getPhysicalFile() on JBoss VirtualFile.", e); + LOG.warn("Error calling getPhysicalFile() on JBoss VirtualFile!", e); } return urls; } Modified: struts/struts2/trunk/core/src/main/resources/struts-default.xml URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/struts-default.xml?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/resources/struts-default.xml (original) +++ struts/struts2/trunk/core/src/main/resources/struts-default.xml Tue Nov 6 06:19:04 2012 @@ -29,10 +29,10 @@ <bean class="com.opensymphony.xwork2.ObjectFactory" name="xwork" /> <bean type="com.opensymphony.xwork2.ObjectFactory" name="struts" class="org.apache.struts2.impl.StrutsObjectFactory" /> - <bean type="com.opensymphony.xwork2.FileManager" class="com.opensymphony.xwork2.util.fs.DefaultFileManager" name="system"/> + <bean type="com.opensymphony.xwork2.FileManager" class="com.opensymphony.xwork2.util.fs.DefaultFileManager" name="system" scope="singleton"/> - <bean type="com.opensymphony.xwork2.FileManagerFactory" class="com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory" name="xwork"/> - <bean type="com.opensymphony.xwork2.FileManagerFactory" class="com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory" name="struts"/> + <bean type="com.opensymphony.xwork2.FileManagerFactory" class="com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory" name="xwork" scope="singleton"/> + <bean type="com.opensymphony.xwork2.FileManagerFactory" class="com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory" name="struts" scope="singleton"/> <bean type="com.opensymphony.xwork2.ActionProxyFactory" name="xwork" class="com.opensymphony.xwork2.DefaultActionProxyFactory"/> <bean type="com.opensymphony.xwork2.ActionProxyFactory" name="struts" class="org.apache.struts2.impl.StrutsActionProxyFactory"/> Modified: struts/struts2/trunk/plugins/embeddedjsp/src/test/java/org/apache/struts2/EmbeddedJSPResultTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/embeddedjsp/src/test/java/org/apache/struts2/EmbeddedJSPResultTest.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/plugins/embeddedjsp/src/test/java/org/apache/struts2/EmbeddedJSPResultTest.java (original) +++ struts/struts2/trunk/plugins/embeddedjsp/src/test/java/org/apache/struts2/EmbeddedJSPResultTest.java Tue Nov 6 06:19:04 2012 @@ -270,7 +270,7 @@ public class EmbeddedJSPResultTest exten XWorkConverter converter = new DummyConverter(); DefaultFileManager fileManager = new DefaultFileManager(); - fileManager.setReloadingConfigs("false"); + fileManager.setReloadingConfigs(false); //mock container Container container = EasyMock.createNiceMock(Container.class); @@ -299,6 +299,9 @@ class DummyConverter extends XWorkConver class DummyFileManagerFactory implements FileManagerFactory { + public void setReloadingConfigs(String reloadingConfigs) { + } + public FileManager getFileManager() { return new DefaultFileManager(); } Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/FileManager.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/FileManager.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/FileManager.java (original) +++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/FileManager.java Tue Nov 6 06:19:04 2012 @@ -10,7 +10,12 @@ import java.util.Collection; */ public interface FileManager { - void setReloadingConfigs(String reloadingConfigs); + /** + * Enables configs reloading when config file changed + * + * @param reloadingConfigs {@link XWorkConstants#RELOAD_XML_CONFIGURATION} + */ + void setReloadingConfigs(boolean reloadingConfigs); boolean isReloadingConfigs(); Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/FileManagerFactory.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/FileManagerFactory.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/FileManagerFactory.java (original) +++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/FileManagerFactory.java Tue Nov 6 06:19:04 2012 @@ -5,6 +5,8 @@ package com.opensymphony.xwork2; */ public interface FileManagerFactory { + void setReloadingConfigs(String reloadingConfigs); + FileManager getFileManager(); } Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManager.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManager.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManager.java (original) +++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManager.java Tue Nov 6 06:19:04 2012 @@ -16,7 +16,6 @@ package com.opensymphony.xwork2.util.fs; import com.opensymphony.xwork2.FileManager; -import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; @@ -49,9 +48,8 @@ public class DefaultFileManager implemen public DefaultFileManager() { } - @Inject(value = "reloadXmlConfiguration", required = false) - public void setReloadingConfigs(String reloadingConfigs) { - this.reloadingConfigs = Boolean.parseBoolean(reloadingConfigs); + public void setReloadingConfigs(boolean reloadingConfigs) { + this.reloadingConfigs = reloadingConfigs; } public boolean isReloadingConfigs() { @@ -94,22 +92,20 @@ public class DefaultFileManager implemen } public void monitorFile(URL fileUrl) { - if (isReloadingConfigs()) { - String fileName = fileUrl.toString(); - Revision revision; - if (LOG.isDebugEnabled()) { - LOG.debug("Creating revision for URL: " + fileName); - } - if (isJarURL(fileUrl)) { - revision = JarEntryRevision.build(fileUrl, this); - } else { - revision = FileRevision.build(fileUrl); - } - if (revision == null) { - files.put(fileName, Revision.build(fileUrl)); - } else { - files.put(fileName, revision); - } + String fileName = fileUrl.toString(); + Revision revision; + if (LOG.isDebugEnabled()) { + LOG.debug("Creating revision for URL: " + fileName); + } + if (isJarURL(fileUrl)) { + revision = JarEntryRevision.build(fileUrl, this); + } else { + revision = FileRevision.build(fileUrl); + } + if (revision == null) { + files.put(fileName, Revision.build(fileUrl)); + } else { + files.put(fileName, revision); } } @@ -135,10 +131,9 @@ public class DefaultFileManager implemen return null; //it is not a jar or zip file } } catch (MalformedURLException e) { - //can this ever happen? - return null; - } catch (IOException e) { - LOG.warn("Error opening JBoss vfs file", e); + if (LOG.isWarnEnabled()) { + LOG.warn("Error opening url [#0]", e, url.toString()); + } return null; } } Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManagerFactory.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManagerFactory.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManagerFactory.java (original) +++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/fs/DefaultFileManagerFactory.java Tue Nov 6 06:19:04 2012 @@ -2,6 +2,7 @@ package com.opensymphony.xwork2.util.fs; import com.opensymphony.xwork2.FileManager; import com.opensymphony.xwork2.FileManagerFactory; +import com.opensymphony.xwork2.XWorkConstants; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.logging.Logger; @@ -17,6 +18,7 @@ public class DefaultFileManagerFactory i private static final Logger LOG = LoggerFactory.getLogger(DefaultFileManagerFactory.class); + private boolean reloadingConfigs; private FileManager fileManager; private Container container; @@ -30,6 +32,11 @@ public class DefaultFileManagerFactory i this.container = container; } + @Inject(value = XWorkConstants.RELOAD_XML_CONFIGURATION, required = false) + public void setReloadingConfigs(String reloadingConfigs) { + this.reloadingConfigs = Boolean.parseBoolean(reloadingConfigs); + } + public FileManager getFileManager() { Set<String> names = container.getInstanceNames(FileManager.class); if (LOG.isDebugEnabled()) { @@ -50,6 +57,7 @@ public class DefaultFileManagerFactory i if (LOG.isDebugEnabled()) { LOG.debug("Using FileManager implementation [#0]", fm.getClass().getSimpleName()); } + fm.setReloadingConfigs(reloadingConfigs); return fm; } } @@ -64,6 +72,7 @@ public class DefaultFileManagerFactory i if (LOG.isDebugEnabled()) { LOG.debug("Using default implementation of FileManager provided under name [system]: #0", fileManager.getClass().getSimpleName()); } + fileManager.setReloadingConfigs(reloadingConfigs); return fileManager; } Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/ConfigurationManagerTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/ConfigurationManagerTest.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/ConfigurationManagerTest.java (original) +++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/ConfigurationManagerTest.java Tue Nov 6 06:19:04 2012 @@ -47,7 +47,7 @@ public class ConfigurationManagerTest ex configProviderMock.expect("loadPackages", C.ANY_ARGS); configProviderMock.expect("destroy", C.ANY_ARGS); configProviderMock.matchAndReturn("toString", "mock"); - configuration.getContainer().getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs("true"); + configuration.getContainer().getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true); configuration = configurationManager.getConfiguration(); configProviderMock.verify(); Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java (original) +++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProviderTest.java Tue Nov 6 06:19:04 2012 @@ -74,10 +74,10 @@ public class XmlConfigurationProviderTes } public void testNeedsReload() throws Exception { - container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs("true"); + container.getInstance(FileManagerFactory.class).setReloadingConfigs("true"); final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions.xml"; ConfigurationProvider provider = buildConfigurationProvider(filename); - container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs("true"); + container.getInstance(FileManagerFactory.class).setReloadingConfigs("true"); assertTrue(!provider.needsReload()); // Revision exists and timestamp didn't change @@ -151,7 +151,7 @@ public class XmlConfigurationProviderTes public void testEmptySpaces() throws Exception { final String filename = "com/opensymphony/xwork2/config/providers/xwork- test.xml"; - container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs("true"); + container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true); ConfigurationProvider provider = buildConfigurationProvider(filename); assertTrue(!provider.needsReload()); @@ -167,7 +167,7 @@ public class XmlConfigurationProviderTes } public void testConfigsInJarFiles() throws Exception { - container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs("true"); + container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true); testProvider("xwork-jar.xml"); testProvider("xwork-zip.xml"); testProvider("xwork - jar.xml"); Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/util/DefaultFileManagerTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/util/DefaultFileManagerTest.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/util/DefaultFileManagerTest.java (original) +++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/util/DefaultFileManagerTest.java Tue Nov 6 06:19:04 2012 @@ -36,11 +36,25 @@ public class DefaultFileManagerTest exte } private void testLoadFile(String fileName) { - fileManager.setReloadingConfigs("true"); + fileManager.setReloadingConfigs(true); URL url = ClassLoaderUtil.getResource(fileName, DefaultFileManagerTest.class); InputStream file = fileManager.loadFile(url); assertNotNull(file); - assertFalse(!fileManager.fileNeedsReloading(fileName)); + assertTrue(fileManager.fileNeedsReloading(fileName)); + } + + public void testReloadingConfigs() throws Exception { + // given + container.getInstance(FileManagerFactory.class).setReloadingConfigs("false"); + FileManager fm = container.getInstance(FileManagerFactory.class).getFileManager(); + assertFalse(fm.isReloadingConfigs()); + + // when + container.getInstance(FileManagerFactory.class).setReloadingConfigs("true"); + fm = container.getInstance(FileManagerFactory.class).getFileManager(); + + // then + assertTrue(fm.isReloadingConfigs()); } } Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/util/fs/DefaultFileManagerFactoryTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/util/fs/DefaultFileManagerFactoryTest.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/util/fs/DefaultFileManagerFactoryTest.java (original) +++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/util/fs/DefaultFileManagerFactoryTest.java Tue Nov 6 06:19:04 2012 @@ -98,7 +98,7 @@ class DummyContainer implements Containe class DummyFileManager implements FileManager { - public void setReloadingConfigs(String reloadingConfigs) { + public void setReloadingConfigs(boolean reloadingConfigs) { } public boolean isReloadingConfigs() { Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManagerTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManagerTest.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManagerTest.java (original) +++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManagerTest.java Tue Nov 6 06:19:04 2012 @@ -103,7 +103,7 @@ public class AnnotationActionValidatorMa List validatorList = annotationActionValidatorManager.getValidators(SimpleAnnotationAction.class, alias, "execute"); //disable configuration reload/devmode - fileManager.setReloadingConfigs("false"); + fileManager.setReloadingConfigs(false); //17 in the class level + 0 in the alias assertEquals(12, validatorList.size()); Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManagerTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManagerTest.java?rev=1406052&r1=1406051&r2=1406052&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManagerTest.java (original) +++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManagerTest.java Tue Nov 6 06:19:04 2012 @@ -172,7 +172,7 @@ public class DefaultActionValidatorManag */ public void testBuildsValidatorsForClassError() { // for this test we need to have a file manager with reloadingConfigs to true - container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs("true"); + container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true); // no validator found, but no check on file since it is not in cache actionValidatorManager.getValidators(List.class, null); // this second call will try reload a not existing file