我正在开发一个 Wicket 应用程序 (wicket 8),为了将其容器化,我添加了一个像
GET /probe/
这样的活动端点,我在返回空页面的虚拟 ProbeApplication(非身份验证应用程序)中处理它。一切顺利,但对于每个请求,Jetty 框架都会创建一个新的 HttpSession,返回到第一个请求
302 Found
Location: http://localhost:8888/probe/;jsessionid=node01t8hgfnbo8d8rgpyws9neqguv0.node0?0
会话过期需要几个小时(我希望用户的会话时间较长),因此应用程序会累积 O(10k) 个空会话,我想避免这种情况。 有没有办法在处理某些类型的请求时不创建Session而只返回
200 OK
?
附注我意识到我在这里讨论的不是 wicket WebSession 对象,而是 Jetty servlet 容器创建的 HttpSession。事实上我的应用程序会话没有创建。所以问题应该是这样的:如何使特定端点的 Jetty HttpSession 失效,或者如何禁用它的会话跟踪。
public class WebApplicationProbe extends WebApplication {
@Override public Class<? extends WebPage> getHomePage() {
return org.apache.wicket.util.tester.DummyHomePage.class; }
@Override public final Session newSession(Request request, Response response) {
WebSession ws = new WebSession(request) ;
System.err.println("Created new web session");
return ws ; }
}
谢谢!
在 Jetty 中,仅当应用程序(或其库)请求创建会话时才会创建
jakarta.servlet.http.HttpSession
。
换句话说,您可以致电...
jakarta.servlet.http.HttpServletRequest.getSession(true)
jakarta.servlet.http.HttpServletRequest.getSession()
如果您将探针更改为使用
jakarta.servlet.http.HttpServletRequest.getSession(false)
,则不会创建 HttpSession(如果尚不存在)。