user1180463
user1180463

Reputation: 245

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

Upvotes: 3

Views: 2783

Answers (1)

Sudhir N
Sudhir N

Reputation: 4096

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

Upvotes: 5

Related Questions