Search in sources :

Example 91 with StandardContext

use of org.apache.catalina.core.StandardContext in project tomcat70 by apache.

the class TestPersistentManagerIntegration method noSessionCreate_57637.

@Test
public void noSessionCreate_57637() throws IOException, LifecycleException {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    StandardContext ctx = (StandardContext) tomcat.addContext("", null);
    ctx.setDistributable(true);
    Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet());
    ctx.addServletMapping("/dummy", "DummyServlet");
    PersistentManager manager = new PersistentManager();
    TesterStore store = new TesterStore();
    manager.setStore(store);
    manager.setMaxIdleBackup(0);
    ctx.setManager(manager);
    ctx.addValve(new PersistentValve());
    tomcat.start();
    Assert.assertEquals(manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
    Assert.assertEquals("NO_SESSION", getUrl("http://localhost:" + getPort() + "/dummy?no_create_session=true").toString());
    Assert.assertEquals(manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions where created", manager.getSessionIdsFull().isEmpty());
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) StandardContext(org.apache.catalina.core.StandardContext) PersistentValve(org.apache.catalina.valves.PersistentValve) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 92 with StandardContext

use of org.apache.catalina.core.StandardContext in project tomcat70 by apache.

the class TestWebappClassLoaderMemoryLeak method testTimerThreadLeak.

@Test
public void testTimerThreadLeak() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    if (ctx instanceof StandardContext) {
        ((StandardContext) ctx).setClearReferencesStopTimerThreads(true);
    }
    Tomcat.addServlet(ctx, "taskServlet", new TaskServlet());
    ctx.addServletMapping("/", "taskServlet");
    tomcat.start();
    // This will trigger the timer & thread creation
    getUrl("http://localhost:" + getPort() + "/");
    // Stop the context
    ctx.stop();
    Thread[] threads = getThreads();
    for (Thread thread : threads) {
        if (thread != null && thread.isAlive() && TaskServlet.TIMER_THREAD_NAME.equals(thread.getName())) {
            thread.join(5000);
            if (thread.isAlive()) {
                Assert.fail("Timer thread still running");
            }
        }
    }
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) Tomcat(org.apache.catalina.startup.Tomcat) StandardContext(org.apache.catalina.core.StandardContext) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 93 with StandardContext

use of org.apache.catalina.core.StandardContext in project tomcat70 by apache.

the class TestGenerator method testBug48701Fail.

@Test
public void testBug48701Fail() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
    // This test needs the JSTL libraries
    File lib = new File("webapps/examples/WEB-INF/lib");
    ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());
    tomcat.start();
    int rc = getUrl("http://localhost:" + getPort() + "/test/bug48nnn/bug48701-fail.jsp", new ByteChunk(), null);
    Assert.assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, rc);
}
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 94 with StandardContext

use of org.apache.catalina.core.StandardContext in project tomcat70 by apache.

the class TestParser method testBug56265.

@Test
public void testBug56265() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
    // This test needs the JSTL libraries
    File lib = new File("webapps/examples/WEB-INF/lib");
    ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());
    tomcat.start();
    ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug56265.jsp");
    String result = res.toString();
    Assert.assertTrue(result, result.contains("[1: [data-test]: [window.alert('Hello World <&>!')]]"));
    Assert.assertTrue(result, result.contains("[2: [data-test]: [window.alert('Hello World <&>!')]]"));
    Assert.assertTrue(result, result.contains("[3: [data-test]: [window.alert('Hello 'World <&>'!')]]"));
    Assert.assertTrue(result, result.contains("[4: [data-test]: [window.alert('Hello 'World <&>'!')]]"));
}
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 95 with StandardContext

use of org.apache.catalina.core.StandardContext in project tomcat70 by apache.

the class TestParser method testBug56334And56561.

@Test
public void testBug56334And56561() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
    // This test needs the JSTL libraries
    File lib = new File("webapps/examples/WEB-INF/lib");
    ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());
    tomcat.start();
    ByteChunk res = getUrl("http://localhost:" + getPort() + "/test/bug5nnnn/bug56334and56561.jspx");
    String result = res.toString();
    // NOTE: The expected values must themselves be \ escaped below
    Assert.assertTrue(result, result.contains("01a\\?resize01a"));
    Assert.assertTrue(result, result.contains("01b\\\\x\\?resize01b"));
    Assert.assertTrue(result, result.contains("<set data-value=\"02a\\\\?resize02a\"/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"02b\\\\\\\\x\\\\?resize02b\"/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"03a\\?resize03a\"/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"03b\\\\x\\?resize03b\"/>"));
    Assert.assertTrue(result, result.contains("<04a\\?resize04a/>"));
    Assert.assertTrue(result, result.contains("<04b\\\\x\\?resize04b/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"05a$${&amp;\"/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"05b$${&amp;2\"/>"));
    Assert.assertTrue(result, result.contains("<set data-value=\"05c##{&gt;hello&lt;\"/>"));
    Assert.assertTrue(result, result.contains("05x:<set data-value=\"\"/>"));
    Assert.assertTrue(result, result.contains("<set xmlns:foo=\"urn:06a\\bar\\baz\"/>"));
    Assert.assertTrue(result, result.contains("07a:<set data-value=\"\\?resize\"/>"));
    Assert.assertTrue(result, result.contains("07b:<set data-content=\"\\?resize=.+\"/>"));
    Assert.assertTrue(result, result.contains("07c:<set data-content=\"\\?resize=.+\"/>"));
    Assert.assertTrue(result, result.contains("07d:<set data-content=\"false\"/>"));
    Assert.assertTrue(result, result.contains("07e:<set data-content=\"false\"/>"));
    Assert.assertTrue(result, result.contains("07f:<set data-content=\"\\\'something\'\"/>"));
    Assert.assertTrue(result, result.contains("07g:<set data-content=\"\\\'something\'\"/>"));
}
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)

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