Ask*_*kov 3 java session session-timeout vaadin
在我的Vaadin应用程序中,当Vaadin在"会话超时"消息后没有使会话无效时,我遇到了问题.收到此消息后,用户有时可以单击链接或刷新页面并继续工作,就好像他们仍在登录一样.我使用以下参数:
closeIdleSessions=true
heartbeatInterval=60
session-timeout=15
Run Code Online (Sandbox Code Playgroud)
最后一个参数(会话超时)也在context.xml(session-timeout = 900)和web.xml(session-config/session-timeout = 15)中设置,因为我没有从vaadin文档中得到清楚,是否有这样的vaadin servlet的参数与否.
有人面对名义上的问题吗?
更新1:固定参数片段.
更新2:出现消息SessionDestroyListener.sessionDestroy时不会触发Session expired.
更新3:由于代码错误而出现上一个错误.现在SessionDestroyListener.sessionDestroy被调用,但我无法访问给HttpSession定的事件.
这是我的SessionDestroyListener代码(请注意其中一个if分支的评论):
private static class SynchronizerSessionDestroyListener implements SessionDestroyListener {
@Override
public void sessionDestroy(SessionDestroyEvent event) {
if (event.getSession() != null){
WrappedSession wrappedSession = event.getSession().getSession();
if (wrappedSession instanceof WrappedHttpSession){
WrappedHttpSession wrappedHttpSession = (WrappedHttpSession) wrappedSession;
HttpSession httpSession = wrappedHttpSession.getHttpSession();
if (httpSession != null){
try {
httpSession.invalidate();
logger.debug("Session '{}' was invalidated", httpSession.getId());
} catch (IllegalStateException e){
// do nothing, already invalidated
logger.debug("Session '{}' was already invalidated: {}", httpSession.getId(), e.getMessage());
}
} else {
logger.warn("Could not invalidate http session for vaadin session: http session is null"); // THIS IS THE BRANCH WHICH IS ACTUALLY GET EXECUTED ON 'SESSION EXPIRED' MESSAGE: event.getSession().getSession() is null!
}
} else {
logger.warn("Could not invalidate http session for vaadin session: event session is not an http session");
}
} else {
logger.warn("Could not invalidate http session for vaadin session: event session is null");
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我如何附加监听器:
public class X extends VaadinServlet {
// different class members
@Override
protected void servletInitialized() throws ServletException {
super.servletInitialized();
getService().addSessionDestroyListener(new SynchronizerSessionDestroyListener());
}
}
Run Code Online (Sandbox Code Playgroud)
我将尝试解释会话失效基本上如何工作,也许这有帮助(我无法从你的问题中读取太多信息):
session-timeout参数内指定的时间后超时
.但是你要考虑心跳间隔.如果心跳间隔短于会话超时(通常是),则心跳将使会话永远保持活动状态.
这是参数closeIdleSessions相关的地方.将此参数设置true为浏览器不会将心跳作为超时的有效请求,而是最后一次非心跳请求.
示例web.xml更好地解释:
<context-param>
<!-- ATTENTION: This value is set in SECONDS -->
<param-name>heartbeatInterval</param-name>
<param-value>180</param-value>
</context-param>
<session-config>
<!-- ATTENTION: This value is set in MINUTES -->
<session-timeout>4</session-timeout>
</session-config>
<servlet>
<servlet-name>VaadinServlet</servlet-name>
<servlet-class>com.example.VaadinServlet</servlet-class>
<init-param>
<param-name>closeIdleSessions</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
Run Code Online (Sandbox Code Playgroud)
使用上面的web.xml,会话将在6分钟后超时(无需用户交互).
说明:
会话超时设置为4分钟,但4分钟没有心跳.下一次心跳将在6分钟.现在,客户端引擎知道会话实际超时并将显示相应的消息.
我不确定使用Vaadin Push时这是否是相同的过程,因为我们有一个从客户端到服务器的连续通道.
资料来源:
Vaadin书 - 4.8.7.Vaadin的会话到期
书 - 4.9.6.其他Servlet配置参数,用户不活动后的会话超时
其他信息:
即将推出的Vaadin 7.6似乎可以改善客户端 - 服务器连接的稳定性:Blog Post
| 归档时间: |
|
| 查看次数: |
2443 次 |
| 最近记录: |