В моем веб-приложении есть пользователи, которые входят в систему.Тайм-аутДо истечения сеанса я хотел бы выполнить метод для очистки некоторых блокировок.
Я реализовал sessionListener
, но как только я достиг public void sessionDestroyed(HttpSessionEvent event)
, сеанс уже закончился, и мне нужны некоторые данные из него, поэтому я хотел бы выполнить метод (которому нужен сеанс живым и иметь доступ к FacesConfig.getCurrentInstance()
) до истечения срока действия сеанса.
Как я могу это сделать?Есть идеи?Это мой слушатель сессии:
public class MySessionListener implements HttpSessionListener {
private static final Logger log = LoggerFactory.getLogger(MySessionListener.class);
public MySessionListener() {
}
public void sessionCreated(HttpSessionEvent event) {
log.debug("Current Session created : "
+ event.getSession().getId()+ " at "+ new Date());
}
public void sessionDestroyed(HttpSessionEvent event) {
// get the destroying session...
HttpSession session = event.getSession();
prepareLogoutInfoAndLogoutActiveUser(session);
log.debug("Current Session destroyed :"
+ session.getId()+ " Logging out user...");
/*
* nobody can reach user data after this point because
* session is invalidated already.
* So, get the user data from session and save its
* logout information before losing it.
* User's redirection to the timeout page will be
* handled by the SessionTimeoutFilter.
*/
// Only if needed
}
/**
* Clean your logout operations.
*/
public void prepareLogoutInfoAndLogoutActiveUser(HttpSession httpSession) {
UserBean user = FacesContext.getCurrentInstance().getApplication().evaluateExpressionGet(FacesContext.getCurrentInstance(), "#{user}", UserBean.class);
LockBean lock = FacesContext.getCurrentInstance().getApplication().evaluateExpressionGet(FacesContext.getCurrentInstance(), "#{lock}", LockBean.class);
lock.unlock(user.getUsername());
log.info("Unlocked examination for user: "+user.getUsername());
}
}
Но я получаю NullPointerException
на FacesContext.getCurrentInstance().getApplication()
, потому что либо getCurrentInstance
равно нулю, либо getApplication
возвращает ноль