I recently moved a project that uses an embedded Jetty from version 6.1 to 9.4. It was easier than I expected. Now only one feature is left to migrate: The project has an administration tool, that shows all the loaded contexts (it can host more than one web applicaton) and for each context, it lists the registered HTTP sessions, including session attributes etc. In Jetty 6, it goes something like this:
Handler[] handlers = jettyServer.getHandlers();
for (Handler h : handlers) {
if (h instanceof ContextHandlerCollection) {
ContextHandlerCollection ch = (ContextHandlerCollection) h;
Handler[] contexts = ch.getHandlers();
for (Handler context : contexts) {
if (context instanceof WebAppContext) {
WebAppContext wapp = (WebAppContext) context;
// Here, I am stuck in migrating this to jetty 9:
SessionManager sm = wapp.getSessionHandler().getSessionManager();
if (sm instanceof HashSessionManager) {
HashSessionManager hsm = (HashSessionManager) sm;
Map<?,?> sessions = hsm.getSessionMap();
if (sessions != null) {
for (Map.Entry<?,?> entry : sessions.entrySet()) {
if (entry.getValue() instanceof HttpSession) {
HttpSession s = (HttpSession) entry.getValue();
}
}
}
}
}
}
}
}
The new Jetty 9 structure is a bit different, but I was able to access all the contexts. But in Jetty 9, I am unable to access the SessionManager
from the context.
wapp.getSessionHandler().getSessionManager();
Does not work anymore, the getSessionManager()
method on SessionHandler
is not there anymore. And after searching for hours, I did not find any way to get from a WebAppContext
to the HTTPSession
instances in that context.
Does anyone know a way to get there?