Search in sources :

Example 1 with JettyResourceFactory

use of org.springframework.http.client.reactive.JettyResourceFactory in project spring-boot by spring-projects.

the class ClientHttpConnectorConfigurationTests method jettyClientHttpConnectorAppliesJettyResourceFactory.

@Test
void jettyClientHttpConnectorAppliesJettyResourceFactory() {
    Executor executor = mock(Executor.class);
    ByteBufferPool byteBufferPool = mock(ByteBufferPool.class);
    Scheduler scheduler = mock(Scheduler.class);
    JettyResourceFactory jettyResourceFactory = new JettyResourceFactory();
    jettyResourceFactory.setExecutor(executor);
    jettyResourceFactory.setByteBufferPool(byteBufferPool);
    jettyResourceFactory.setScheduler(scheduler);
    JettyClientHttpConnector connector = getClientHttpConnector(jettyResourceFactory);
    HttpClient httpClient = (HttpClient) ReflectionTestUtils.getField(connector, "httpClient");
    assertThat(httpClient.getExecutor()).isSameAs(executor);
    assertThat(httpClient.getByteBufferPool()).isSameAs(byteBufferPool);
    assertThat(httpClient.getScheduler()).isSameAs(scheduler);
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) JettyResourceFactory(org.springframework.http.client.reactive.JettyResourceFactory) Executor(java.util.concurrent.Executor) Scheduler(org.eclipse.jetty.util.thread.Scheduler) HttpClient(org.eclipse.jetty.client.HttpClient) JettyClientHttpConnector(org.springframework.http.client.reactive.JettyClientHttpConnector) Test(org.junit.jupiter.api.Test)

Example 2 with JettyResourceFactory

use of org.springframework.http.client.reactive.JettyResourceFactory in project spring-boot by spring-projects.

the class ClientHttpConnectorConfigurationTests method JettyResourceFactoryHasSslContextFactory.

@Test
void JettyResourceFactoryHasSslContextFactory() {
    // gh-16810
    JettyResourceFactory jettyResourceFactory = new JettyResourceFactory();
    JettyClientHttpConnector connector = getClientHttpConnector(jettyResourceFactory);
    HttpClient httpClient = (HttpClient) ReflectionTestUtils.getField(connector, "httpClient");
    assertThat(httpClient.getSslContextFactory()).isNotNull();
}
Also used : JettyResourceFactory(org.springframework.http.client.reactive.JettyResourceFactory) HttpClient(org.eclipse.jetty.client.HttpClient) JettyClientHttpConnector(org.springframework.http.client.reactive.JettyClientHttpConnector) Test(org.junit.jupiter.api.Test)

Example 3 with JettyResourceFactory

use of org.springframework.http.client.reactive.JettyResourceFactory 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)

Example 4 with JettyResourceFactory

use of org.springframework.http.client.reactive.JettyResourceFactory in project spring-boot by spring-projects.

the class JettyReactiveWebServerFactoryTests method useServerResources.

@Test
void useServerResources() throws Exception {
    JettyResourceFactory resourceFactory = new JettyResourceFactory();
    resourceFactory.afterPropertiesSet();
    JettyReactiveWebServerFactory factory = getFactory();
    factory.setResourceFactory(resourceFactory);
    JettyWebServer webServer = (JettyWebServer) factory.getWebServer(new EchoHandler());
    webServer.start();
    Connector connector = webServer.getServer().getConnectors()[0];
    assertThat(connector.getByteBufferPool()).isEqualTo(resourceFactory.getByteBufferPool());
    assertThat(connector.getExecutor()).isEqualTo(resourceFactory.getExecutor());
    assertThat(connector.getScheduler()).isEqualTo(resourceFactory.getScheduler());
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) JettyResourceFactory(org.springframework.http.client.reactive.JettyResourceFactory) Test(org.junit.jupiter.api.Test)

Aggregations

JettyResourceFactory (org.springframework.http.client.reactive.JettyResourceFactory)4 Test (org.junit.jupiter.api.Test)3 HttpClient (org.eclipse.jetty.client.HttpClient)2 ServerConnector (org.eclipse.jetty.server.ServerConnector)2 JettyClientHttpConnector (org.springframework.http.client.reactive.JettyClientHttpConnector)2 ArrayList (java.util.ArrayList)1 Executor (java.util.concurrent.Executor)1 HTTP2CServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory)1 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)1 ConnectionFactory (org.eclipse.jetty.server.ConnectionFactory)1 Connector (org.eclipse.jetty.server.Connector)1 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)1 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)1 Scheduler (org.eclipse.jetty.util.thread.Scheduler)1