This content has been marked as final.
Show 2 replies
-
1. Re: Monitoring Session timeout
rmemoria.ricardo.rmemoria.com.br Mar 31, 2009 6:05 AM (in response to rmemoria.ricardo.rmemoria.com.br)Forget about it... My mistake.
-
2. Re: Monitoring Session timeout
jabinara Apr 18, 2009 7:27 AM (in response to rmemoria.ricardo.rmemoria.com.br)Hi.
I am trying out the same thing, to catch the time stamp of session time out and persist it as logout time. But in the method every object is becoming null so not able to get session object. I am doing like this:
@Observer("org.jboss.seam.preDestroyContext.SESSION")
@Transactional(TransactionPropagationType.REQUIRED)
public void sessionTimeoutListener() {
System.out.println("Bingo !!!!");
HttpSession session = (HttpSession) this.ec.getSession(false);
String sessionId = session.getId();
em.joinTransaction();
List<SessionHistory> sessionHistoryList = em.createQuery("from SessionHistory sh where sh.sessionId = :sessionId order by sh.loginDateTime desc")
.setParameter("sessionId", sessionId)
.getResultList();
SessionHistory sessionHistory = sessionHistoryList.get(0);
sessionHistory.setLogoutDateTime(new Date());
em.persist(sessionHistory);
em.flush();
System.out.println("exiting sessiontimeout");
}
For getting session object, I was trying to do in the famous way, using HttpSessionListener. In this case I m getting the session object, but entity manager is becoming null. It is like this I was doing:
public class SessionTimeOut implements HttpSessionListener{
@In
EntityManager em ;
public void sessionCreated(HttpSessionEvent arg0) {
}
@Transactional(TransactionPropagationType.REQUIRED)
public void sessionDestroyed(HttpSessionEvent arg0) {
System.out.println("Bingo in http!!!!");
HttpSession session = arg0.getSession();
String sessionId = session.getId();
em.joinTransaction();
List<SessionHistory> sessionHistoryList = em.createQuery("from SessionHistory sh where sh.sessionId = :sessionId order by sh.loginDateTime desc")
.setParameter("sessionId", sessionId)
.getResultList();
SessionHistory sessionHistory = sessionHistoryList.get(0);
sessionHistory.setLogoutDateTime(new Date());
em.persist(sessionHistory);
em.flush();
System.out.println("exiting sessiontimeout");
}
}
The third way I applied, is using @WebRemote. In that case atleast I was getting an em from PersistenceContext by calling (EntityManager)Component.getInstance("em");
But then i am getting "no transaction is active".
I know its lots of stuffs I have done, but whats the use if I m not getting the results. Please somebody give an idea about this, before I break my head.
Thanks