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();
}
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);
}
}
}
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();
}
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());
}
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());
}
Aggregations