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
ctx.addServletMapping("*.jspx", "jsp");
// Sessions
- ctx.setManager( new StandardManager());
ctx.setSessionTimeout(30);
// MIME mappings
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;
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 {
}
/**
+ * 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 {
}
@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();