Search in sources :

Example 91 with ServerConnector

use of org.eclipse.jetty.server.ServerConnector in project hadoop by apache.

the class TestWebAppProxyServlet method start.

/**
   * Simple http server. Server should send answer with status 200
   */
@BeforeClass
public static void start() throws Exception {
    server = new Server(0);
    ((QueuedThreadPool) server.getThreadPool()).setMaxThreads(10);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/foo");
    server.setHandler(context);
    context.addServlet(new ServletHolder(TestServlet.class), "/bar");
    ((ServerConnector) server.getConnectors()[0]).setHost("localhost");
    server.start();
    originalPort = ((ServerConnector) server.getConnectors()[0]).getLocalPort();
    LOG.info("Running embedded servlet container at: http://localhost:" + originalPort);
    // This property needs to be set otherwise CORS Headers will be dropped
    // by HttpUrlConnection
    System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) BeforeClass(org.junit.BeforeClass)

Example 92 with ServerConnector

use of org.eclipse.jetty.server.ServerConnector in project hbase by apache.

the class HttpServer method toString.

/**
   * Return the host and port of the HttpServer, if live
   * @return the classname and any HTTP URL
   */
@Override
public String toString() {
    if (listeners.isEmpty()) {
        return "Inactive HttpServer";
    } else {
        StringBuilder sb = new StringBuilder("HttpServer (").append(isAlive() ? STATE_DESCRIPTION_ALIVE : STATE_DESCRIPTION_NOT_LIVE).append("), listening at:");
        for (ListenerInfo li : listeners) {
            ServerConnector l = li.listener;
            sb.append(l.getHost()).append(":").append(l.getPort()).append("/,");
        }
        return sb.toString();
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector)

Example 93 with ServerConnector

use of org.eclipse.jetty.server.ServerConnector in project hbase by apache.

the class TestHttpServer method checkBindAddress.

private HttpServer checkBindAddress(String host, int port, boolean findPort) throws Exception {
    HttpServer server = createServer(host, port);
    try {
        // not bound, ephemeral should return requested port (0 for ephemeral)
        List<?> listeners = (List<?>) Whitebox.getInternalState(server, "listeners");
        ServerConnector listener = (ServerConnector) Whitebox.getInternalState(listeners.get(0), "listener");
        assertEquals(port, listener.getPort());
        // verify hostname is what was given
        server.openListeners();
        assertEquals(host, server.getConnectorAddress(0).getHostName());
        int boundPort = server.getConnectorAddress(0).getPort();
        if (port == 0) {
            // ephemeral should now return bound port
            assertTrue(boundPort != 0);
        } else if (findPort) {
            assertTrue(boundPort > port);
            // allow a little wiggle room to prevent random test failures if
            // some consecutive ports are already in use
            assertTrue(boundPort - port < 8);
        }
    } catch (Exception e) {
        server.stop();
        throw e;
    }
    return server;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) AccessControlList(org.apache.hadoop.security.authorize.AccessControlList) List(java.util.List) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 94 with ServerConnector

use of org.eclipse.jetty.server.ServerConnector in project zeppelin by apache.

the class ZeppelinServer method setupJettyServer.

private static Server setupJettyServer(ZeppelinConfiguration conf) {
    final Server server = new Server();
    ServerConnector connector;
    if (conf.useSsl()) {
        LOG.debug("Enabling SSL for Zeppelin Server on port " + conf.getServerSslPort());
        HttpConfiguration httpConfig = new HttpConfiguration();
        httpConfig.setSecureScheme("https");
        httpConfig.setSecurePort(conf.getServerSslPort());
        httpConfig.setOutputBufferSize(32768);
        httpConfig.setRequestHeaderSize(8192);
        httpConfig.setResponseHeaderSize(8192);
        httpConfig.setSendServerVersion(true);
        HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
        SecureRequestCustomizer src = new SecureRequestCustomizer();
        // Only with Jetty 9.3.x
        // src.setStsMaxAge(2000);
        // src.setStsIncludeSubDomains(true);
        httpsConfig.addCustomizer(src);
        connector = new ServerConnector(server, new SslConnectionFactory(getSslContextFactory(conf), HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
    } else {
        connector = new ServerConnector(server);
    }
    // Set some timeout options to make debugging easier.
    int timeout = 1000 * 30;
    connector.setIdleTimeout(timeout);
    connector.setSoLingerTime(-1);
    connector.setHost(conf.getServerAddress());
    if (conf.useSsl()) {
        connector.setPort(conf.getServerSslPort());
    } else {
        connector.setPort(conf.getServerPort());
    }
    server.addConnector(connector);
    return server;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) NotebookServer(org.apache.zeppelin.socket.NotebookServer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 95 with ServerConnector

use of org.eclipse.jetty.server.ServerConnector in project killbill by killbill.

the class HttpServer method configureSslConnector.

private ServerConnector configureSslConnector(final HttpConfiguration httpConfiguration, final boolean isStatsOn, final int localSslPort, final String sslKeyStorePath, final String sslKeyStorePassword) {
    // SSL Context Factory for HTTPS
    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(sslKeyStorePath);
    sslContextFactory.setKeyStorePassword(sslKeyStorePassword);
    // HTTPS Configuration
    final HttpConfiguration httpsConfig = new HttpConfiguration(httpConfiguration);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    // HTTPS connector
    final ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfig));
    https.setPort(localSslPort);
    if (isStatsOn) {
        final ConnectorStatistics stats = new ConnectorStatistics();
        https.addBean(stats);
    }
    return https;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ConnectorStatistics(org.eclipse.jetty.server.ConnectorStatistics) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Aggregations

ServerConnector (org.eclipse.jetty.server.ServerConnector)291 Server (org.eclipse.jetty.server.Server)213 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)91 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)83 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)67 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)64 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)55 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)53 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)45 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)45 URI (java.net.URI)37 Test (org.junit.Test)32 File (java.io.File)30 BeforeClass (org.junit.BeforeClass)29 IOException (java.io.IOException)27 Before (org.junit.Before)25 BeforeClass (org.testng.annotations.BeforeClass)22 ServletException (javax.servlet.ServletException)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)19 Connector (org.eclipse.jetty.server.Connector)19