How to maintain user sessions in DropWizard?

AppleGrew picture AppleGrew · Nov 14, 2013 · Viewed 8.1k times · Source

I am looking for a persistent session manager which saves the session on file system (like PHP) that can be used with DropWizard. I see there is one Environment.getSessionHandler(), but I see no documentation on it.

I could write my own but I am hoping for a cooked meal. Will the above SessionHandler is what I am looking for? And how to use that?

Answer

Toilal picture Toilal · Nov 30, 2014

With dropwizard>0.7

environment.jersey().register(HttpSessionProvider.class);
environment.servlets().setSessionHandler(new SessionHandler());

And then use @Session annotation in your resource classes.