Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51558
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 26 Aug 2011 16:03:57 +0000 (16:03 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 26 Aug 2011 16:03:57 +0000 (16:03 +0000)
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
test/org/apache/catalina/startup/TestTomcat.java

index bfb4cf0..d00521d 100644 (file)
@@ -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
index e68e912..8358692 100644 (file)
@@ -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();