我想要在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);
}
有没有一种更高效、立即且没有剩余会话的方法来完成它?