use of org.apache.catalina.core.StandardHost in project tomcat by apache.
the class TestWebappClassLoaderThreadLocalMemoryLeak method testThreadLocalLeak2.
@Test
public void testThreadLocalLeak2() 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, "leakServlet2", "org.apache.tomcat.unittest.TesterLeakingServlet2");
ctx.addServletMappingDecoded("/leak2", "leakServlet2");
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 [ROOT] 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("TesterThreadScopedHolder", (WebappClassLoaderBase) ctx.getLoader().getClassLoader());
loadClass("TesterLeakingServlet2", (WebappClassLoaderBase) ctx.getLoader().getClassLoader());
// This will trigger the ThreadLocal creation
int rc = getUrl("http://localhost:" + getPort() + "/leak2", 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 tomcat by apache.
the class TestMapper method createHost.
private synchronized Host createHost(String name) {
Host host = hostMap.get(name);
if (host == null) {
host = new StandardHost();
host.setName(name);
hostMap.put(name, host);
}
return host;
}
use of org.apache.catalina.core.StandardHost in project tomcat by apache.
the class TestAbstractArchiveResource method testJarGetURL.
@Test
public void testJarGetURL() throws Exception {
Tomcat tomcat = getTomcatInstance();
File docBase = new File("test/webapp");
Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath());
skipTldsForResourceJars(ctx);
((StandardHost) tomcat.getHost()).setUnpackWARs(false);
tomcat.start();
WebResource webResource = ctx.getResources().getClassLoaderResource("/META-INF/tags/echo.tag");
StringBuilder expectedURL = new StringBuilder("jar:");
expectedURL.append(docBase.getCanonicalFile().toURI().toURL().toString());
expectedURL.append("WEB-INF/lib/test-lib.jar!/META-INF/tags/echo.tag");
Assert.assertEquals(expectedURL.toString(), webResource.getURL().toString());
}
use of org.apache.catalina.core.StandardHost in project tomcat by apache.
the class TestCachedResource method testDirectoryListingsPackedWar.
@Test
public void testDirectoryListingsPackedWar() throws Exception {
Tomcat tomcat = getTomcatInstance();
File docBase = new File("test/webresources/war-url-connection.war");
Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath());
((StandardHost) tomcat.getHost()).setUnpackWARs(false);
tomcat.start();
WebResourceRoot root = ctx.getResources();
URL d1 = root.getResource("/").getURL();
try (InputStream is = d1.openStream()) {
Assert.assertNotNull(is);
}
}
use of org.apache.catalina.core.StandardHost in project tomcat by apache.
the class TestHandlerIntegration method testToURI.
@Test
public void testToURI() throws Exception {
Tomcat tomcat = getTomcatInstance();
File docBase = new File("test/webresources/war-url-connection.war");
Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath());
skipTldsForResourceJars(ctx);
((StandardHost) tomcat.getHost()).setUnpackWARs(false);
tomcat.start();
URL url = ctx.getServletContext().getResource("/index.html");
try {
url.toURI();
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
Aggregations