我想使我在 Tomcat 中的所有会话都过期。我们在 Fitnesse 下测试我们的产品,一些会话仍然存在,会话结束会导致测试之间存在依赖关系。我使用以下代码手动执行此操作,但仍保留一些会话(我可以使用http://localhost:8080/manager/html/list url 检查它)
public static void expireAllSessions() {
String[] applications = { "a", "b", "c", "d", "e" };
for (String application : applications) {
try {
expireAllSessions(application);
} catch (Exception e) {
logger.error(e);
}
}
}
private static void expireAllSessions(final String application) throws Exception {
// cf doc http://hc.apache.org/httpclient-3.x/authentication.html
HttpClient client = new HttpClient();
client.getParams().setAuthenticationPreemptive(true);
Credentials userPassword = new UsernamePasswordCredentials("tomcat", "tomcat");
client.getState().setCredentials(AuthScope.ANY, userPassword);
String url = "http://localhost:8080/manager/html/expire";
NameValuePair[] parametres = new NameValuePair[] {
new NameValuePair("path", "/" + application),
new NameValuePair("idle", "0")
};
HttpMethod method = new GetMethod(url);
method.setQueryString(parametres);
client.executeMethod(method);
}
有没有办法在没有剩余会话的情况下更有效、更直接地做到这一点?