Java 类org.eclipse.jetty.server.session.HashSessionManager 实例源码

项目:pinto    文件:Demo.java   
public void run() throws Exception {
    org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
    Server server = new Server(port);
       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       context.setContextPath("/");
       context.setWelcomeFiles(new String[]{ "demo.html" });
       context.setResourceBase(httpPath);
       HashSessionIdManager idmanager = new HashSessionIdManager();
       server.setSessionIdManager(idmanager);
       HashSessionManager manager = new HashSessionManager();
       SessionHandler sessions = new SessionHandler(manager);
       sessions.setHandler(context);
       context.addServlet(new ServletHolder(new Servlet(this::getPinto)),"/pinto/*");
       ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
       context.addServlet(holderPwd,"/*");
       server.setHandler(sessions);
       server.start();
       server.join();
}
项目:pinto    文件:Main.java   
public void run() throws Exception {

        org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
        Server server = new Server(port);
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        context.setResourceBase(httpPath);
        HashSessionIdManager idmanager = new HashSessionIdManager();
        server.setSessionIdManager(idmanager);
        HashSessionManager manager = new HashSessionManager();
        SessionHandler sessions = new SessionHandler(manager);
        sessions.setHandler(context);
        context.addServlet(new ServletHolder(new Servlet(this::getPinto)),"/pinto/*");
        ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
        context.addServlet(holderPwd,"/*");
        server.setHandler(sessions);
        new Thread(new Console(getPinto(),port,build, () -> {
            try {
                server.stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }), "console_thread").start();
        server.start();
        server.join();
    }
项目:MoodCat.me-Core    文件:App.java   
private ContextHandlerCollection attachHandlers(final File staticsFolder, final Module... overrides) {
    final MoodcatHandler moodcatHandler = new MoodcatHandler(this, staticsFolder, overrides);

    final ResourceHandler resources = new ResourceHandler();
    resources.setBaseResource(Resource.newResource(staticsFolder));
    resources.setDirectoriesListed(false);
    resources.setCacheControl("max-age=3600");

    final HashSessionManager hashSessionManager = new HashSessionManager();
    hashSessionManager.setMaxInactiveInterval(SESSION_KEEP_ALIVE);

    final ContextHandlerCollection handlers = new ContextHandlerCollection();
    // CHECKSTYLE:OFF
    handlers.addContext("/", "/").setHandler(resources);
    handlers.addContext("/", "/").setHandler(moodcatHandler);
    // CHECKSTYLE:ON

    return handlers;
}
项目:commafeed    文件:SessionManagerFactory.java   
public SessionManager build() throws IOException {
    HashSessionManager manager = new HashSessionManager();
    manager.setSessionTrackingModes(ImmutableSet.of(SessionTrackingMode.COOKIE));
    manager.setHttpOnly(true);
    manager.getSessionCookieConfig().setHttpOnly(true);
    manager.setDeleteUnrestorableSessions(true);

    manager.setStoreDirectory(new File(getPath()));
    manager.getSessionCookieConfig().setMaxAge((int) cookieMaxAge.toSeconds());
    manager.setRefreshCookieAge((int) cookieRefreshAge.toSeconds());
    manager.setMaxInactiveInterval((int) maxInactiveInterval.toSeconds());
    manager.setIdleSavePeriod((int) idleSavePeriod.toSeconds());
    manager.setSavePeriod((int) savePeriod.toSeconds());
    manager.setScavengePeriod((int) scavengePeriod.toSeconds());
    return manager;
}
项目:traccar-service    文件:WebServer.java   
public WebServer(Config config, DataSource dataSource) {
    this.config = config;
    this.dataSource = dataSource;

    sessionManager = new HashSessionManager();
    int sessionTimeout = config.getInteger("web.sessionTimeout");
    if (sessionTimeout != 0) {
        sessionManager.setMaxInactiveInterval(sessionTimeout);
    }

    initServer();
    initApi();
    if (config.getBoolean("web.console")) {
        initConsole();
    }
    switch (config.getString("web.type", "new")) {
        case "old":
            initOldWebApp();
            break;
        default:
            initWebApp();
            break;
    }
    initClientProxy();
    server.setHandler(handlers);

    server.addBean(new ErrorHandler() {
        @Override
        protected void handleErrorPage(
                HttpServletRequest request, Writer writer, int code, String message) throws IOException {
            writer.write("<!DOCTYPE<html><head><title>Error</title></head><html><body>"
                    + code + " - " + HttpStatus.getMessage(code) + "</body></html>");
        }
    }, false);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JettyEmbeddedServletContainerFactory.java   
private void configureSession(WebAppContext context) {
    SessionManager sessionManager = context.getSessionHandler().getSessionManager();
    int sessionTimeout = (getSessionTimeout() > 0 ? getSessionTimeout() : -1);
    sessionManager.setMaxInactiveInterval(sessionTimeout);
    if (isPersistSession()) {
        Assert.isInstanceOf(HashSessionManager.class, sessionManager,
                "Unable to use persistent sessions");
        configurePersistSession(sessionManager);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JettyEmbeddedServletContainerFactory.java   
private void configurePersistSession(SessionManager sessionManager) {
    try {
        ((HashSessionManager) sessionManager)
                .setStoreDirectory(getValidSessionStoreDir());
    }
    catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
项目:flowable-engine    文件:TestServerUtil.java   
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    WebConfigurer configurer = new WebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);

    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);

    return contextHandler;
}
项目:flowable-engine    文件:BaseJPARestTestCase.java   
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    JPAWebConfigurer configurer = new JPAWebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);

    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);

    return contextHandler;
}
项目:flowable-engine    文件:TestServerUtil.java   
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    WebConfigurer configurer = new WebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);

    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);

    return contextHandler;
}
项目:flowable-engine    文件:TestServerUtil.java   
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    WebConfigurer configurer = new WebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);

    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);

    return contextHandler;
}
项目:Wiab.pro    文件:ServerRpcProvider.java   
private void restoreSessions() {
  try {
    HashSessionManager hashSessionManager = (HashSessionManager) jettySessionManager;
    hashSessionManager.setStoreDirectory(FileUtils.createDirIfNotExists(sessionStoreDir,
        "Session persistence"));
    hashSessionManager.setSavePeriod(60);
    hashSessionManager.setMaxInactiveInterval(-1);
    hashSessionManager.restoreSessions();
  } catch (Exception e) {
    LOG.warning("Cannot restore sessions");
  }
}
项目:Wiab.pro    文件:ServerModule.java   
@Provides
@Singleton
public org.eclipse.jetty.server.SessionManager provideSessionManager(
    @Named(CoreSettings.SESSION_COOKIE_MAX_AGE) int sessionCookieMaxAge) {
  HashSessionManager sessionManager = new HashSessionManager();
  sessionManager.getSessionCookieConfig().setMaxAge(sessionCookieMaxAge);
  return sessionManager;
}
项目:spring-boot-concourse    文件:JettyEmbeddedServletContainerFactory.java   
private void configureSession(WebAppContext context) {
    SessionManager sessionManager = context.getSessionHandler().getSessionManager();
    int sessionTimeout = (getSessionTimeout() > 0 ? getSessionTimeout() : -1);
    sessionManager.setMaxInactiveInterval(sessionTimeout);
    if (isPersistSession()) {
        Assert.isInstanceOf(HashSessionManager.class, sessionManager,
                "Unable to use persistent sessions");
        configurePersistSession(sessionManager);
    }
}
项目:spring-boot-concourse    文件:JettyEmbeddedServletContainerFactory.java   
private void configurePersistSession(SessionManager sessionManager) {
    try {
        ((HashSessionManager) sessionManager)
                .setStoreDirectory(getValidSessionStoreDir());
    }
    catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
项目:Camel    文件:WebsocketComponent.java   
protected Server createStaticResourcesServer(Server server, ServletContextHandler context, String home) throws Exception {

        context.setContextPath("/");

        SessionManager sm = new HashSessionManager();
        SessionHandler sh = new SessionHandler(sm);
        context.setSessionHandler(sh);

        if (home != null) {
            String[] resources = home.split(":");
            if (LOG.isDebugEnabled()) {
                LOG.debug(">>> Protocol found: " + resources[0] + ", and resource: " + resources[1]);
            }

            if (resources[0].equals("classpath")) {
                // Does not work when deployed as a bundle
                // context.setBaseResource(new JettyClassPathResource(getCamelContext().getClassResolver(), resources[1]));
                URL url = this.getCamelContext().getClassResolver().loadResourceAsURL(resources[1]);
                context.setBaseResource(Resource.newResource(url));
            } else if (resources[0].equals("file")) {
                context.setBaseResource(Resource.newResource(resources[1]));
            }
            DefaultServlet defaultServlet = new DefaultServlet();
            ServletHolder holder = new ServletHolder(defaultServlet);

            // avoid file locking on windows
            // http://stackoverflow.com/questions/184312/how-to-make-jetty-dynamically-load-static-pages
            holder.setInitParameter("useFileMappedBuffer", "false");
            context.addServlet(holder, "/");
        }

        server.setHandler(context);

        return server;
    }
项目:contestparser    文件:JettyEmbeddedServletContainerFactory.java   
private void configureSession(WebAppContext context) {
    SessionManager sessionManager = context.getSessionHandler().getSessionManager();
    int sessionTimeout = (getSessionTimeout() > 0 ? getSessionTimeout() : -1);
    sessionManager.setMaxInactiveInterval(sessionTimeout);
    if (isPersistSession()) {
        Assert.isInstanceOf(HashSessionManager.class, sessionManager,
                "Unable to use persistent sessions");
        configurePersistSession(sessionManager);
    }
}
项目:contestparser    文件:JettyEmbeddedServletContainerFactory.java   
private void configurePersistSession(SessionManager sessionManager) {
    try {
        ((HashSessionManager) sessionManager)
                .setStoreDirectory(getValidSessionStoreDir());
    }
    catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
项目:stoneboard    文件:Service.java   
@Override
public void run(final Configuration configuration, final Environment environment) throws Exception {
    // FIXME: Doesn't scale to 1+ dynos
    final String githubHostname = optionalEnv("GITHUB_HOSTNAME").orElse("github.com");
    environment.servlets().setSessionHandler(new SessionHandler(new HashSessionManager()));
    environment.jersey().register(new Milestones(asList(env("REPOSITORIES").split(",")), githubHostname));
    environment.jersey().register(new OAuth(env("GITHUB_CLIENT_ID"), env("GITHUB_CLIENT_SECRET"), githubHostname));
    environment.jersey().register(new Github(githubHostname));
    environment.jersey().register(GithubExceptionMapper.class);
}
项目:pipes    文件:SessionManagerConfig.java   
public static void configure(HashSessionManager sessionManager) {
    sessionManager.setHttpOnly(true);
    sessionManager.setSessionCookie("APPSESSIONID");
    try {
        Path dir = Files.createDirectories(Paths.get(System.getProperty("java.io.tmpdir"), "app-session-store"));
        sessionManager.setStoreDirectory(dir.toFile());
    } catch (IOException e) {
        logger.warn(e.getMessage(), e);
    }
}
项目:pipes    文件:ExampleApp.java   
@Override
public void configure(ConfigurableApp<Pipes> app) {
    app.configure(SessionManager.class, HashSessionManager::new, SessionManagerConfig::configure);
    app.configure(ObjectMapper.class, JacksonJsonConfig::configure);
    app.configure((LoggerContext) LoggerFactory.getILoggerFactory(), LogbackConfig::configure);
    app.configure(org.hibernate.cfg.Configuration.class, HibernateConfig::configure);
}
项目:gocd    文件:HttpTestUtil.java   
public HttpTestUtil(final ContextCustomizer customizer) throws Exception {
      Security.addProvider(new BouncyCastleProvider());
      serverKeyStore = createTempFile("server.jks");
      prepareCertStore(serverKeyStore);
      server = new Server();
WebAppContext ctx = new WebAppContext();
      SessionManager sm = new HashSessionManager();
      SessionHandler sh = new SessionHandler(sm);
      ctx.setSessionHandler(sh);
      customizer.customize(ctx);
      ctx.setContextPath("/go");
server.setHandler(ctx);
  }
项目:incubator-wave    文件:ServerRpcProvider.java   
private void restoreSessions() {
  try {
    HashSessionManager hashSessionManager = (HashSessionManager) jettySessionManager;
    hashSessionManager.setStoreDirectory(FileUtils.createDirIfNotExists(sessionStoreDir,
        "Session persistence"));
    hashSessionManager.setSavePeriod(60);
    hashSessionManager.restoreSessions();
  } catch (Exception e) {
    LOG.warning("Cannot restore sessions");
  }
}
项目:incubator-wave    文件:ServerModule.java   
@Provides
@Singleton
public org.eclipse.jetty.server.SessionManager provideSessionManager(Config config) {
  HashSessionManager sessionManager = new HashSessionManager();
  sessionManager.getSessionCookieConfig().setMaxAge(config.getInt("network.session_cookie_max_age"));
  return sessionManager;
}
项目:e-voting    文件:JettyRunner.java   
public static Server run(ResourceConfig application, Properties properties, int port, String originFilter,
                         String aliasName, File keystoreFile, String password, String frontendRoot, String apiPathPattern, boolean copyWebDir) {
    try {
        QueuedThreadPool threadPool = new QueuedThreadPool(
                Integer.valueOf(properties.getProperty("jetty.maxThreads")),
                Integer.valueOf(properties.getProperty("jetty.minThreads")),
                Integer.valueOf(properties.getProperty("jetty.idleTimeout")),
                new ArrayBlockingQueue<>(Integer.valueOf(properties.getProperty("jetty.maxQueueSize"))));
        Server server = new Server(threadPool);
        HttpConfiguration config = new HttpConfiguration();

        if (keystoreFile != null) {
            log.info("Jetty runner {}. SSL enabled.", application.getClass());
            SslContextFactory sslFactory = new SslContextFactory();
            sslFactory.setCertAlias(aliasName);

            String path = keystoreFile.getAbsolutePath();
            if (!keystoreFile.exists()) {
                log.error("Couldn't load keystore file: {}", path);
                return null;
            }
            sslFactory.setKeyStorePath(path);
            sslFactory.setKeyStorePassword(password);
            sslFactory.setKeyManagerPassword(password);
            sslFactory.setTrustStorePath(path);
            sslFactory.setTrustStorePassword(password);

            config.setSecureScheme("https");
            config.setSecurePort(port);
            config.addCustomizer(new SecureRequestCustomizer());

            ServerConnector https = new ServerConnector(server,
                    new SslConnectionFactory(sslFactory, "http/1.1"),
                    new HttpConnectionFactory(config));
            https.setPort(port);
            server.setConnectors(new Connector[]{https});
        } else {
            ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(config));
            http.setPort(port);
            server.setConnectors(new Connector[]{http});
        }

        Handler handler = ContainerFactory.createContainer(JettyHttpContainer.class, application);
        if (originFilter != null)
            handler = new CrossDomainFilter(handler, originFilter);
        if (frontendRoot != null) {
            WebAppContext htmlHandler = new WebAppContext();
            htmlHandler.setResourceBase(frontendRoot);
            htmlHandler.setCopyWebDir(copyWebDir);
            Map<Pattern, Handler> pathToHandler = new HashMap<>();
            pathToHandler.put(Pattern.compile(apiPathPattern), handler);

            SessionManager sm = new HashSessionManager();
            SessionHandler sh = new SessionHandler(sm);
            htmlHandler.setSessionHandler(sh);

            DefaultServlet defaultServlet = new DefaultServlet();
            ServletHolder holder = new ServletHolder(defaultServlet);
            holder.setInitParameter("useFileMappedBuffer", Boolean.toString(!copyWebDir));
            holder.setInitParameter("cacheControl", "no-store,no-cache,must-revalidate,max-age=-1,public");
            htmlHandler.addServlet(holder, "/");

            handler = new RequestsRouter(htmlHandler, pathToHandler, frontendRoot);
        }
        server.setHandler(handler);
        server.start();

        while (!server.isStarted()) {
            Thread.sleep(50);
        }
        log.info("Jetty server started {} on port {}", application.getClass(), port);
        return server;
    } catch (Exception e) {
        log.error(String.format("Jetty start failed %s.", application.getClass()), e);
        return null;
    }
}
项目:Camel    文件:CometdComponent.java   
protected CometDServlet createServletForConnector(Server server, Connector connector, CometdEndpoint endpoint) throws Exception {
    CometDServlet servlet = new CometDServlet();

    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);

    ServletHolder holder = new ServletHolder();
    holder.setServlet(servlet);
    holder.setAsyncSupported(true);

    // Use baseResource to pass as a parameter the url
    // pointing to by example classpath:webapp
    if (endpoint.getBaseResource() != null) {
        String[] resources = endpoint.getBaseResource().split(":");
        if (LOG.isDebugEnabled()) {
            LOG.debug(">>> Protocol found: " + resources[0] + ", and resource: " + resources[1]);
        }

        if (resources[0].equals("file")) {
            context.setBaseResource(Resource.newResource(resources[1]));
        } else if (resources[0].equals("classpath")) {
            // Create a URL handler using classpath protocol
            URL url = this.getCamelContext().getClassResolver().loadResourceAsURL(resources[1]);
            context.setBaseResource(Resource.newResource(url));
        }
    }

    applyCrossOriginFiltering(endpoint, context);

    context.addServlet(holder, "/cometd/*");
    context.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/");
    context.setSessionHandler(new SessionHandler(new HashSessionManager()));

    holder.setInitParameter("timeout", Integer.toString(endpoint.getTimeout()));
    holder.setInitParameter("interval", Integer.toString(endpoint.getInterval()));
    holder.setInitParameter("maxInterval", Integer.toString(endpoint.getMaxInterval()));
    holder.setInitParameter("multiFrameInterval", Integer.toString(endpoint.getMultiFrameInterval()));
    holder.setInitParameter("JSONCommented", Boolean.toString(endpoint.isJsonCommented()));
    holder.setInitParameter("logLevel", Integer.toString(endpoint.getLogLevel()));

    return servlet;
}
项目:jtwig-web    文件:ApplicationSessionVariableTest.java   
@Override
protected void setUpContext(ServletContextHandler context) {
    context.addServlet(new ServletHolder(new SessionStoreServlet()), "/session");
    context.addServlet(new ServletHolder(new HelloServlet()), "/*");
    context.setSessionHandler(new SessionHandler(new HashSessionManager()));
}
项目:pipes    文件:AbstractApp.java   
public AbstractApp() {
    configs.put(getKey(SessionManager.class, null), new HashSessionManager());
    configs.put(getKey(ObjectMapper.class, null), configureObjectMapper(new ObjectMapper()));
    configs.put(getKey(ObjectMapper.class, XML_MAPPER_NAME), configureObjectMapper(new ObjectMapper()));
}