Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpSession in Grails Application

In my grails application running on tomcat 7, Somewhere I am invalidating the existing http session (session.invalidate()) and creating a new session (request.getSession(true)).

But my 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. I am just using 'session'.

Is there anything in Grails 1.3.7, so that this new session gets reflected every where in app.

Please let me know if you need more info.

Regards

like image 488
user1180463 Avatar asked Sep 25 '26 13:09

user1180463


1 Answers

Well, 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..

This should work for you..

Execute following line Just after you do session.invalidate

//Trick - so that grails doesn't use old invalidated session but rather create new.
GrailsWebRequest.lookup(request).session = null

After that you can use session just as you do normally.. you dont need to create a new session yourself

See this thread for internals

like image 108
Sudhir N Avatar answered Sep 28 '26 02:09

Sudhir N