01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tctest.webapp.servlets;
06:
07: import java.io.IOException;
08: import java.io.PrintWriter;
09:
10: import javax.servlet.http.HttpServlet;
11: import javax.servlet.http.HttpServletRequest;
12: import javax.servlet.http.HttpServletResponse;
13: import javax.servlet.http.HttpSession;
14:
15: public final class SessionConfigServlet extends HttpServlet {
16:
17: public void doGet(HttpServletRequest request,
18: HttpServletResponse response) throws IOException {
19: HttpSession session = request.getSession(true);
20: response.setContentType("text/html");
21: PrintWriter out = response.getWriter();
22:
23: String testCase = request.getParameter("testcase");
24: if ("testCookieDisabled".equals(testCase)) {
25: // cookie enable set to false so we should get no cookies
26: // on second hit (hit=1)
27: String hit = request.getParameter("hit");
28: if ("1".equals(hit) && request.getCookies() != null) {
29: out
30: .println("Still receive cookie when CookiesEnabled=false");
31: }
32: } else if ("testUrlRewritingDisabled".equals(testCase)) {
33: String originalUrl = request.getRequestURI()
34: + "/index.html";
35: String encodedUrl = response.encodeURL(originalUrl);
36: if (!originalUrl.equals(encodedUrl)) {
37: out.println("encodeUrl succeeded: " + encodedUrl);
38: }
39: } else if ("testTrackingDisabled".equals(testCase)) {
40: String hit = request.getParameter("hit");
41: if ("1".equals(hit) && request.getCookies() != null) {
42: out
43: .println("Still receive cookie when TrackingDisabled=false");
44: }
45: String originalUrl = request.getRequestURI()
46: + "/index.html";
47: String encodedUrl = response.encodeURL(originalUrl);
48: if (!originalUrl.equals(encodedUrl)) {
49: out.println("encodeUrl succeeded: " + encodedUrl);
50: }
51: } else if ("testSessionTimeOutArbitrary".equals(testCase)) {
52: out.println(session.getMaxInactiveInterval());
53: } else if ("testSessionTimeOutNegative".equals(testCase)) {
54: int hit = Integer.parseInt(request.getParameter("hit"));
55: if (hit == 0) {
56: out.println(session.getMaxInactiveInterval());
57: session.setAttribute("testSessionTimeOutNegative", "0");
58: } else if (hit == 1) {
59: if (session.getAttribute("testSessionTimeOutNegative") == null) {
60: out.println("session has expired. isNew() returns "
61: + session.isNew());
62: }
63: }
64: }
65: out.println("OK");
66: }
67: }
|