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