Search in sources :

Example 16 with ConnectionFactory

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

the class JettyHTTPServerEngine method createConnectorJetty.

AbstractConnector createConnectorJetty(SslContextFactory sslcf, String hosto, int porto, int major, int minor) {
    AbstractConnector result = null;
    try {
        HttpConfiguration httpConfig = new HttpConfiguration();
        httpConfig.setSendServerVersion(getSendServerVersion());
        HttpConnectionFactory httpFactory = new HttpConnectionFactory(httpConfig);
        Collection<ConnectionFactory> connectionFactories = new ArrayList<>();
        result = new org.eclipse.jetty.server.ServerConnector(server);
        if (tlsServerParameters != null) {
            httpConfig.addCustomizer(new org.eclipse.jetty.server.SecureRequestCustomizer());
            SslConnectionFactory scf = new SslConnectionFactory(sslcf, "HTTP/1.1");
            connectionFactories.add(scf);
            String proto = (major > 9 || (major == 9 && minor >= 3)) ? "SSL" : "SSL-HTTP/1.1";
            result.setDefaultProtocol(proto);
        }
        connectionFactories.add(httpFactory);
        result.setConnectionFactories(connectionFactories);
        if (getMaxIdleTime() > 0) {
            result.setIdleTimeout(Long.valueOf(getMaxIdleTime()));
        }
    } catch (RuntimeException rex) {
        throw rex;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return result;
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) AbstractConnector(org.eclipse.jetty.server.AbstractConnector)

Example 17 with ConnectionFactory

use of org.eclipse.jetty.server.ConnectionFactory in project steve by RWTH-i5-IDSG.

the class JettyServer method getConnectorPath.

private static String getConnectorPath(Connector c) {
    ServerConnector sc = (ServerConnector) c;
    String prefix = "http";
    String host = sc.getHost();
    int port = sc.getPort();
    ConnectionFactory cf = sc.getDefaultConnectionFactory();
    if (cf instanceof SslConnectionFactory) {
        prefix = "https";
    }
    if (host == null || host.equals("0.0.0.0")) {
        try {
            host = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            // Well, we failed to read from system, fall back to main.properties.
            // Better than nothing
            host = CONFIG.getJetty().getServerHost();
        }
    }
    String layout = "%s://%s:%d" + CONFIG.getContextPath();
    return String.format(layout, prefix, host, port);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) UnknownHostException(java.net.UnknownHostException) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 18 with ConnectionFactory

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

the class UnifiedConnectionFactory method newConnection.

@Override
public Connection newConnection(Connector connector, EndPoint realEndPoint) {
    ReadAheadEndpoint aheadEndpoint = new ReadAheadEndpoint(realEndPoint, 1);
    byte[] bytes = aheadEndpoint.getBytes();
    boolean isSSL;
    if (bytes == null || bytes.length == 0) {
        isSSL = false;
        LOG.warn("Incoming connection has no data");
    } else {
        // TLS first byte is 0x16, let's not support SSLv3 and below
        byte b = bytes[0];
        // matches SSL detection in NettyServerCnxnFactory.java
        isSSL = b == 0x16;
    }
    LOG.debug(String.format("UnifiedConnectionFactory: newConnection() with SSL = %b", isSSL));
    EndPoint plainEndpoint;
    SslConnection sslConnection;
    if (isSSL) {
        SSLEngine engine = this.sslContextFactory.newSSLEngine(aheadEndpoint.getRemoteAddress());
        engine.setUseClientMode(false);
        sslConnection = this.newSslConnection(connector, aheadEndpoint, engine);
        sslConnection.setRenegotiationAllowed(this.sslContextFactory.isRenegotiationAllowed());
        this.configure(sslConnection, connector, aheadEndpoint);
        plainEndpoint = sslConnection.getDecryptedEndPoint();
    } else {
        sslConnection = null;
        plainEndpoint = aheadEndpoint;
        ServerMetrics.getMetrics().INSECURE_ADMIN.add(1);
    }
    ConnectionFactory next = connector.getConnectionFactory(nextProtocol);
    Connection connection = next.newConnection(connector, plainEndpoint);
    plainEndpoint.setConnection(connection);
    return (sslConnection == null) ? connection : sslConnection;
}
Also used : SslConnection(org.eclipse.jetty.io.ssl.SslConnection) AbstractConnectionFactory(org.eclipse.jetty.server.AbstractConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SSLEngine(javax.net.ssl.SSLEngine) Connection(org.eclipse.jetty.io.Connection) SslConnection(org.eclipse.jetty.io.ssl.SslConnection) EndPoint(org.eclipse.jetty.io.EndPoint)

Example 19 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) {
    HttpConfiguration httpConfiguration = new HttpConfiguration();
    httpConfiguration.setSendServerVersion(false);
    List<ConnectionFactory> connectionFactories = new ArrayList<>();
    connectionFactories.add(new HttpConnectionFactory(httpConfiguration));
    if (getHttp2() != null && getHttp2().isEnabled()) {
        connectionFactories.add(new HTTP2CServerConnectionFactory(httpConfiguration));
    }
    ServerConnector connector = new ServerConnector(server, this.acceptors, this.selectors, connectionFactories.toArray(new ConnectionFactory[0]));
    connector.setHost(address.getHostString());
    connector.setPort(address.getPort());
    return connector;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) ArrayList(java.util.ArrayList) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 20 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) {
    HttpConfiguration httpConfiguration = new HttpConfiguration();
    httpConfiguration.setSendServerVersion(false);
    List<ConnectionFactory> connectionFactories = new ArrayList<>();
    connectionFactories.add(new HttpConnectionFactory(httpConfiguration));
    if (getHttp2() != null && getHttp2().isEnabled()) {
        connectionFactories.add(new HTTP2CServerConnectionFactory(httpConfiguration));
    }
    JettyResourceFactory resourceFactory = getResourceFactory();
    ServerConnector connector;
    if (resourceFactory != null) {
        connector = new ServerConnector(server, resourceFactory.getExecutor(), resourceFactory.getScheduler(), resourceFactory.getByteBufferPool(), this.acceptors, this.selectors, connectionFactories.toArray(new ConnectionFactory[0]));
    } else {
        connector = new ServerConnector(server, this.acceptors, this.selectors, connectionFactories.toArray(new ConnectionFactory[0]));
    }
    connector.setHost(address.getHostString());
    connector.setPort(address.getPort());
    return connector;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) JettyResourceFactory(org.springframework.http.client.reactive.JettyResourceFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) ArrayList(java.util.ArrayList) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Aggregations

ConnectionFactory (org.eclipse.jetty.server.ConnectionFactory)24 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)18 ServerConnector (org.eclipse.jetty.server.ServerConnector)16 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)15 ArrayList (java.util.ArrayList)12 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)12 Server (org.eclipse.jetty.server.Server)12 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)8 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)6 IOException (java.io.IOException)5 SSLEngine (javax.net.ssl.SSLEngine)5 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)5 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)4 Connector (org.eclipse.jetty.server.Connector)4 Test (org.junit.jupiter.api.Test)4 ServletException (javax.servlet.ServletException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ALPNServerConnectionFactory (org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory)3 HTTP2CServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory)3 File (java.io.File)2