Mi piacerebbe scadere tutte le mie sessioni in Tomcat. Testiamo il nostro prodotto sotto Fitnesse e alcune sessioni rimangono e la fine della sessione causa dipendenza tra i test. Io lo faccio a mano con il seguente codice, ma alcune sessioni rimango (posso controllare con il http://localhost:8080/manager/html/list URL)Come posso scadere tutte le mie sessioni in Tomcat?
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);
}
C'è un modo per farlo in modo più efficiente ed immediato con nessuna sessione restante?
Class SessionMap non è thread-safe –