Session management

63 views
Skip to first unread message

Andrea Asta

unread,
Mar 27, 2017, 10:14:42 AM3/27/17
to sparkjava
I need to intercept the session destroy to close some handlers, how to do it in Spark Java?
Thanks
Andrea

domin...@gmail.com

unread,
Mar 28, 2017, 10:43:52 AM3/28/17
to sparkjava
Hello,

Unfortunately, the session is not 'directly' available if you are using the Spark singleton for this type of usage. 

You can obtain the session, but only during a route request. eg.

HttpSession session = request.session().raw();

I would suggest using Spark within a container you have full control over. http://sparkjava.com/documentation.html#other-webserver

Starting up an quick, small, embedded Jetty yourself using sparkjava is easy. https://www.eclipse.org/jetty/documentation/9.4.x/embedding-jetty.html

This way you have full control over Session Management; adding hooks for create and destroy are trivial with listeners.

Happy to hear another way if one does exist. Anyone? (This group is pretty silent most of the time.)

-d
Reply all
Reply to author
Forward
0 new messages