Search in sources :

Example 6 with ConnectionFactory

use of org.eclipse.jetty.server.ConnectionFactory in project jetty.project by eclipse.

the class DirectHTTP2OverTLSTest method startServer.

private void startServer(Handler handler) throws Exception {
    QueuedThreadPool serverThreads = new QueuedThreadPool();
    serverThreads.setName("server");
    server = new Server(serverThreads);
    HttpConfiguration httpsConfig = new HttpConfiguration();
    httpsConfig.addCustomizer(new SecureRequestCustomizer());
    ConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpsConfig);
    ConnectionFactory ssl = new SslConnectionFactory(newSslContextFactory(), h2.getProtocol());
    connector = new ServerConnector(server, 1, 1, ssl, h2);
    server.addConnector(connector);
    server.setHandler(handler);
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 7 with ConnectionFactory

use of org.eclipse.jetty.server.ConnectionFactory in project jetty.project by eclipse.

the class ALPNServerConnection method select.

@Override
public String select(List<String> clientProtocols) {
    SSLEngine sslEngine = getSSLEngine();
    List<String> serverProtocols = getProtocols();
    SSLSession sslSession = sslEngine.getHandshakeSession();
    if (sslSession == null)
        sslSession = sslEngine.getSession();
    String tlsProtocol = sslSession.getProtocol();
    String tlsCipher = sslSession.getCipherSuite();
    String negotiated = null;
    // that it prefers that is also supported by the client.
    for (String serverProtocol : serverProtocols) {
        if (clientProtocols.contains(serverProtocol)) {
            ConnectionFactory factory = getConnector().getConnectionFactory(serverProtocol);
            if (factory instanceof CipherDiscriminator && !((CipherDiscriminator) factory).isAcceptable(serverProtocol, tlsProtocol, tlsCipher)) {
                if (LOG.isDebugEnabled())
                    LOG.debug("{} protocol {} not acceptable to {} for {}/{}", this, serverProtocol, factory, tlsProtocol, tlsCipher);
                continue;
            }
            negotiated = serverProtocol;
            break;
        }
    }
    if (negotiated == null) {
        if (clientProtocols.isEmpty()) {
            negotiated = getDefaultProtocol();
        } else {
            if (LOG.isDebugEnabled())
                LOG.debug("{} could not negotiate protocol among client{} and server{}", this, clientProtocols, serverProtocols);
            throw new IllegalStateException();
        }
    }
    if (LOG.isDebugEnabled())
        LOG.debug("{} protocol selected {} among client{} and server{}", this, negotiated, clientProtocols, serverProtocols);
    setProtocol(negotiated);
    ALPN.remove(sslEngine);
    return negotiated;
}
Also used : ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SSLEngine(javax.net.ssl.SSLEngine) SSLSession(javax.net.ssl.SSLSession)

Example 8 with ConnectionFactory

use of org.eclipse.jetty.server.ConnectionFactory in project druid by druid-io.

the class JettyServerModule method makeJettyServer.

static Server makeJettyServer(DruidNode node, ServerConfig config) {
    final QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMinThreads(config.getNumThreads());
    threadPool.setMaxThreads(config.getNumThreads());
    threadPool.setDaemon(true);
    final Server server = new Server(threadPool);
    // Without this bean set, the default ScheduledExecutorScheduler runs as non-daemon, causing lifecycle hooks to fail
    // to fire on main exit. Related bug: https://github.com/druid-io/druid/pull/1627
    server.addBean(new ScheduledExecutorScheduler("JettyScheduler", true), true);
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(node.getPort());
    connector.setIdleTimeout(Ints.checkedCast(config.getMaxIdleTime().toStandardDuration().getMillis()));
    // workaround suggested in -
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=435322#c66 for jetty half open connection issues during failovers
    connector.setAcceptorPriorityDelta(-1);
    List<ConnectionFactory> monitoredConnFactories = new ArrayList<>();
    for (ConnectionFactory cf : connector.getConnectionFactories()) {
        monitoredConnFactories.add(new JettyMonitoringConnectionFactory(cf, activeConnections));
    }
    connector.setConnectionFactories(monitoredConnFactories);
    server.setConnectors(new Connector[] { connector });
    return server;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) ArrayList(java.util.ArrayList)

Example 9 with ConnectionFactory

use of org.eclipse.jetty.server.ConnectionFactory in project spring-boot by spring-projects.

the class JettyReactiveWebServerFactory method createConnector.

private AbstractConnector createConnector(InetSocketAddress address, Server server) {
    ServerConnector connector = new ServerConnector(server, this.acceptors, this.selectors);
    connector.setHost(address.getHostName());
    connector.setPort(address.getPort());
    for (ConnectionFactory connectionFactory : connector.getConnectionFactories()) {
        if (connectionFactory instanceof HttpConfiguration.ConnectionFactory) {
            ((HttpConfiguration.ConnectionFactory) connectionFactory).getHttpConfiguration().setSendServerVersion(false);
        }
    }
    return connector;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 10 with ConnectionFactory

use of org.eclipse.jetty.server.ConnectionFactory in project spring-boot by spring-projects.

the class JettyServletWebServerFactory method createConnector.

private AbstractConnector createConnector(InetSocketAddress address, Server server) {
    ServerConnector connector = new ServerConnector(server, this.acceptors, this.selectors);
    connector.setHost(address.getHostName());
    connector.setPort(address.getPort());
    for (ConnectionFactory connectionFactory : connector.getConnectionFactories()) {
        if (connectionFactory instanceof HttpConfiguration.ConnectionFactory) {
            ((HttpConfiguration.ConnectionFactory) connectionFactory).getHttpConfiguration().setSendServerVersion(false);
        }
    }
    return connector;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Aggregations

ConnectionFactory (org.eclipse.jetty.server.ConnectionFactory)13 ServerConnector (org.eclipse.jetty.server.ServerConnector)10 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)8 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)7 Server (org.eclipse.jetty.server.Server)6 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)3 URI (java.net.URI)2 URL (java.net.URL)2 Connector (org.eclipse.jetty.server.Connector)2 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 File (java.io.File)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 MalformedURLException (java.net.MalformedURLException)1 ServerSocket (java.net.ServerSocket)1