From 653434bbe7faf8e204b7187c0f5b14bf4c93cf9b Mon Sep 17 00:00:00 2001 From: markt Date: Fri, 26 Aug 2011 16:03:57 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51558 No need to force the use of the StandardManager with addWebapp() since StandardContext will add it if it is not set. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1162149 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/startup/Tomcat.java | 2 -- test/org/apache/catalina/startup/TestTomcat.java | 38 +++++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/java/org/apache/catalina/startup/Tomcat.java b/java/org/apache/catalina/startup/Tomcat.java index bfb4cf0c1..d00521d72 100644 --- a/java/org/apache/catalina/startup/Tomcat.java +++ b/java/org/apache/catalina/startup/Tomcat.java @@ -55,7 +55,6 @@ import org.apache.catalina.core.StandardWrapper; import org.apache.catalina.deploy.LoginConfig; import org.apache.catalina.realm.GenericPrincipal; import org.apache.catalina.realm.RealmBase; -import org.apache.catalina.session.StandardManager; // TODO: lazy init for the temp dir - only when a JSP is compiled or // get temp dir is called we need to create it. This will avoid the @@ -747,7 +746,6 @@ public class Tomcat { ctx.addServletMapping("*.jspx", "jsp"); // Sessions - ctx.setManager( new StandardManager()); ctx.setSessionTimeout(30); // MIME mappings diff --git a/test/org/apache/catalina/startup/TestTomcat.java b/test/org/apache/catalina/startup/TestTomcat.java index e68e9125f..8358692e0 100644 --- a/test/org/apache/catalina/startup/TestTomcat.java +++ b/test/org/apache/catalina/startup/TestTomcat.java @@ -35,6 +35,7 @@ import javax.naming.NamingException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -51,7 +52,7 @@ import org.apache.tomcat.util.buf.ByteChunk; public class TestTomcat extends TomcatBaseTest { /** - * Simple servlet to test in-line registration + * Simple servlet to test in-line registration. */ public static class HelloWorld extends HttpServlet { @@ -65,6 +66,22 @@ public class TestTomcat extends TomcatBaseTest { } /** + * Simple servlet to test the default session manager. + */ + public static class HelloWorldSession extends HttpServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse res) + throws IOException { + HttpSession s = req.getSession(true); + s.getId(); + res.getWriter().write("Hello world"); + } + } + + /** * Simple servlet to test JNDI */ public static class HelloWorldJndi extends HttpServlet { @@ -238,6 +255,25 @@ public class TestTomcat extends TomcatBaseTest { } @Test + public void testSession() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + // Must have a real docBase - just use temp + org.apache.catalina.Context ctx = + tomcat.addContext("", System.getProperty("java.io.tmpdir")); + // You can customize the context by calling + // its API + + Tomcat.addServlet(ctx, "myServlet", new HelloWorldSession()); + ctx.addServletMapping("/", "myServlet"); + + tomcat.start(); + + ByteChunk res = getUrl("http://localhost:" + getPort() + "/"); + assertEquals("Hello world", res.toString()); + } + + @Test public void testLaunchTime() throws Exception { Tomcat tomcat = getTomcatInstance(); long t0 = System.currentTimeMillis(); -- 2.11.0