Author: markt
Date: Mon Nov 25 21:52:57 2013
New Revision: 1545416
URL: http://svn.apache.org/r1545416
Log:
Ensure that the Host's contextClassName attribute is used when parsing
descriptors that do not define one.
Modified:
tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
Modified: tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1545416&r1=1545415&r2=1545416&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/HostConfig.java Mon Nov 25
21:52:57 2013
@@ -145,7 +145,8 @@ public class HostConfig
/**
* The <code>Digester</code> instance used to parse context descriptors.
*/
- protected static final Digester digester = createDigester();
+ protected Digester digester = createDigester(contextClass);
+ private final Object digesterLock = new Object();
/**
* The list of Wars in the appBase to be ignored because they are invalid
@@ -173,8 +174,14 @@ public class HostConfig
*/
public void setContextClass(String contextClass) {
+ String oldContextClass = this.contextClass;
this.contextClass = contextClass;
+ if (oldContextClass != contextClass) {
+ synchronized (digesterLock) {
+ digester = createDigester(getContextClass());
+ }
+ }
}
@@ -343,12 +350,11 @@ public class HostConfig
/**
* Create the digester which will be used to parse context config files.
*/
- protected static Digester createDigester() {
+ protected static Digester createDigester(String contextClassName) {
Digester digester = new Digester();
digester.setValidating(false);
// Add object creation rule
- digester.addObjectCreate("Context",
"org.apache.catalina.core.StandardContext",
- "className");
+ digester.addObjectCreate("Context", contextClassName, "className");
// Set the properties on that object (it doesn't matter if extra
// properties are set)
digester.addSetProperties("Context");
@@ -521,7 +527,7 @@ public class HostConfig
File expandedDocBase = null;
try (FileInputStream fis = new FileInputStream(contextXml)) {
- synchronized (digester) {
+ synchronized (digesterLock) {
try {
context = (Context) digester.parse(fis);
} catch (Exception e) {
@@ -790,7 +796,7 @@ public class HostConfig
Context context = null;
try {
if (deployXML && xml.exists() && !copyXML) {
- synchronized (digester) {
+ synchronized (digesterLock) {
try {
context = (Context) digester.parse(xml);
} catch (Exception e) {
@@ -806,7 +812,7 @@ public class HostConfig
}
context.setConfigFile(xml.toURI().toURL());
} else if (deployXML && xmlInWar) {
- synchronized (digester) {
+ synchronized (digesterLock) {
try {
jar = new JarFile(war);
entry =
@@ -1062,7 +1068,7 @@ public class HostConfig
try {
if (deployXML && xml.exists()) {
- synchronized (digester) {
+ synchronized (digesterLock) {
try {
context = (Context) digester.parse(xml);
} catch (Exception e) {
Modified:
tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java?rev=1545416&r1=1545415&r2=1545416&view=diff
==============================================================================
---
tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
(original)
+++
tomcat/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
Mon Nov 25 21:52:57 2013
@@ -35,6 +35,7 @@ import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.LifecycleState;
+import org.apache.catalina.core.StandardContext;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.util.ContextName;
@@ -1813,4 +1814,36 @@ public class TestHostConfigAutomaticDepl
context.getSessionCookieName());
}
}
+
+
+ @Test
+ public void testSetContextClassName() throws Exception {
+
+ Tomcat tomcat = getTomcatInstance();
+
+ Host host = tomcat.getHost();
+ if (host instanceof StandardHost) {
+ StandardHost standardHost = (StandardHost) host;
+ standardHost.setContextClass(TesterContext.class.getName());
+ }
+
+ // Copy the WAR file
+ File war = new File(host.getAppBaseFile(),
+ APP_NAME.getBaseName() + ".war");
+ Files.copy(WAR_XML_SOURCE.toPath(), war.toPath());
+
+ // Deploy the copied war
+ tomcat.start();
+ host.backgroundProcess();
+
+ // Check the Context class
+ Context ctxt = (Context) host.findChild(APP_NAME.getName());
+
+ Assert.assertTrue(ctxt instanceof TesterContext);
+ }
+
+
+ public static class TesterContext extends StandardContext {
+ // No functional change
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]