use of org.apache.catalina.core.StandardContext in project tomcat70 by apache.
the class TestNamingContext method doTestBug51744.
private void doTestBug51744(boolean exceptionOnFailedWrite) throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.enableNaming();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
ctx.setJndiExceptionOnFailedWrite(exceptionOnFailedWrite);
// Map the test Servlet
Bug51744Servlet bug51744Servlet = new Bug51744Servlet();
Tomcat.addServlet(ctx, "bug51744Servlet", bug51744Servlet);
ctx.addServletMapping("/", "bug51744Servlet");
tomcat.start();
ByteChunk bc = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/", bc, null);
Assert.assertEquals(200, rc);
Assert.assertTrue(bc.toString().contains(Bug51744Servlet.EXPECTED));
if (exceptionOnFailedWrite) {
Assert.assertTrue(bc.toString().contains(Bug51744Servlet.ERROR_MESSAGE));
}
}
use of org.apache.catalina.core.StandardContext in project tomcat70 by apache.
the class TestNamingContext method testListBindings.
@Test
public void testListBindings() throws Exception {
Tomcat tomcat = getTomcatInstance();
tomcat.enableNaming();
// No file system docBase required
StandardContext ctx = (StandardContext) tomcat.addContext("", null);
// Create the resource
ContextResource cr = new ContextResource();
cr.setName("list/foo");
cr.setType("org.apache.naming.resources.TesterObject");
cr.setProperty("factory", "org.apache.naming.resources.TesterFactory");
ctx.getNamingResources().addResource(cr);
// Map the test Servlet
Bug23950Servlet bug23950Servlet = new Bug23950Servlet();
Tomcat.addServlet(ctx, "bug23950Servlet", bug23950Servlet);
ctx.addServletMapping("/", "bug23950Servlet");
tomcat.start();
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
Assert.assertEquals("org.apache.naming.resources.TesterObject", bc.toString());
}
use of org.apache.catalina.core.StandardContext in project tomcat70 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-3.0-fragments");
// app dir is relative to server home
StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
ctxt.setCachingAllowed(true);
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.core.StandardContext in project tomcat70 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-3.0-fragments");
// app dir is relative to server home
StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
ctxt.setCachingAllowed(false);
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.core.StandardContext 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