问题
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?
回答1:
With dropwizard>0.7
environment.jersey().register(HttpSessionProvider.class);
environment.servlets().setSessionHandler(new SessionHandler());
And then use @Session
annotation in your resource classes.
回答2:
DropWizard does not support sessions out of the box and based on posts by the author in google groups, they aren't planning on supporting it in the future either.
The only way currently would be for you to implement org.eclipse.jetty.server.session.SessionHandler
yourself or look for something that already exists and then call environment.setSessionHandler(...)
And in case you need this info, DW 0.6.2 uses Jetty 8.1.10
You can also checkout http://cosmo-opticon.net/blog/2013/1/23/session-based-security-in-dropwizard and see if you can reuse some of that.
回答3:
REST is by definition stateless so no sessions should be used at all. The same URI should always return the same results regardless of the session state.
来源:https://stackoverflow.com/questions/19970591/how-to-maintain-user-sessions-in-dropwizard