use of org.apache.catalina.webresources.StandardRoot in project tomcat by apache.
the class TestWarDirContext method testReservedJNDIFileNamesNoCache.
/*
* Additional test following on from SPR-7350 above to check files that
* contain JNDI reserved characters can be served when caching is disabled.
*/
@Test
public void testReservedJNDIFileNamesNoCache() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-fragments");
// app dir is relative to server home
StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
StandardRoot root = new StandardRoot();
root.setCachingAllowed(true);
ctxt.setResources(root);
skipTldsForResourceJars(ctxt);
tomcat.start();
// Should be found in resources.jar
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/test/'singlequote.jsp");
Assert.assertEquals("<p>'singlequote.jsp in resources.jar</p>", bc.toString());
// Should be found in file system
bc = getUrl("http://localhost:" + getPort() + "/test/'singlequote2.jsp");
Assert.assertEquals("<p>'singlequote2.jsp in file system</p>", bc.toString());
}
use of org.apache.catalina.webresources.StandardRoot in project tomcat by apache.
the class TestWarDirContext method testReservedJNDIFileNamesWithCache.
/*
* Additional test following on from SPR-7350 above to check files that
* contain JNDI reserved characters can be served when caching is enabled.
*/
@Test
public void testReservedJNDIFileNamesWithCache() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-fragments");
// app dir is relative to server home
StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
StandardRoot root = new StandardRoot();
root.setCachingAllowed(true);
ctxt.setResources(root);
tomcat.start();
// Should be found in resources.jar
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/test/'singlequote.jsp");
Assert.assertEquals("<p>'singlequote.jsp in resources.jar</p>", bc.toString());
// Should be found in file system
bc = getUrl("http://localhost:" + getPort() + "/test/'singlequote2.jsp");
Assert.assertEquals("<p>'singlequote2.jsp in file system</p>", bc.toString());
}
use of org.apache.catalina.webresources.StandardRoot in project hazelcast by hazelcast.
the class ServiceLoaderTest method testClassIteratorInTomcat_whenClassesInBothLibs.
@Test
public void testClassIteratorInTomcat_whenClassesInBothLibs() throws Exception {
ClassLoader launchClassLoader = this.getClass().getClassLoader();
ClassLoader webappClassLoader;
// setup embedded tomcat
Tomcat tomcat = new Tomcat();
// 8080 may be used by some other tests
tomcat.setPort(13256);
Context ctx = tomcat.addContext("", null);
// Map target/classes as WEB-INF/classes, so webapp classloader
// will locate compiled production classes in the webapp classpath.
// The purpose of this setup is to make project classes available
// to both launch classloader and webapplication classloader,
// modeling a Tomcat deployment in which Hazelcast JARs are deployed
// in both tomcat/lib and webapp/lib
File webInfClasses = new File("target/classes");
WebResourceRoot resources = new StandardRoot(ctx);
resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes", webInfClasses.getAbsolutePath(), "/"));
ctx.setResources(resources);
TestServiceLoaderServlet testServlet = new TestServiceLoaderServlet();
Wrapper wrapper = tomcat.addServlet("", "testServlet", testServlet);
wrapper.setLoadOnStartup(1);
ctx.addServletMappingDecoded("/", "testServlet");
tomcat.start();
try {
assertTrueEventually(() -> assertTrue(testServlet.isInitDone()));
assertNull("No failure is expected from servlet init() method", testServlet.failure());
webappClassLoader = testServlet.getWebappClassLoader();
assertNotEquals(launchClassLoader, webappClassLoader);
Iterator<? extends Class<?>> iterator = ServiceLoader.classIterator(DataSerializerHook.class, "com.hazelcast.DataSerializerHook", webappClassLoader);
assertTrue(iterator.hasNext());
while (iterator.hasNext()) {
Class<?> klass = iterator.next();
assertEquals(launchClassLoader, klass.getClassLoader());
}
} finally {
tomcat.stop();
}
}
Aggregations