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

项目: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();
    }
项目:c4a_data_repository    文件:JettyLauncher.java   
/**
 * Starts a Jetty server with D2R Server as root webapp.
 * 
 * @return <code>true</code> on success, <code>false</code> if webapp init failed 
 */
public boolean start() {
    Server jetty = new Server(port);

    // use Random (/dev/urandom) instead of SecureRandom to generate session keys - otherwise Jetty may hang during startup waiting for enough entropy
    // see http://jira.codehaus.org/browse/JETTY-331 and http://docs.codehaus.org/display/JETTY/Connectors+slow+to+startup
    jetty.setSessionIdManager(new HashSessionIdManager(new Random()));
    WebAppContext context = new WebAppContext(jetty, "webapp", "");
    // Place the system loader into the servlet context. The webapp init
    // listener will find it there and create the D2RServer instance.
    D2RServer.storeSystemLoader(loader, context.getServletContext());
    try {
        jetty.start();
        D2RServer server = D2RServer.fromServletContext(context.getServletContext());
        if (server == null || server.errorOnStartup()) {
            jetty.stop();
            log.warn("[[[ Server startup failed, see messages above ]]]");
            return false;
        }
        log.info("[[[ Server started at " + loader.getSystemBaseURI() + " ]]]");
        return true;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
项目:flowable-engine    文件:TestServerUtil.java   
public static TestServer createAndStartServer(Class<?>... configClasses) {
    int port = NEXT_PORT.incrementAndGet();
    Server server = new Server(port);

    HashSessionIdManager idmanager = new HashSessionIdManager();
    server.setSessionIdManager(idmanager);

    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.register(configClasses);
    applicationContext.refresh();

    try {
        server.setHandler(getServletContextHandler(applicationContext));
        server.start();
    } catch (Exception e) {
        LOGGER.error("Error starting server", e);
    }

    return new TestServer(server, applicationContext, port);
}
项目:flowable-engine    文件:BaseJPARestTestCase.java   
public static void createAndStartServer() {
    server = new Server(HTTP_SERVER_PORT);

    HashSessionIdManager idmanager = new HashSessionIdManager();
    server.setSessionIdManager(idmanager);

    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.register(JPAApplicationConfiguration.class);
    applicationContext.refresh();

    appContext = applicationContext;

    try {
        server.setHandler(getServletContextHandler(applicationContext));
        server.start();
    } catch (Exception e) {
        LOGGER.error("Error starting server", e);
    }
}
项目:flowable-engine    文件:TestServerUtil.java   
public static TestServer createAndStartServer(Class<?>... configClasses) {
    int port = NEXT_PORT.incrementAndGet();
    Server server = new Server(port);

    HashSessionIdManager idmanager = new HashSessionIdManager();
    server.setSessionIdManager(idmanager);

    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.register(configClasses);
    applicationContext.refresh();

    try {
        server.setHandler(getServletContextHandler(applicationContext));
        server.start();
    } catch (Exception e) {
        LOGGER.error("Error starting server", e);
    }

    return new TestServer(server, applicationContext, port);
}
项目:flowable-engine    文件:TestServerUtil.java   
public static TestServer createAndStartServer(Class<?>... configClasses) {
    int port = NEXT_PORT.incrementAndGet();
    Server server = new Server(port);

    HashSessionIdManager idmanager = new HashSessionIdManager();
    server.setSessionIdManager(idmanager);

    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.register(configClasses);
    applicationContext.refresh();

    try {
        server.setHandler(getServletContextHandler(applicationContext));
        server.start();
    } catch (Exception e) {
        LOGGER.error("Error starting server", e);
    }

    return new TestServer(server, applicationContext, port);
}
项目:MoodCat.me-Core    文件:App.java   
/**
 * Instantiates the server and adds handlers for the requests.
 *
 * @throws IOException
 *             If the statics folder threw an IOException.
 */
public App(final Module... overrides) throws IOException {
    final File staticsFolder = new File("src/main/resources/static/app");

    // Make sure the folder is available, else we can't start the server.
    if (!staticsFolder.exists() && !staticsFolder.mkdir()) {
        throw new IOException("Static folder could not be initialized.");
    }

    for (final String file : staticsFolder.list()) {
        log.info("Found resource {}", file);
    }

    this.server = new Server(SERVER_PORT);
    this.server.setSessionIdManager(new HashSessionIdManager());
    this.server.setHandler(this.attachHandlers(staticsFolder, overrides));
}
项目:OpenCollegeGraph    文件:JettyLauncher.java   
/**
 * Starts a Jetty server with D2R Server as root webapp.
 * 
 * @return <code>true</code> on success, <code>false</code> if webapp init failed 
 */
public boolean start() {
    Server jetty = new Server(port);

    // use Random (/dev/urandom) instead of SecureRandom to generate session keys - otherwise Jetty may hang during startup waiting for enough entropy
    // see http://jira.codehaus.org/browse/JETTY-331 and http://docs.codehaus.org/display/JETTY/Connectors+slow+to+startup
    jetty.setSessionIdManager(new HashSessionIdManager(new Random()));
    WebAppContext context = new WebAppContext(jetty, "webapp", "");
    // Place the system loader into the servlet context. The webapp init
    // listener will find it there and create the D2RServer instance.
    D2RServer.storeSystemLoader(loader, context.getServletContext());
    try {
        jetty.start();
        D2RServer server = D2RServer.fromServletContext(context.getServletContext());
        if (server == null || server.errorOnStartup()) {
            jetty.stop();
            log.warn("[[[ Server startup failed, see messages above ]]]");
            return false;
        }
        log.info("[[[ Server started at " + loader.getSystemBaseURI() + " ]]]");
        return true;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
项目:pipes    文件:JettyHttpServer.java   
@Override
public HttpServer listen(int port) throws Exception {

    SessionHandler sessionHandler = new SessionHandler(app.configuration(SessionManager.class));
    sessionHandler.setHandler(new MiddlewareHandler(app));

    ContextHandler context = new ContextHandler();
    context.setContextPath("/");
    context.setResourceBase(".");
    context.setClassLoader(Thread.currentThread().getContextClassLoader());
    context.setHandler(sessionHandler);

    Server server = new Server(port);

    server.setSessionIdManager(new HashSessionIdManager());
    server.setHandler(context);

    server.start();
    server.join();

    return this;
}
项目:VirtualSPARQLer    文件:JettyLauncher.java   
/**
 * Starts a Jetty server with D2R Server as root webapp.
 * 
 * @return <code>true</code> on success, <code>false</code> if webapp init failed 
 */
public boolean start() {
    Server jetty = new Server(port);

    // use Random (/dev/urandom) instead of SecureRandom to generate session keys - otherwise Jetty may hang during startup waiting for enough entropy
    // see http://jira.codehaus.org/browse/JETTY-331 and http://docs.codehaus.org/display/JETTY/Connectors+slow+to+startup
    jetty.setSessionIdManager(new HashSessionIdManager(new Random()));
    WebAppContext context = new WebAppContext(jetty, "webapp", "");
    // Place the system loader into the servlet context. The webapp init
    // listener will find it there and create the D2RServer instance.
    D2RServer.storeSystemLoader(loader, context.getServletContext());
    try {
        jetty.start();
        D2RServer server = D2RServer.fromServletContext(context.getServletContext());
        if (server == null || server.errorOnStartup()) {
            jetty.stop();
            log.warn("[[[ Server startup failed, see messages above ]]]");
            return false;
        }
        log.info("[[[ Server started at " + loader.getSystemBaseURI() + " ]]]");
        return true;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
项目:search    文件:JettyWebappTest.java   
@Override
public void setUp() throws Exception 
{
  super.setUp();
  System.setProperty("solr.solr.home", ExternalPaths.EXAMPLE_HOME);
  System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));

  File dataDir = createTempDir();
  dataDir.mkdirs();

  System.setProperty("solr.data.dir", dataDir.getCanonicalPath());
  String path = ExternalPaths.WEBAPP_HOME;

  server = new Server(port);
  // insecure: only use for tests!!!!
  server.setSessionIdManager(new HashSessionIdManager(new Random(random().nextLong())));
  new WebAppContext(server, path, context );

  SocketConnector connector = new SocketConnector();
  connector.setMaxIdleTime(1000 * 60 * 60);
  connector.setSoLingerTime(-1);
  connector.setPort(0);
  server.setConnectors(new Connector[]{connector});
  server.setStopAtShutdown( true );

  server.start();
  port = connector.getLocalPort();
}
项目:NYBC    文件:JettyWebappTest.java   
@Override
public void setUp() throws Exception 
{
  super.setUp();
  System.setProperty("solr.solr.home", ExternalPaths.EXAMPLE_HOME);

  File dataDir = new File(LuceneTestCase.TEMP_DIR,
      getClass().getName() + "-" + System.currentTimeMillis());
  dataDir.mkdirs();
  System.setProperty("solr.data.dir", dataDir.getCanonicalPath());
  String path = ExternalPaths.WEBAPP_HOME;

  server = new Server(port);
  // insecure: only use for tests!!!!
  server.setSessionIdManager(new HashSessionIdManager(new Random(random().nextLong())));
  new WebAppContext(server, path, context );

  SocketConnector connector = new SocketConnector();
  connector.setMaxIdleTime(1000 * 60 * 60);
  connector.setSoLingerTime(-1);
  connector.setPort(0);
  server.setConnectors(new Connector[]{connector});
  server.setStopAtShutdown( true );

  server.start();
  port = connector.getLocalPort();
}
项目:MCManager    文件:WebServer.java   
/**
 * Creates an instance of the web server but does not actually start
 * it. To start it you must call the {@link start} method.
 * 
 * @param config - the mod's core config
 * 
 * @throws IOException thrown when the web socket could not be created and bound
 */
public WebServer(Configuration config) throws IOException
{
    // TODO: set this up to use HTTPS instead when requested
    webServer = new Server(config.get(WEBSERVER_CONFIG_CATEGORY, "port", 1716).getInt());
    webServer.setGracefulShutdown(STOP_WAIT_TIME);
    webServer.setSessionIdManager(new HashSessionIdManager());

    int maxConnections = config.get(WEBSERVER_CONFIG_CATEGORY, "max-sessions", 20).getInt();
    if(maxConnections < 2)
    {
        LogHelper.warning("The selected number of minimum connections allowed is too low. Using low default instead.");
        maxConnections = 2;
    }

    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxConnections);
    ThreadPool tp = new ExecutorThreadPool(2, maxConnections, 60, TimeUnit.SECONDS, queue);
    webServer.setThreadPool(tp);

    handlers = new RegExContextHandlerCollection();
    webServer.setHandler(handlers);

    sessionHandler = new SessionHandler();
    sessionHandler.getSessionManager().setSessionIdManager(webServer.getSessionIdManager());
    addHandler("/", sessionHandler);

    rootHandler = new RootHttpHandler();
    sessionHandler.setHandler(rootHandler);

    resourceHandler = new ResourceHandler();
    addHandler("^/resources/.*$", resourceHandler);

    rpcHandler = new JsonRpcHandler();
    addHandler("/rpc/*", rpcHandler);
}
项目:UltimateGames    文件:JettyServer.java   
public JettyServer(UG plugin) throws Exception {
    org.eclipse.jetty.util.log.Log.setLog(new JettyNullLogger());
    server = new Server(plugin.getConfig().getInt("APIPort"));
    server.setHandler(new JettyHandler());
    server.setSessionIdManager(new HashSessionIdManager());

    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(MAX_CONNECTIONS);

    ExecutorThreadPool pool = new ExecutorThreadPool(CORE_POOL_SIZE, MAX_CONNECTIONS, KEEP_ALIVE_TIME, TimeUnit.SECONDS, queue);
    server.setThreadPool(pool);
}
项目:grails-lightweight-deploy    文件:Launcher.java   
protected Handler createExternalContext(Server server, Set<? extends Connector> connectors, String webAppRoot, String contextPath) throws IOException {
    final WebAppContext handler = new ExternalContext(webAppRoot, getMetricsRegistry(), getHealthCheckRegistry(), contextPath);

    // Enable sessions support if required
    final SessionsConfiguration sessionsConfiguration = configuration.getHttpConfiguration().getSessionsConfiguration();
    if (sessionsConfiguration.isEnabled()) {
        final HashSessionIdManager idManager = new HashSessionIdManager();
        if (!Strings.isNullOrEmpty(sessionsConfiguration.getWorkerName())) {
            idManager.setWorkerName(sessionsConfiguration.getWorkerName());
        }

        // Assumes ExternalContext extends WebAppContext which configures sessions by default
        handler.getSessionHandler().getSessionManager().setSessionIdManager(idManager);
    } else {
        handler.setSessionHandler(null);
    }

    restrictToConnectors(handler, connectors);
    configureExternalServlets(handler);

    // Optionally support GZip requests/responses
    configureGzip(handler);

    // Instrument our handler
    final Handler instrumented = new InstrumentedHandler(metricsRegistry, handler);

    return instrumented;
}
项目:kurve-server    文件:ServerStatusServlet.java   
public ServerStatusServlet(SocialAccountService socialAccountService, HashSessionIdManager sessionIdManager, GameService gameService) {
    super(socialAccountService);
    this.sessionIdManager = sessionIdManager;
    this.gameService = gameService;
}
项目:MinecraftLTI    文件:MinecraftLTI.java   
private void startWebserver() {
  JSONObject config = getConfig();
  webport = Integer.parseInt((String)config.get("port"));

  org.eclipse.jetty.util.log.Log.setLog(new NullLogger());

  webserver = new Server(webport);
  webserver.setSessionIdManager(new HashSessionIdManager());

  RewriteHandler rewriteHandler = new RewriteHandler();
  rewriteHandler.setRewriteRequestURI(true);
  rewriteHandler.setRewritePathInfo(true);
  rewriteHandler.setOriginalPathAttribute("requestedPath");
  RedirectRegexRule rule = new RedirectRegexRule();
  rule.setRegex("/");
  rule.setReplacement("/index");
  rewriteHandler.addRule(rule);

  WebAppContext dynamicHandler = new WebAppContext();
  String webDir = this.getClass().getClassLoader().getResource("web").toExternalForm();
  dynamicHandler.setResourceBase(webDir);

  dynamicHandler.addServlet(new ServletHolder(new IndexServlet(this)),"/index");
  dynamicHandler.addServlet(new ServletHolder(new LTIServlet(this)),"/lti");
  dynamicHandler.addServlet(new ServletHolder(new TokenServlet(this)),"/token");
  dynamicHandler.addServlet(new ServletHolder(new AssignmentServlet(this)),"/assignment");
  dynamicHandler.addServlet(new ServletHolder(new ConsumerServlet(this)),"/consumer");
  dynamicHandler.addServlet(new ServletHolder(new LTIConfigServlet()),"/config.xml");

  ResourceHandler staticHandler = new ResourceHandler();
  String staticDir = this.getClass().getClassLoader().getResource("static").toExternalForm();
  staticHandler.setResourceBase(staticDir);

  HandlerList handlers = new HandlerList();
  handlers.setHandlers(new Handler[] { rewriteHandler, staticHandler, dynamicHandler, new DefaultHandler() });
  webserver.setHandler(handlers);
  try {
    webserver.start();
  } catch (Exception e) {
    getLogger().severe("Failed to start server.");
  }
}