0

I need to invalidate and cleanup active session objects when the JSF application shutdown or tomact shutdown. The following is the code I have written in application scoped bean

@PreDestroy
public void shutdown(){

Map appMap = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap();
Map<String,HttpSession> userSessionMap=(Map<String,HttpSession>)appMap.get("USERS");
log.info("userSessionMap " + userSessionMap);
Set<Entry<String, HttpSession>> entrySet = userSessionMap.entrySet();
for(Entry<String, HttpSession> entry:entrySet){
    HttpSession session = entry.getValue();
    log.info("HttpSession " + session.getId() + " calling invalidate");
    session.invalidate();
}
  }

and the following is overwritten HttpSessionListener

@Override
public void sessionDestroyed(HttpSessionEvent se){

HttpSession session = se.getSession();
String id = session.getId();
LoginActionController controller = (LoginActionController) session.getAttribute("userInfo");
log.info("HttpSession " + id + ", LoginActionController " + controller + " is being destroyed...");
if(controller != null){
    log.info("User " + controller.getUserName() + " is logged out");
    String userName = controller.getUserName();
    ServletContext context = session.getServletContext();
    Object obj = context.getAttribute("USERS");
    if(obj instanceof Map){
    Map map = (Map) obj;
    map.remove(userName);
        RWFacade rWFacade =(RWFacade)session.getAttribute("rWFacade");
        rWFacade.closeFacade();
    }

}
}

when run this code

session.invalidate();

is not getting executed. I missed anything ? Thanks.

vels4j
  • 11,208
  • 5
  • 38
  • 63

1 Answers1

1

To disable session persitence across restart in tomcat you can uncomment a config in $TOMCAT_HOME/conf/context.xml

<!-- Uncomment this to disable session persistence across Tomcat restarts

    <Manager pathname="" /> -->

May be it will help you.

La Chamelle
  • 2,927
  • 4
  • 36
  • 54
  • Thanks for your suggestion but I'm not using any context here and there is no context.xml under tomcatHome/conf. – vels4j Aug 22 '12 at 10:00