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.listeners;
06:
07: import com.tctest.webapp.servlets.ListenerReportingServlet;
08:
09: import javax.servlet.http.HttpSession;
10: import javax.servlet.http.HttpSessionEvent;
11: import javax.servlet.http.HttpSessionListener;
12:
13: public class SessionListener implements HttpSessionListener {
14: public SessionListener() {
15: System.err.println("### SessionListener() is here!!!");
16: }
17:
18: public void sessionCreated(HttpSessionEvent httpsessionevent) {
19: System.err
20: .println("### SessionListener.sessionCreated() is here!!!");
21: ListenerReportingServlet
22: .incrementCallCount("SessionListener.sessionCreated");
23: }
24:
25: public void sessionDestroyed(HttpSessionEvent httpsessionevent) {
26: testAttributeAccess(httpsessionevent.getSession());
27: System.err
28: .println("### SessionListener.sessionDestroyed() is here!!!");
29: ListenerReportingServlet
30: .incrementCallCount("SessionListener.sessionDestroyed");
31: }
32:
33: private void testAttributeAccess(HttpSession session) {
34: // While session destroyed event is being called, you should still be able to get
35: // attributes
36:
37: String[] attrs = session.getValueNames();
38: if (attrs == null || attrs.length == 0) {
39: // please make at least one attribute is present
40: throw new AssertionError(
41: "Attributes should be present during this phase");
42: }
43:
44: for (int i = 0; i < attrs.length; i++) {
45: String attr = attrs[i];
46: session.getAttribute(attr);
47: }
48: }
49: }
|