Session Time out in Seam
radouane.r.marjani.how-to-organize.de Aug 11, 2009 8:21 PMHi,
I try to develop a expired time out in Seam, but I sill have a problem with this.
I have done these Steps:
1.Step: I have a class that implement PhaseListner and I write these Methodes there:
- beforePhase to control if the session is expired, if yes I araise an event whith the name org.jboss.seam.sessionExpired
.
- With observer annotation to this event, the methode sessionExpiredEventListner
is called and throw an exception new ViewExpiredException()
public void beforePhase(PhaseEvent pEvent) { if(null != pEvent) { if(pEvent.getPhaseId() == PhaseId.RESTORE_VIEW) { HttpServletRequest request =(HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); if(request != null){ //if(isSessionExpired && Identity.instance().isLoggedIn()) { if(request.getRequestedSessionId() != null && request.getSession().isNew()){ Events.instance().raiseEvent("jboss.seam.sessionExpired"); } if(request.getRequestedSessionId() == null && request.getSession().isNew()){ Events.instance().raiseEvent("org.jboss.seam.newSession"); } } else {log.info("-------8------>: Request is NULL");} } }else { log.info("------------->PhaseEvent is NULL"); } } @Observer("org.jboss.seam.sessionExpired") public void sessionExpiredEventListener(){ FacesMessages.instance().add("User session expired"); throw new ViewExpiredException(); //Identity.instance().logout(); }
-Step2:
-Because of throw the exception ViewExpiredException
, I define in pages.xml this Exception to go to the page: login.xhtml to logging new:
<exception class="javax.faces.application.ViewExpiredException"> <redirect view-id="/login.xhtml"> <message>Your session has timed out, please try again</message> </redirect> </exception>
- Step 3:
-to set the time out for session in web.xml in 1 minute:
<session-config> <session-timeout>1</session-timeout> </session-config>
After writing this code and testing, I never get the time out session and my development works normally.
Just after conversation time out I go to home.xhtml: From components.xml (I know that the time out of session must be greater then conversation time out, but here just to testing)
<core:manager concurrent-request-timeout="180000" conversation-timeout="180000" conversation-id-parameter="cid" parent-conversation-id-parameter="pid"/>
Can some one tell me, what I did wrong. I see on the forum, there is some discussions about this but I can't get any step forward...
Thanks,
Radouane