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());
}
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
}
}
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());
}
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;
}
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;
}
}
Aggregations