Sunday, June 17, 2018

Grails on Groovy > Invalidate Session > Error Handling - Session already invalidated

Problem is that in my grails application, when I invalidating the existing http session using session.invalidate() and creating a new session using request.getSession(true) is working fine for some time.
But this new session is not getting reflected everywhere in grails application. Due to this I do get 'Session already invalidated'.
I don't want to do request.getSession() everywhere, actually I would not get notified when this required or not. I am just using 'session'.
Grails holds the reference to a session object and every time you ask it for a session it returns the same reference.. so if you invalidate a session and then ask for the session it will return the same invalidated session, and cause 'session already invalidated' exception..
Execute following line Just after you do session.invalidate
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest

session.invalidate()
GrailsWebRequest.lookup(request).session = null

No comments:

Post a Comment