Search in sources :

Example 1 with ClientConnectionFactory

use of org.eclipse.jetty.io.ClientConnectionFactory in project jetty.project by eclipse.

the class HTTP2Client method doStart.

@Override
protected void doStart() throws Exception {
    if (executor == null)
        setExecutor(new QueuedThreadPool());
    if (scheduler == null)
        setScheduler(new ScheduledExecutorScheduler());
    if (bufferPool == null)
        setByteBufferPool(new MappedByteBufferPool());
    if (connectionFactory == null) {
        HTTP2ClientConnectionFactory h2 = new HTTP2ClientConnectionFactory();
        setClientConnectionFactory((endPoint, context) -> {
            ClientConnectionFactory factory = h2;
            SslContextFactory sslContextFactory = (SslContextFactory) context.get(SslClientConnectionFactory.SSL_CONTEXT_FACTORY_CONTEXT_KEY);
            if (sslContextFactory != null) {
                ALPNClientConnectionFactory alpn = new ALPNClientConnectionFactory(getExecutor(), h2, getProtocols());
                factory = new SslClientConnectionFactory(sslContextFactory, getByteBufferPool(), getExecutor(), alpn);
            }
            return factory.newConnection(endPoint, context);
        });
    }
    if (selector == null) {
        selector = newSelectorManager();
        addBean(selector);
    }
    selector.setConnectTimeout(getConnectTimeout());
    super.doStart();
}
Also used : MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) SslClientConnectionFactory(org.eclipse.jetty.io.ssl.SslClientConnectionFactory) ALPNClientConnectionFactory(org.eclipse.jetty.alpn.client.ALPNClientConnectionFactory) ClientConnectionFactory(org.eclipse.jetty.io.ClientConnectionFactory) SslClientConnectionFactory(org.eclipse.jetty.io.ssl.SslClientConnectionFactory) ALPNClientConnectionFactory(org.eclipse.jetty.alpn.client.ALPNClientConnectionFactory)

Example 2 with ClientConnectionFactory

use of org.eclipse.jetty.io.ClientConnectionFactory in project jetty.project by eclipse.

the class HttpClientTimeoutTest method testIdleTimeout.

@Test
public void testIdleTimeout() throws Throwable {
    long timeout = 1000;
    start(new TimeoutHandler(2 * timeout));
    client.stop();
    final AtomicBoolean sslIdle = new AtomicBoolean();
    client = new HttpClient(new HttpClientTransportOverHTTP() {

        @Override
        public HttpDestination newHttpDestination(Origin origin) {
            return new HttpDestinationOverHTTP(getHttpClient(), origin) {

                @Override
                protected ClientConnectionFactory newSslClientConnectionFactory(ClientConnectionFactory connectionFactory) {
                    HttpClient client = getHttpClient();
                    return new SslClientConnectionFactory(client.getSslContextFactory(), client.getByteBufferPool(), client.getExecutor(), connectionFactory) {

                        @Override
                        protected SslConnection newSslConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine engine) {
                            return new SslConnection(byteBufferPool, executor, endPoint, engine) {

                                @Override
                                protected boolean onReadTimeout() {
                                    sslIdle.set(true);
                                    return super.onReadTimeout();
                                }
                            };
                        }
                    };
                }
            };
        }
    }, sslContextFactory);
    client.setIdleTimeout(timeout);
    client.start();
    try {
        client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).send();
        Assert.fail();
    } catch (Exception x) {
        Assert.assertFalse(sslIdle.get());
        Assert.assertThat(x.getCause(), Matchers.instanceOf(TimeoutException.class));
    }
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) SSLEngine(javax.net.ssl.SSLEngine) SslClientConnectionFactory(org.eclipse.jetty.io.ssl.SslClientConnectionFactory) HttpClientTransportOverHTTP(org.eclipse.jetty.client.http.HttpClientTransportOverHTTP) ClientConnectionFactory(org.eclipse.jetty.io.ClientConnectionFactory) SslClientConnectionFactory(org.eclipse.jetty.io.ssl.SslClientConnectionFactory) EndPoint(org.eclipse.jetty.io.EndPoint) ServletException(javax.servlet.ServletException) TimeoutException(java.util.concurrent.TimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) SslConnection(org.eclipse.jetty.io.ssl.SslConnection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Executor(java.util.concurrent.Executor) HttpDestinationOverHTTP(org.eclipse.jetty.client.http.HttpDestinationOverHTTP) Test(org.junit.Test)

Example 3 with ClientConnectionFactory

use of org.eclipse.jetty.io.ClientConnectionFactory in project jetty.project by eclipse.

the class HttpClientTransportOverHTTP2 method newConnection.

@Override
public org.eclipse.jetty.io.Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException {
    endPoint.setIdleTimeout(httpClient.getIdleTimeout());
    ClientConnectionFactory factory = connectionFactory;
    HttpDestinationOverHTTP2 destination = (HttpDestinationOverHTTP2) context.get(HTTP_DESTINATION_CONTEXT_KEY);
    ProxyConfiguration.Proxy proxy = destination.getProxy();
    boolean ssl = proxy == null ? HttpScheme.HTTPS.is(destination.getScheme()) : proxy.isSecure();
    if (ssl && isUseALPN())
        factory = new ALPNClientConnectionFactory(client.getExecutor(), factory, client.getProtocols());
    return factory.newConnection(endPoint, context);
}
Also used : ProxyConfiguration(org.eclipse.jetty.client.ProxyConfiguration) HTTP2ClientConnectionFactory(org.eclipse.jetty.http2.client.HTTP2ClientConnectionFactory) ALPNClientConnectionFactory(org.eclipse.jetty.alpn.client.ALPNClientConnectionFactory) ClientConnectionFactory(org.eclipse.jetty.io.ClientConnectionFactory) ALPNClientConnectionFactory(org.eclipse.jetty.alpn.client.ALPNClientConnectionFactory)

Aggregations

ClientConnectionFactory (org.eclipse.jetty.io.ClientConnectionFactory)3 ALPNClientConnectionFactory (org.eclipse.jetty.alpn.client.ALPNClientConnectionFactory)2 SslClientConnectionFactory (org.eclipse.jetty.io.ssl.SslClientConnectionFactory)2 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 Executor (java.util.concurrent.Executor)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 SSLEngine (javax.net.ssl.SSLEngine)1 ServletException (javax.servlet.ServletException)1 ProxyConfiguration (org.eclipse.jetty.client.ProxyConfiguration)1 HttpClientTransportOverHTTP (org.eclipse.jetty.client.http.HttpClientTransportOverHTTP)1 HttpDestinationOverHTTP (org.eclipse.jetty.client.http.HttpDestinationOverHTTP)1 HTTP2ClientConnectionFactory (org.eclipse.jetty.http2.client.HTTP2ClientConnectionFactory)1 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)1 EndPoint (org.eclipse.jetty.io.EndPoint)1 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)1 SslConnection (org.eclipse.jetty.io.ssl.SslConnection)1 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)1 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)1