0 Replies Latest reply on Jul 28, 2010 12:06 PM by wangliyu

    Workaround of monitor HttpSession invalid(timeout)

    wangliyu

      I tried to use Weld in my web proj, I need to implement login/logout, follow the sample login from weld, I found it's missing logout, so on logout action, we need to call HttpSession.invalid() to invalid the session (or http session will timeout in certain time), in reality, we often need to call some business logic to release some locks (for example auto release the login user), so I need to find a way to monitor the HttpSession lifecycle, unfortunately, it's not build in the Weld servlet, and I can't declare the servlet listener separately in the Web.xml (at least for TC6), so here is a work around:


      @Named
      @SessionScoped
      public class LoginSession implement Serializable {


         @PreDestroy
         public void release() {
           // releasing the user here.
         }


      }


      Since in the servlet env, SessionScoped is bound to HttpSession, so if session is invalid, CDI will call PreDestroy method on session scoped object, so you don't need to monitor Session lifecycle method.


      Hope this will help if you have same issue.