1 22 package org.jboss.test.web.servlets; 23 24 import java.util.HashMap ; 25 import java.util.Enumeration ; 26 import javax.servlet.http.HttpSessionListener ; 27 import javax.servlet.http.HttpSessionEvent ; 28 import javax.servlet.http.HttpSession ; 29 30 import org.jboss.logging.Logger; 31 32 38 public class TestSessionListener implements HttpSessionListener 39 { 40 static Logger log = Logger.getLogger(TestSessionListener.class); 41 static HashMap eventMap = new HashMap (); 42 43 static boolean wasCreated(String sessionID) 44 { 45 boolean[] events = (boolean[]) eventMap.get(sessionID); 46 if( events == null ) 47 return false; 48 return events[0]; 49 } 50 static boolean wasDestroyed(String sessionID) 51 { 52 boolean[] events = (boolean[]) eventMap.get(sessionID); 53 if( events == null ) 54 return false; 55 return events[1]; 56 } 57 58 public void sessionCreated(HttpSessionEvent event) 59 { 60 String sessionID = event.getSession().getId(); 61 log.info("sessionCreated, sessionID="+sessionID); 62 boolean[] events = {true, false}; 63 eventMap.put(sessionID, events); 64 } 65 66 public void sessionDestroyed(HttpSessionEvent event) 67 { 68 String sessionID = event.getSession().getId(); 69 log.info("sessionDestroyed, sessionID="+sessionID); 70 HttpSession session = event.getSession(); 71 Enumeration names = session.getAttributeNames(); 72 while( names.hasMoreElements() ) 73 { 74 String name = (String ) names.nextElement(); 75 log.info(name+"="+session.getAttribute(name)); 76 } 77 boolean[] events = (boolean[]) eventMap.get(sessionID); 78 events[1] = true; 79 } 80 } 81 | Popular Tags |