01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 2005 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: CheckServlet.java 6666 2005-04-28 12:17:19Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.objectweb.sampleCluster2.web;
25:
26: import java.io.IOException;
27:
28: import javax.servlet.RequestDispatcher;
29: import javax.servlet.ServletException;
30: import javax.servlet.http.Cookie;
31: import javax.servlet.http.HttpServletRequest;
32: import javax.servlet.http.HttpServletResponse;
33: import javax.servlet.http.HttpSession;
34:
35: import org.objectweb.util.monolog.api.BasicLevel;
36:
37: /**
38: * @author goebelg
39: *
40: * Servlet which checks the HTTP session
41: */
42: public class CheckServlet extends AbstractServlet {
43:
44: /**
45: *
46: */
47: private static final long serialVersionUID = 1L;
48:
49: /**
50: * doGet methode of the servlet
51: * @param req http servlet request
52: * @param res http servlet response
53: * @throws ServletException servlet exception
54: * @throws IOException io exception
55: */
56: public void doGet(HttpServletRequest req, HttpServletResponse res)
57: throws ServletException, IOException {
58:
59: HttpSession session = req.getSession(false);
60:
61: String sessionCheckInfo = "JSESSIONID cookie absent.";
62: Cookie[] cookies = req.getCookies();
63: if (cookies != null) {
64: for (int i = 0; i < cookies.length; i++) {
65: if (cookies[i].getName().equals("JSESSIONID")) {
66: sessionCheckInfo = "JSESSIONID cookie present.";
67: }
68: }
69: }
70:
71: getLogger().log(BasicLevel.INFO, sessionCheckInfo);
72: req.setAttribute("sessionCheckInfo", sessionCheckInfo);
73:
74: // --------------
75: // Write response
76: // --------------
77: RequestDispatcher disp = req
78: .getRequestDispatcher("../jsp/checkRsp.jsp");
79: disp.forward(req, res);
80:
81: return;
82: }
83: }
|