public EmbeddedJettyServer(int port, boolean useRestSession) throws Exception { server = new Server(); connector = new SelectChannelConnector(); connector.setPort(port); server.addConnector(connector); root = new WebAppContext(); root.setContextPath("/"); root.setResourceBase("."); if (useRestSession) { RestSessionIdManager idManager = new RestSessionIdManager(); RestSessionManager sessionManager = new RestSessionManager(); server.setSessionIdManager(idManager); sessionManager.setSessionIdManager(idManager); SessionHandler sessionHandler = new SessionHandler(); sessionHandler.setSessionManager(sessionManager); root.setSessionHandler(sessionHandler); root.setClassLoader(getContextClassLoader()); } server.setHandler(root); server.start(); while (!server.isStarted()) { Thread.sleep(100); } }
private void persistSession(WebAppContext webApp) { String storeDir = getStoreDir(); SessionManager sm = webApp.getSessionHandler().getSessionManager(); if (sm instanceof HashSessionManager) { ((HashSessionManager) sm).setStoreDirectory(new File(storeDir)); return; } HashSessionManager hsm = new HashSessionManager(); hsm.setStoreDirectory(new File(storeDir)); SessionHandler sh = new SessionHandler(); sh.setSessionManager(hsm); webApp.setSessionHandler(sh); }