Dropwizard 0.8.x中的会话管理 [英] Session management in Dropwizard 0.8.x

查看:127
本文介绍了Dropwizard 0.8.x中的会话管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以让我了解如何在Dropwizard 0.8.x或更高版本中实现会话管理.到目前为止,我一直在使用Dropwizard 0.7.0并在其中完美运行.但是我真的对迁移到0.8.x时提供的更改文档感到困惑.

Can someone give me insight of how do I implement session management in Dropwizard 0.8.x or above. I was using Dropwizard 0.7.0 till now and working perfectly in it. But I really confused by change docs provided when I migrated to 0.8.x.

在Dropwizard 0.7.0(我以前使用过)中,它的操作类似于以下内容

In Dropwizard 0.7.0 (which I was using previously) it was done like the following

/*MainApplication.class session handler */
environment.jersey().register(HttpSessionProvider.class);
environment.servlets().setSessionHandler(new SessionHandler());


/*Resource.class session check*/
HttpSession session = httpServletRequest.getSession(true);

但是它似乎不再有效,确切地说是HttpSessionProvider.class不存在,并被其他一些实现代替.

But it does not seems working anymore, precisely saying HttpSessionProvider.class is not there and replaced by some other implementations.

这将对显示更改内容非常有帮助. 谢谢.

It would be really helpful someone show to what this is changed to. Thanks.

推荐答案

@Yashwanth Krishnan

@Yashwanth Krishnan

我知道这很旧,但是我注意到会话不是从一个URL到另一个URL维护的,只需在初始化应用程序时添加此代码,会话处理主要是容器的事情,而不是DropWizard特有的.

I know this is old but I noticed that the session was not maintained from one URL to another, simply add this code when you init the application, session handling is mostly a container thing and not specific to DropWizard.

SessionHandler sessionHandler = new SessionHandler();
sessionHandler.getSessionManager().setMaxInactiveInterval(SOME_NUMBER);

    /**
     * By default the session manager tracks sessions by URL and Cookies, we 
     * want to track by cookies only since
     * we are doing a validation on all the app not URL by URL.
     */
    sessionHandler.getSessionManager().setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));

    environment.servlets().setSessionHandler(sessionHandler);

这篇关于Dropwizard 0.8.x中的会话管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆