You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2016/11/11 09:27:39 UTC
svn commit: r1769263 - in /tomcat/trunk:
java/org/apache/catalina/startup/Tomcat.java
test/org/apache/catalina/core/TestStandardContextResources.java
test/org/apache/catalina/startup/TestTomcat.java webapps/docs/changelog.xml
Author: markt
Date: Fri Nov 11 09:27:38 2016
New Revision: 1769263
URL: http://svn.apache.org/viewvc?rev=1769263&view=rev
Log:
Take account of the Host's contextClass attribute when embedding
Modified:
tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java
tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java?rev=1769263&r1=1769262&r2=1769263&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java Fri Nov 11 09:27:38 2016
@@ -561,7 +561,17 @@ public class Tomcat {
* @see #addWebapp(String, String)
*/
public Context addWebapp(Host host, String contextPath, String docBase) {
- return addWebapp(host, contextPath, docBase, new ContextConfig());
+ LifecycleListener listener = null;
+ try {
+ Class<?> clazz = Class.forName(getHost().getConfigClass());
+ listener = (LifecycleListener) clazz.newInstance();
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
+ // Wrap in IAE since we can't easily change the method signature to
+ // to throw the specific checked exceptions
+ throw new IllegalArgumentException(e);
+ }
+
+ return addWebapp(host, contextPath, docBase, listener);
}
/**
@@ -572,8 +582,27 @@ public class Tomcat {
* @param config Custom context configurator helper
* @return the deployed context
* @see #addWebapp(String, String)
+ *
+ * @deprecated Use {@link
+ * #addWebapp(Host, String, String, LifecycleListener)} instead
*/
+ @Deprecated
public Context addWebapp(Host host, String contextPath, String docBase, ContextConfig config) {
+ return addWebapp(host, contextPath, docBase, (LifecycleListener) config);
+ }
+
+
+ /**
+ * @param host The host in which the context will be deployed
+ * @param contextPath The context mapping to use, "" for root context.
+ * @param docBase Base directory for the context, for static files.
+ * Must exist, relative to the server home
+ * @param config Custom context configurator helper
+ * @return the deployed context
+ * @see #addWebapp(String, String)
+ */
+ public Context addWebapp(Host host, String contextPath, String docBase,
+ LifecycleListener config) {
silence(host, contextPath);
@@ -585,8 +614,10 @@ public class Tomcat {
ctx.addLifecycleListener(config);
- // prevent it from looking ( if it finds one - it'll have dup error )
- config.setDefaultWebXml(noDefaultWebXmlPath());
+ if (config instanceof ContextConfig) {
+ // prevent it from looking ( if it finds one - it'll have dup error )
+ ((ContextConfig) config).setDefaultWebXml(noDefaultWebXmlPath());
+ }
if (host == null) {
getHost().addChild(ctx);
Modified: tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java?rev=1769263&r1=1769262&r2=1769263&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java (original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestStandardContextResources.java Fri Nov 11 09:27:38 2016
@@ -37,6 +37,7 @@ import static org.junit.Assert.assertTru
import org.junit.Test;
import org.apache.catalina.Context;
+import org.apache.catalina.LifecycleListener;
import org.apache.catalina.startup.Constants;
import org.apache.catalina.startup.ContextConfig;
import org.apache.catalina.startup.Tomcat;
@@ -135,7 +136,7 @@ public class TestStandardContextResource
// app dir is relative to server home
StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test",
- appDir.getAbsolutePath(), absoluteOrderConfig);
+ appDir.getAbsolutePath(), (LifecycleListener) absoluteOrderConfig);
Tomcat.addServlet(ctx, "getresource", new GetResourceServlet());
ctx.addServletMappingDecoded("/getresource", "getresource");
@@ -157,7 +158,7 @@ public class TestStandardContextResource
absoluteOrderConfig.swap();
ctx = (StandardContext) tomcat.addWebapp(null, "/test",
- appDir.getAbsolutePath(), absoluteOrderConfig);
+ appDir.getAbsolutePath(), (LifecycleListener) absoluteOrderConfig);
Tomcat.addServlet(ctx, "getresource", new GetResourceServlet());
ctx.addServletMappingDecoded("/getresource", "getresource");
Modified: tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java?rev=1769263&r1=1769262&r2=1769263&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java Fri Nov 11 09:27:38 2016
@@ -39,10 +39,13 @@ import static org.junit.Assert.assertNul
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import org.junit.Assert;
import org.junit.Test;
import org.apache.catalina.Context;
import org.apache.catalina.Host;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.ha.context.ReplicatedContext;
@@ -530,4 +533,33 @@ public class TestTomcat extends TomcatBa
.getName());
}
+ @Test
+ public void testCustomContextConfig() throws Exception {
+
+ Tomcat tomcat = getTomcatInstance();
+
+ tomcat.getHost().setConfigClass(CustomContextConfig.class.getName());
+
+ File docBase = new File("test/webapp");
+ tomcat.addWebapp("/test", docBase.getAbsolutePath());
+
+ tomcat.start();
+
+ Assert.assertTrue(CustomContextConfig.isUsed());
+ }
+
+ public static class CustomContextConfig implements LifecycleListener {
+
+ private static volatile boolean used = false;
+
+ public static boolean isUsed() {
+ return used;
+ }
+
+ @Override
+ public void lifecycleEvent(LifecycleEvent event) {
+ // Hack via a static since we can't pass an instance in the test.
+ used = true;
+ }
+ }
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1769263&r1=1769262&r2=1769263&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Nov 11 09:27:38 2016
@@ -61,6 +61,10 @@
Correctly generate URLs for resources located inside JARs that are
themselves located inside a packed WAR file. (markt)
</fix>
+ <fix>
+ Correctly handle the <code>configClass</code> attribute of a Host when
+ embedding Tomcat. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Tribes">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org