Search in sources :

Example 1 with HashSessionIdManager

use of org.eclipse.jetty.server.session.HashSessionIdManager in project lucene-solr by apache.

the class JettyWebappTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    System.setProperty("solr.solr.home", SolrJettyTestBase.legacyExampleCollection1SolrHome());
    System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
    System.setProperty("solr.tests.doContainerStreamCloseAssert", "false");
    File dataDir = createTempDir().toFile();
    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);
    ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());
    connector.setIdleTimeout(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(0);
    server.setConnectors(new Connector[] { connector });
    server.setStopAtShutdown(true);
    server.start();
    port = connector.getLocalPort();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) Random(java.util.Random) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) File(java.io.File) HashSessionIdManager(org.eclipse.jetty.server.session.HashSessionIdManager)

Example 2 with HashSessionIdManager

use of org.eclipse.jetty.server.session.HashSessionIdManager in project Activiti by Activiti.

the class TestServerUtil method createAndStartServer.

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) {
        log.error("Error starting server", e);
    }
    return new TestServer(server, applicationContext, port);
}
Also used : Server(org.eclipse.jetty.server.Server) HashSessionIdManager(org.eclipse.jetty.server.session.HashSessionIdManager) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) IOException(java.io.IOException)

Example 3 with HashSessionIdManager

use of org.eclipse.jetty.server.session.HashSessionIdManager in project Activiti by Activiti.

the class BaseJPARestTestCase method createAndStartServer.

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) {
        log.error("Error starting server", e);
    }
}
Also used : Server(org.eclipse.jetty.server.Server) HashSessionIdManager(org.eclipse.jetty.server.session.HashSessionIdManager) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) ActivitiException(org.activiti.engine.ActivitiException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with HashSessionIdManager

use of org.eclipse.jetty.server.session.HashSessionIdManager in project lucene-solr by apache.

the class ReplicatorTestCase method newHttpServer.

/**
   * Returns a new {@link Server HTTP Server} instance. To obtain its port, use
   * {@link #serverPort(Server)}.
   */
public static synchronized Server newHttpServer(Handler handler) throws Exception {
    // if this property is true, then jetty will be configured to use SSL
    // leveraging the same system properties as java to specify
    // the keystore/truststore if they are set
    //
    // This means we will use the same truststore, keystore (and keys) for
    // the server as well as any client actions taken by this JVM in
    // talking to that server, but for the purposes of testing that should 
    // be good enough
    final boolean useSsl = Boolean.getBoolean("tests.jettySsl");
    final SslContextFactory sslcontext = new SslContextFactory(false);
    if (useSsl) {
        if (null != System.getProperty("javax.net.ssl.keyStore")) {
            sslcontext.setKeyStorePath(System.getProperty("javax.net.ssl.keyStore"));
        }
        if (null != System.getProperty("javax.net.ssl.keyStorePassword")) {
            sslcontext.setKeyStorePassword(System.getProperty("javax.net.ssl.keyStorePassword"));
        }
        if (null != System.getProperty("javax.net.ssl.trustStore")) {
            sslcontext.setKeyStorePath(System.getProperty("javax.net.ssl.trustStore"));
        }
        if (null != System.getProperty("javax.net.ssl.trustStorePassword")) {
            sslcontext.setTrustStorePassword(System.getProperty("javax.net.ssl.trustStorePassword"));
        }
        sslcontext.setNeedClientAuth(Boolean.getBoolean("tests.jettySsl.clientAuth"));
    }
    final QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setDaemon(true);
    threadPool.setMaxThreads(10000);
    threadPool.setIdleTimeout(5000);
    threadPool.setStopTimeout(30000);
    Server server = new Server(threadPool);
    server.setStopAtShutdown(true);
    server.manage(threadPool);
    final ServerConnector connector;
    if (useSsl) {
        HttpConfiguration configuration = new HttpConfiguration();
        configuration.setSecureScheme("https");
        configuration.addCustomizer(new SecureRequestCustomizer());
        ServerConnector c = new ServerConnector(server, new SslConnectionFactory(sslcontext, "http/1.1"), new HttpConnectionFactory(configuration));
        connector = c;
    } else {
        ServerConnector c = new ServerConnector(server, new HttpConnectionFactory());
        connector = c;
    }
    connector.setPort(0);
    connector.setHost("127.0.0.1");
    server.setConnectors(new Connector[] { connector });
    server.setSessionIdManager(new HashSessionIdManager(new Random(random().nextLong())));
    server.setHandler(handler);
    server.start();
    return server;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Random(java.util.Random) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) HashSessionIdManager(org.eclipse.jetty.server.session.HashSessionIdManager)

Example 5 with HashSessionIdManager

use of org.eclipse.jetty.server.session.HashSessionIdManager in project lucene-solr by apache.

the class JettySolrRunner method init.

private void init(int port) {
    QueuedThreadPool qtp = new QueuedThreadPool();
    qtp.setMaxThreads(THREAD_POOL_MAX_THREADS);
    qtp.setIdleTimeout(THREAD_POOL_MAX_IDLE_TIME_MS);
    qtp.setStopTimeout((int) TimeUnit.MINUTES.toMillis(1));
    server = new Server(qtp);
    server.manage(qtp);
    server.setStopAtShutdown(config.stopAtShutdown);
    if (System.getProperty("jetty.testMode") != null) {
        // if this property is true, then jetty will be configured to use SSL
        // leveraging the same system properties as java to specify
        // the keystore/truststore if they are set unless specific config
        // is passed via the constructor.
        //
        // This means we will use the same truststore, keystore (and keys) for
        // the server as well as any client actions taken by this JVM in
        // talking to that server, but for the purposes of testing that should 
        // be good enough
        final SslContextFactory sslcontext = SSLConfig.createContextFactory(config.sslConfig);
        ServerConnector connector;
        if (sslcontext != null) {
            HttpConfiguration configuration = new HttpConfiguration();
            configuration.setSecureScheme("https");
            configuration.addCustomizer(new SecureRequestCustomizer());
            connector = new ServerConnector(server, new SslConnectionFactory(sslcontext, "http/1.1"), new HttpConnectionFactory(configuration));
        } else {
            connector = new ServerConnector(server, new HttpConnectionFactory());
        }
        connector.setReuseAddress(true);
        connector.setSoLingerTime(-1);
        connector.setPort(port);
        connector.setHost("127.0.0.1");
        connector.setIdleTimeout(THREAD_POOL_MAX_IDLE_TIME_MS);
        server.setConnectors(new Connector[] { connector });
        server.setSessionIdManager(new HashSessionIdManager(new Random()));
    } else {
        ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());
        connector.setPort(port);
        connector.setSoLingerTime(-1);
        connector.setIdleTimeout(THREAD_POOL_MAX_IDLE_TIME_MS);
        server.setConnectors(new Connector[] { connector });
    }
    // Initialize the servlets
    final ServletContextHandler root = new ServletContextHandler(server, config.context, ServletContextHandler.SESSIONS);
    server.addLifeCycleListener(new LifeCycle.Listener() {

        @Override
        public void lifeCycleStopping(LifeCycle arg0) {
        }

        @Override
        public void lifeCycleStopped(LifeCycle arg0) {
        }

        @Override
        public void lifeCycleStarting(LifeCycle arg0) {
            synchronized (JettySolrRunner.this) {
                waitOnSolr = true;
                JettySolrRunner.this.notify();
            }
        }

        @Override
        public void lifeCycleStarted(LifeCycle arg0) {
            lastPort = getFirstConnectorPort();
            nodeProperties.setProperty("hostPort", Integer.toString(lastPort));
            nodeProperties.setProperty("hostContext", config.context);
            root.getServletContext().setAttribute(SolrDispatchFilter.PROPERTIES_ATTRIBUTE, nodeProperties);
            root.getServletContext().setAttribute(SolrDispatchFilter.SOLRHOME_ATTRIBUTE, solrHome);
            logger.info("Jetty properties: {}", nodeProperties);
            debugFilter = root.addFilter(DebugFilter.class, "*", EnumSet.of(DispatcherType.REQUEST));
            extraFilters = new LinkedList<>();
            for (Class<? extends Filter> filterClass : config.extraFilters.keySet()) {
                extraFilters.add(root.addFilter(filterClass, config.extraFilters.get(filterClass), EnumSet.of(DispatcherType.REQUEST)));
            }
            for (ServletHolder servletHolder : config.extraServlets.keySet()) {
                String pathSpec = config.extraServlets.get(servletHolder);
                root.addServlet(servletHolder, pathSpec);
            }
            dispatchFilter = root.getServletHandler().newFilterHolder(BaseHolder.Source.EMBEDDED);
            dispatchFilter.setHeldClass(SolrDispatchFilter.class);
            dispatchFilter.setInitParameter("excludePatterns", excludePatterns);
            root.addFilter(dispatchFilter, "*", EnumSet.of(DispatcherType.REQUEST));
        }

        @Override
        public void lifeCycleFailure(LifeCycle arg0, Throwable arg1) {
            System.clearProperty("hostPort");
        }
    });
    // for some reason, there must be a servlet for this to get applied
    root.addServlet(Servlet404.class, "/*");
    GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.setHandler(root);
    gzipHandler.setMinGzipSize(0);
    gzipHandler.setCheckGzExists(false);
    gzipHandler.setCompressionLevel(-1);
    gzipHandler.setExcludedAgentPatterns(".*MSIE.6\\.0.*");
    gzipHandler.setIncludedMethods("GET");
    server.setHandler(gzipHandler);
}
Also used : LifeCycle(org.eclipse.jetty.util.component.LifeCycle) SolrDispatchFilter(org.apache.solr.servlet.SolrDispatchFilter) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) HashSessionIdManager(org.eclipse.jetty.server.session.HashSessionIdManager) LinkedList(java.util.LinkedList) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Random(java.util.Random) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) SolrDispatchFilter(org.apache.solr.servlet.SolrDispatchFilter) Filter(javax.servlet.Filter) GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

Server (org.eclipse.jetty.server.Server)5 HashSessionIdManager (org.eclipse.jetty.server.session.HashSessionIdManager)5 Random (java.util.Random)3 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 IOException (java.io.IOException)2 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)2 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)2 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)2 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)2 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)2 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 LinkedList (java.util.LinkedList)1 Filter (javax.servlet.Filter)1 ActivitiException (org.activiti.engine.ActivitiException)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 SolrDispatchFilter (org.apache.solr.servlet.SolrDispatchFilter)1