Search in sources :

Example 21 with ConnectionFactory

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

the class SslServerCustomizerTests method whenHttp2IsEnabledServerConnectorsHasSslAlpnH2AndHttpConnectionFactories.

@Test
@SuppressWarnings("rawtypes")
void whenHttp2IsEnabledServerConnectorsHasSslAlpnH2AndHttpConnectionFactories() {
    Http2 http2 = new Http2();
    http2.setEnabled(true);
    Server server = createCustomizedServer(http2);
    assertThat(server.getConnectors()).hasSize(1);
    List<ConnectionFactory> factories = new ArrayList<>(server.getConnectors()[0].getConnectionFactories());
    assertThat(factories).extracting((factory) -> (Class) factory.getClass()).containsExactly(SslConnectionFactory.class, ALPNServerConnectionFactory.class, HTTP2ServerConnectionFactory.class, HttpConnectionFactory.class);
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) WebServerException(org.springframework.boot.web.server.WebServerException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Http2(org.springframework.boot.web.server.Http2) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) InetSocketAddress(java.net.InetSocketAddress) Ssl(org.springframework.boot.web.server.Ssl) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) Server(org.eclipse.jetty.server.Server) Http2(org.springframework.boot.web.server.Http2) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 22 with ConnectionFactory

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

the class SslServerCustomizerTests method whenHttp2IsNotEnabledServerConnectorHasSslAndHttpConnectionFactories.

@Test
@SuppressWarnings("rawtypes")
void whenHttp2IsNotEnabledServerConnectorHasSslAndHttpConnectionFactories() {
    Server server = createCustomizedServer();
    assertThat(server.getConnectors()).hasSize(1);
    List<ConnectionFactory> factories = new ArrayList<>(server.getConnectors()[0].getConnectionFactories());
    assertThat(factories).extracting((factory) -> (Class) factory.getClass()).containsExactly(SslConnectionFactory.class, HttpConnectionFactory.class);
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) WebServerException(org.springframework.boot.web.server.WebServerException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Http2(org.springframework.boot.web.server.Http2) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) InetSocketAddress(java.net.InetSocketAddress) Ssl(org.springframework.boot.web.server.Ssl) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) Server(org.eclipse.jetty.server.Server) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 23 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, final Bus bus) {
    final AbstractConnector result;
    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());
            if (!isHttp2Enabled(bus)) {
                final SslConnectionFactory scf = new SslConnectionFactory(sslcf, httpFactory.getProtocol());
                connectionFactories.add(scf);
            } else {
                // The ALPN processors are application specific (as per Jetty docs) and are pluggable as
                // additional dependency.
                final ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
                alpn.setDefaultProtocol(httpFactory.getProtocol());
                final SslConnectionFactory scf = new SslConnectionFactory(sslcf, alpn.getProtocol());
                connectionFactories.add(scf);
                connectionFactories.add(alpn);
                connectionFactories.add(new HTTP2ServerConnectionFactory(httpConfig));
            }
            String proto = (major > 9 || (major == 9 && minor >= 3)) ? "SSL" : "SSL-HTTP/1.1";
            result.setDefaultProtocol(proto);
        } else if (isHttp2Enabled(bus)) {
            connectionFactories.add(new HTTP2CServerConnectionFactory(httpConfig));
        }
        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) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServletException(javax.servlet.ServletException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) AbstractConnector(org.eclipse.jetty.server.AbstractConnector)

Example 24 with ConnectionFactory

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

the class JettyHTTPServerEngineFactoryTest method testMakeSureJetty9ConnectorConfigured.

@Test
public void testMakeSureJetty9ConnectorConfigured() throws Exception {
    URL config = getClass().getResource("server-engine-factory-jetty9-connector.xml");
    bus = new SpringBusFactory().createBus(config, true);
    JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
    assertNotNull("EngineFactory is not configured.", factory);
    JettyHTTPServerEngine engine = factory.createJettyHTTPServerEngine(1234, "http");
    assertNotNull("Engine is not available.", engine);
    assertEquals(1234, engine.getPort());
    assertEquals("Not http", "http", engine.getProtocol());
    Connector connector = engine.getConnector();
    Collection<ConnectionFactory> connectionFactories = connector.getConnectionFactories();
    assertEquals("Has one HttpConnectionFactory", 1, connectionFactories.size());
    ConnectionFactory connectionFactory = connectionFactories.iterator().next();
    assertTrue(connectionFactory instanceof HttpConnectionFactory);
    HttpConfiguration httpConfiguration = ((HttpConnectionFactory) connectionFactory).getHttpConfiguration();
    assertEquals("Has one ForwardedRequestCustomizer", 1, httpConfiguration.getCustomizers().size());
    assertTrue(httpConfiguration.getCustomizers().iterator().next() instanceof org.eclipse.jetty.server.ForwardedRequestCustomizer);
}
Also used : Connector(org.eclipse.jetty.server.Connector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) URL(java.net.URL) Test(org.junit.Test)

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