Search in sources :

Example 51 with StandardHost

use of org.apache.catalina.core.StandardHost in project tomcat70 by apache.

the class TestTomcat method testGetCustomContextPerAddWebappWithHost.

@Test
public void testGetCustomContextPerAddWebappWithHost() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClass(ReplicatedContext.class.getName());
    }
    File appFile = new File("test/deployment/context.war");
    Context context = tomcat.addWebapp(host, "/test", appFile.getAbsolutePath());
    Assert.assertEquals(ReplicatedContext.class.getName(), context.getClass().getName());
}
Also used : ReplicatedContext(org.apache.catalina.ha.context.ReplicatedContext) InitialContext(javax.naming.InitialContext) Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) StandardHost(org.apache.catalina.core.StandardHost) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) ReplicatedContext(org.apache.catalina.ha.context.ReplicatedContext) File(java.io.File) Test(org.junit.Test)

Example 52 with StandardHost

use of org.apache.catalina.core.StandardHost in project tomcat70 by apache.

the class TestTomcat method testGetBrokenContextPerAddContext.

@Test
public void testGetBrokenContextPerAddContext() {
    Tomcat tomcat = getTomcatInstance();
    Host host = tomcat.getHost();
    if (host instanceof StandardHost) {
        ((StandardHost) host).setContextClass("InvalidContextClassName");
    }
    // No file system docBase required
    try {
        tomcat.addContext(null, "", null);
        Assert.fail();
    } catch (IllegalArgumentException e) {
    // OK
    }
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) Test(org.junit.Test)

Example 53 with StandardHost

use of org.apache.catalina.core.StandardHost in project tomcat70 by apache.

the class TestWebappClassLoaderThreadLocalMemoryLeak method testThreadLocalLeak1.

@Test
public void testThreadLocalLeak1() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // Need to make sure we see a leak for the right reasons
    tomcat.getServer().addLifecycleListener(new JreMemoryLeakPreventionListener());
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    Tomcat.addServlet(ctx, "leakServlet1", "org.apache.tomcat.unittest.TesterLeakingServlet1");
    ctx.addServletMapping("/leak1", "leakServlet1");
    tomcat.start();
    Executor executor = tomcat.getConnector().getProtocolHandler().getExecutor();
    ((ThreadPoolExecutor) executor).setThreadRenewalDelay(-1);
    // Configure logging filter to check leak message appears
    TesterLogValidationFilter f = TesterLogValidationFilter.add(null, "The web application [] created a ThreadLocal with key of", null, "org.apache.catalina.loader.WebappClassLoaderBase");
    // Need to force loading of all web application classes via the web
    // application class loader
    loadClass("TesterCounter", (WebappClassLoaderBase) ctx.getLoader().getClassLoader());
    loadClass("TesterLeakingServlet1", (WebappClassLoaderBase) ctx.getLoader().getClassLoader());
    // This will trigger the ThreadLocal creation
    int rc = getUrl("http://localhost:" + getPort() + "/leak1", new ByteChunk(), null);
    // Make sure request is OK
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    // Destroy the context
    ctx.stop();
    tomcat.getHost().removeChild(ctx);
    ctx = null;
    // Make sure we have a memory leak
    String[] leaks = ((StandardHost) tomcat.getHost()).findReloadedContextMemoryLeaks();
    Assert.assertNotNull(leaks);
    Assert.assertTrue(leaks.length > 0);
    // Make sure the message was logged
    Assert.assertEquals(1, f.getMessageCount());
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) Executor(java.util.concurrent.Executor) ThreadPoolExecutor(org.apache.tomcat.util.threads.ThreadPoolExecutor) TesterLogValidationFilter(org.apache.tomcat.unittest.TesterLogValidationFilter) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) StandardHost(org.apache.catalina.core.StandardHost) JreMemoryLeakPreventionListener(org.apache.catalina.core.JreMemoryLeakPreventionListener) ThreadPoolExecutor(org.apache.tomcat.util.threads.ThreadPoolExecutor) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 54 with StandardHost

use of org.apache.catalina.core.StandardHost in project tomcat70 by apache.

the class ClusterJmxHelper method getDefaultClusterName.

private static ObjectName getDefaultClusterName(SimpleTcpCluster cluster) throws Exception {
    String domain = getMBeanServer().getDefaultDomain();
    String type = ":type=";
    String clusterType = type + "Cluster";
    if (cluster.getContainer() instanceof StandardHost) {
        domain = ((StandardHost) cluster.getContainer()).getDomain();
        clusterType += ",host=" + cluster.getContainer().getName();
    } else {
        if (cluster.getContainer() instanceof StandardEngine) {
            domain = ((StandardEngine) cluster.getContainer()).getDomain();
        }
    }
    ObjectName clusterName = new ObjectName(domain + clusterType);
    return clusterName;
}
Also used : StandardEngine(org.apache.catalina.core.StandardEngine) StandardHost(org.apache.catalina.core.StandardHost) ObjectName(javax.management.ObjectName)

Example 55 with StandardHost

use of org.apache.catalina.core.StandardHost in project tomcat70 by apache.

the class MBeanFactory method getParentContainerFromChild.

/**
 * Get Parent ContainerBase to add its child component
 * from child component's ObjectName  as a String
 */
private ContainerBase getParentContainerFromChild(ObjectName oname) throws Exception {
    String hostName = oname.getKeyProperty("host");
    String path = oname.getKeyProperty("path");
    Service service = getService(oname);
    StandardEngine engine = (StandardEngine) service.getContainer();
    if (hostName == null) {
        // child's container is Engine
        return engine;
    } else if (path == null) {
        // child's container is Host
        StandardHost host = (StandardHost) engine.findChild(hostName);
        return host;
    } else {
        // child's container is Context
        StandardHost host = (StandardHost) engine.findChild(hostName);
        path = getPathStr(path);
        StandardContext context = (StandardContext) host.findChild(path);
        return context;
    }
}
Also used : StandardEngine(org.apache.catalina.core.StandardEngine) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service)

Aggregations

StandardHost (org.apache.catalina.core.StandardHost)90 File (java.io.File)48 Context (org.apache.catalina.Context)38 StandardContext (org.apache.catalina.core.StandardContext)36 Host (org.apache.catalina.Host)29 Test (org.junit.Test)26 Tomcat (org.apache.catalina.startup.Tomcat)16 Container (org.apache.catalina.Container)12 StandardEngine (org.apache.catalina.core.StandardEngine)12 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)12 IOException (java.io.IOException)10 URL (java.net.URL)8 Service (org.apache.catalina.Service)8 HostConfig (org.apache.catalina.startup.HostConfig)8 InitialContext (javax.naming.InitialContext)7 Engine (org.apache.catalina.Engine)7 InputStream (java.io.InputStream)6 ObjectName (javax.management.ObjectName)6 ReplicatedContext (org.apache.catalina.ha.context.ReplicatedContext)6 ArrayList (java.util.ArrayList)5