Search in sources :

Example 96 with StandardContext

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));
    }
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) StandardContext(org.apache.catalina.core.StandardContext)

Example 97 with StandardContext

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());
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) StandardContext(org.apache.catalina.core.StandardContext) ContextResource(org.apache.catalina.deploy.ContextResource) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 98 with StandardContext

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());
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) StandardContext(org.apache.catalina.core.StandardContext) File(java.io.File) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 99 with StandardContext

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());
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) ByteChunk(org.apache.tomcat.util.buf.ByteChunk) StandardContext(org.apache.catalina.core.StandardContext) File(java.io.File) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 100 with StandardContext

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;
    }
}
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

StandardContext (org.apache.catalina.core.StandardContext)181 File (java.io.File)72 Tomcat (org.apache.catalina.startup.Tomcat)64 Test (org.junit.Test)52 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)41 Context (org.apache.catalina.Context)32 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)31 StandardHost (org.apache.catalina.core.StandardHost)25 IOException (java.io.IOException)22 Host (org.apache.catalina.Host)18 MalformedURLException (java.net.MalformedURLException)16 JarFile (java.util.jar.JarFile)16 ServletContext (javax.servlet.ServletContext)16 StandardRoot (org.apache.catalina.webresources.StandardRoot)16 URL (java.net.URL)13 InterceptSupport (com.creditease.monitor.interceptframework.InterceptSupport)12 InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)12 HashMap (java.util.HashMap)12 List (java.util.List)12 Container (org.apache.catalina.Container)12