Search in sources :

Example 86 with HttpConnectionFactory

use of org.eclipse.jetty.server.HttpConnectionFactory in project ignite by apache.

the class GridJettyRestProtocol method loadJettyConfiguration.

/**
     * Loads jetty configuration from the given URL.
     *
     * @param cfgUrl URL to load configuration from.
     * @throws IgniteCheckedException if load failed.
     */
private void loadJettyConfiguration(@Nullable URL cfgUrl) throws IgniteCheckedException {
    if (cfgUrl == null) {
        HttpConfiguration httpCfg = new HttpConfiguration();
        httpCfg.setSecureScheme("https");
        httpCfg.setSecurePort(8443);
        httpCfg.setSendServerVersion(true);
        httpCfg.setSendDateHeader(true);
        String srvPortStr = System.getProperty(IGNITE_JETTY_PORT, "8080");
        int srvPort;
        try {
            srvPort = Integer.parseInt(srvPortStr);
        } catch (NumberFormatException ignore) {
            throw new IgniteCheckedException("Failed to start Jetty server because IGNITE_JETTY_PORT system property " + "cannot be cast to integer: " + srvPortStr);
        }
        httpSrv = new Server(new QueuedThreadPool(200, 20));
        ServerConnector srvConn = new ServerConnector(httpSrv, new HttpConnectionFactory(httpCfg));
        srvConn.setHost(System.getProperty(IGNITE_JETTY_HOST, "localhost"));
        srvConn.setPort(srvPort);
        srvConn.setIdleTimeout(30000L);
        srvConn.setReuseAddress(true);
        httpSrv.addConnector(srvConn);
        httpSrv.setStopAtShutdown(false);
    } else {
        XmlConfiguration cfg;
        try {
            cfg = new XmlConfiguration(cfgUrl);
        } catch (FileNotFoundException e) {
            throw new IgniteSpiException("Failed to find configuration file: " + cfgUrl, e);
        } catch (SAXException e) {
            throw new IgniteSpiException("Failed to parse configuration file: " + cfgUrl, e);
        } catch (IOException e) {
            throw new IgniteSpiException("Failed to load configuration file: " + cfgUrl, e);
        } catch (Exception e) {
            throw new IgniteSpiException("Failed to start HTTP server with configuration file: " + cfgUrl, e);
        }
        try {
            httpSrv = (Server) cfg.configure();
        } catch (Exception e) {
            throw new IgniteCheckedException("Failed to start Jetty HTTP server.", e);
        }
    }
    assert httpSrv != null;
    httpSrv.setHandler(jettyHnd);
    override(getJettyConnector());
}
Also used : Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) FileNotFoundException(java.io.FileNotFoundException) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) IOException(java.io.IOException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) SocketException(java.net.SocketException) MultiException(org.eclipse.jetty.util.MultiException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) ServerConnector(org.eclipse.jetty.server.ServerConnector) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 87 with HttpConnectionFactory

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

the class StartSolrJetty method main.

public static void main(String[] args) {
    //System.setProperty("solr.solr.home", "../../../example/solr");
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory());
    // Set some timeout options to make debugging easier.
    connector.setIdleTimeout(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(8983);
    server.setConnectors(new Connector[] { connector });
    WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/solr");
    bb.setWar("webapp/web");
    //    // START JMX SERVER
    //    if( true ) {
    //      MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    //      MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    //      server.getContainer().addEventListener(mBeanContainer);
    //      mBeanContainer.start();
    //    }
    server.setHandler(bb);
    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        while (System.in.available() == 0) {
            Thread.sleep(5000);
        }
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(100);
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory)

Example 88 with HttpConnectionFactory

use of org.eclipse.jetty.server.HttpConnectionFactory 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 89 with HttpConnectionFactory

use of org.eclipse.jetty.server.HttpConnectionFactory 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)

Example 90 with HttpConnectionFactory

use of org.eclipse.jetty.server.HttpConnectionFactory in project XRTB by benmfaul.

the class AddShutdownHook method startSeparateAdminServer.

/**
	 * Start a different handler for control and reporting functions
	 * 
	 * @throws Exception
	 *             if SSL is specified but is not configured
	 */
void startSeparateAdminServer() throws Exception {
    SSL ssl = Configuration.getInstance().ssl;
    QueuedThreadPool threadPool = new QueuedThreadPool(threads, 50);
    Server server = new Server(threadPool);
    ServerConnector connector;
    if (Configuration.getInstance().adminPort == 0)
        return;
    Controller.getInstance().sendLog(1, "initialization", ("Admin functions are available on port: " + Configuration.getInstance().adminPort));
    if (!Configuration.getInstance().adminSSL) {
        // adminPort
        connector = new ServerConnector(server);
        connector.setPort(Configuration.getInstance().adminPort);
        connector.setIdleTimeout(60000);
        server.setConnectors(new Connector[] { connector });
    } else {
        if (config.getInstance().ssl == null) {
            throw new Exception("Admin port set to SSL but no SSL credentials are configured.");
        }
        Controller.getInstance().sendLog(1, "initialization", "Admin functions are available by SSL only");
        HttpConfiguration https = new HttpConfiguration();
        https.addCustomizer(new SecureRequestCustomizer());
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePath(ssl.setKeyStorePath);
        sslContextFactory.setKeyStorePassword(ssl.setKeyStorePassword);
        sslContextFactory.setKeyManagerPassword(ssl.setKeyManagerPassword);
        ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https));
        sslConnector.setPort(Configuration.getInstance().adminPort);
        server.setConnectors(new Connector[] { sslConnector });
    }
    adminHandler = new AdminHandler();
    // org.eclipse.jetty.server.session.SessionHandler
    SessionHandler sh = new SessionHandler();
    sh.setHandler(adminHandler);
    // set session handle
    server.setHandler(sh);
    server.start();
    server.join();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) 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) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) SSL(com.xrtb.common.SSL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)90 ServerConnector (org.eclipse.jetty.server.ServerConnector)79 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)69 Server (org.eclipse.jetty.server.Server)56 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)44 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)43 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)39 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)16 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)15 File (java.io.File)12 Connector (org.eclipse.jetty.server.Connector)12 IOException (java.io.IOException)11 ServletException (javax.servlet.ServletException)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)9 Before (org.junit.Before)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)8 Request (org.eclipse.jetty.server.Request)8