Search in sources :

Example 86 with StandardContext

use of org.apache.catalina.core.StandardContext in project Synthese_2BIN by TheYoungSensei.

the class Main method main.

public static void main(String[] args) throws Exception {
    Tomcat tomcat = new Tomcat();
    tomcat.setPort(8080);
    StandardContext ctx = (StandardContext) tomcat.addWebapp("/", new File("./web").getAbsolutePath());
    WebResourceRoot resources = new StandardRoot(ctx);
    ctx.setResources(resources);
    tomcat.start();
    tomcat.getServer().await();
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) StandardContext(org.apache.catalina.core.StandardContext) StandardRoot(org.apache.catalina.webresources.StandardRoot) File(java.io.File) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 87 with StandardContext

use of org.apache.catalina.core.StandardContext in project Payara by payara.

the class Request method addSessionCookie.

private void addSessionCookie() {
    if (context != null && context.getCookies() && response != null) {
        String jvmRoute = ((StandardContext) getContext()).getJvmRoute();
        /*
             * Check if context has been configured with jvmRoute for
             * Apache LB. If it has, do not add the JSESSIONID cookie
             * here, but rely on OutputBuffer#addSessionCookieWithJvmRoute
             * to add the jvmRoute enhanced JSESSIONID as a cookie right
             * before the response is flushed.
             */
        if (jvmRoute == null) {
            Cookie newCookie = new Cookie(getContext().getSessionCookieName(), session.getId());
            configureSessionCookie(newCookie);
            ((HttpResponse) response).addSessionCookieInternal(newCookie);
        }
    }
}
Also used : Cookie(javax.servlet.http.Cookie) StandardContext(org.apache.catalina.core.StandardContext) HttpResponse(org.apache.catalina.HttpResponse)

Example 88 with StandardContext

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

the class TestVirtualWebappLoader method testStartInternal.

@Test
public void testStartInternal() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    File appDir = new File("test/webapp-3.0");
    // Must have a real docBase - just use temp
    StandardContext ctx = (StandardContext) tomcat.addContext("", appDir.getAbsolutePath());
    VirtualWebappLoader loader = new VirtualWebappLoader();
    loader.setContainer(ctx);
    ctx.setLoader(loader);
    ctx.setResources(new FileDirContext());
    ctx.resourcesStart();
    File dir = new File("test/webapp-3.0-fragments/WEB-INF/lib");
    loader.setVirtualClasspath(dir.getAbsolutePath() + "/*.jar");
    loader.start();
    String[] repos = loader.getRepositories();
    Assert.assertEquals(2, repos.length);
    loader.stop();
    // ToDo: Why doesn't remove repositories?
    repos = loader.getRepositories();
    Assert.assertEquals(2, repos.length);
    // no leak
    loader.start();
    repos = loader.getRepositories();
    Assert.assertEquals(2, repos.length);
    // clear loader
    ctx.setLoader(null);
    // see tearDown()!
    tomcat.start();
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) FileDirContext(org.apache.naming.resources.FileDirContext) StandardContext(org.apache.catalina.core.StandardContext) File(java.io.File) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 89 with StandardContext

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

the class Benchmarks method doTestManagerBaseCreateSession.

private void doTestManagerBaseCreateSession(int threadCount, int iterCount) {
    // Create a default session manager
    StandardManager mgr = new StandardManager();
    try {
        mgr.startInternal();
    } catch (LifecycleException e) {
    // Ignore - this is expected
    }
    mgr.setContainer(new StandardContext());
    mgr.generateSessionId();
    while (mgr.sessionCreationTiming.size() < ManagerBase.TIMING_STATS_CACHE_SIZE) {
        mgr.sessionCreationTiming.add(null);
    }
    while (mgr.sessionExpirationTiming.size() < ManagerBase.TIMING_STATS_CACHE_SIZE) {
        mgr.sessionExpirationTiming.add(null);
    }
    Thread[] threads = new Thread[threadCount];
    for (int i = 0; i < threadCount; i++) {
        threads[i] = new Thread(new TestThreadCreateSession(mgr, iterCount));
    }
    long start = System.currentTimeMillis();
    for (int i = 0; i < threadCount; i++) {
        threads[i].start();
    }
    for (int i = 0; i < threadCount; i++) {
        try {
            threads[i].join();
        } catch (InterruptedException e) {
            e.printStackTrace();
            Assert.fail(e.getMessage());
        }
    }
    long end = System.currentTimeMillis();
    StringBuilder result = new StringBuilder();
    result.append("Threads: ");
    result.append(threadCount);
    result.append(", Time(ms): ");
    result.append(end - start);
    System.out.println(result.toString());
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) StandardContext(org.apache.catalina.core.StandardContext)

Example 90 with StandardContext

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

the class TestPersistentManagerIntegration method testCreateSessionAndPassivate.

@Test
public void testCreateSessionAndPassivate() throws IOException, LifecycleException, ClassNotFoundException {
    // 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("No active sessions", manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
    String sessionId = getUrl("http://localhost:" + getPort() + "/dummy?no_create_session=false").toString();
    Assert.assertNotNull("Session is stored", store.load(sessionId));
    Assert.assertEquals("All sessions are passivated", manager.getActiveSessions(), 0);
    Assert.assertTrue("One session was 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)

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