Search in sources :

Example 1 with ClientH2StreamMultiplexerFactory

use of org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory in project httpcomponents-core by apache.

the class H2RequesterBootstrap method create.

public H2AsyncRequester create() {
    final ManagedConnPool<HttpHost, IOSession> connPool;
    switch(poolConcurrencyPolicy != null ? poolConcurrencyPolicy : PoolConcurrencyPolicy.STRICT) {
        case LAX:
            connPool = new LaxConnPool<>(defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20, timeToLive, poolReusePolicy, new DefaultDisposalCallback<>(), connPoolListener);
            break;
        case STRICT:
        default:
            connPool = new StrictConnPool<>(defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20, maxTotal > 0 ? maxTotal : 50, timeToLive, poolReusePolicy, new DefaultDisposalCallback<>(), connPoolListener);
            break;
    }
    final RequestHandlerRegistry<Supplier<AsyncPushConsumer>> registry = new RequestHandlerRegistry<>(uriPatternType);
    for (final HandlerEntry<Supplier<AsyncPushConsumer>> entry : pushConsumerList) {
        registry.register(entry.hostname, entry.uriPattern, entry.handler);
    }
    final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(httpProcessor != null ? httpProcessor : H2Processors.client(), new DefaultAsyncPushConsumerFactory(registry), h2Config != null ? h2Config : H2Config.DEFAULT, charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT, streamListener);
    final TlsStrategy actualTlsStrategy = tlsStrategy != null ? tlsStrategy : new H2ClientTlsStrategy();
    final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ClientHttp1StreamDuplexerFactory(httpProcessor != null ? httpProcessor : HttpProcessors.client(), http1Config != null ? http1Config : Http1Config.DEFAULT, charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT, DefaultConnectionReuseStrategy.INSTANCE, new DefaultHttpResponseParserFactory(http1Config), DefaultHttpRequestWriterFactory.INSTANCE, DefaultContentLengthStrategy.INSTANCE, DefaultContentLengthStrategy.INSTANCE, http1StreamListener);
    final IOEventHandlerFactory ioEventHandlerFactory = new ClientHttpProtocolNegotiationStarter(http1StreamHandlerFactory, http2StreamHandlerFactory, versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE, actualTlsStrategy, handshakeTimeout);
    return new H2AsyncRequester(versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE, ioReactorConfig, ioEventHandlerFactory, ioSessionDecorator, exceptionCallback, sessionListener, connPool, actualTlsStrategy, handshakeTimeout);
}
Also used : H2ClientTlsStrategy(org.apache.hc.core5.http2.ssl.H2ClientTlsStrategy) TlsStrategy(org.apache.hc.core5.http.nio.ssl.TlsStrategy) DefaultDisposalCallback(org.apache.hc.core5.pool.DefaultDisposalCallback) ClientH2StreamMultiplexerFactory(org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory) ClientHttpProtocolNegotiationStarter(org.apache.hc.core5.http2.impl.nio.ClientHttpProtocolNegotiationStarter) RequestHandlerRegistry(org.apache.hc.core5.http.protocol.RequestHandlerRegistry) DefaultAsyncPushConsumerFactory(org.apache.hc.core5.http2.nio.support.DefaultAsyncPushConsumerFactory) DefaultHttpResponseParserFactory(org.apache.hc.core5.http.impl.nio.DefaultHttpResponseParserFactory) ClientHttp1StreamDuplexerFactory(org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory) HttpHost(org.apache.hc.core5.http.HttpHost) H2ClientTlsStrategy(org.apache.hc.core5.http2.ssl.H2ClientTlsStrategy) IOSession(org.apache.hc.core5.reactor.IOSession) Supplier(org.apache.hc.core5.function.Supplier) IOEventHandlerFactory(org.apache.hc.core5.reactor.IOEventHandlerFactory)

Example 2 with ClientH2StreamMultiplexerFactory

use of org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory in project httpcomponents-core by apache.

the class InternalClientProtocolNegotiationStarter method createHandler.

@Override
public IOEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
    if (sslContext != null) {
        ioSession.startTls(sslContext, null, null, sslSessionInitializer, sslSessionVerifier, null);
    }
    final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ClientHttp1StreamDuplexerFactory(httpProcessor != null ? httpProcessor : HttpProcessors.client(), http1Config, charCodingConfig, LoggingHttp1StreamListener.INSTANCE_CLIENT);
    final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(httpProcessor != null ? httpProcessor : H2Processors.client(), exchangeHandlerFactory, h2Config, charCodingConfig, LoggingH2StreamListener.INSTANCE);
    ioSession.registerProtocol(ApplicationProtocol.HTTP_1_1.id, new ClientHttp1UpgradeHandler(http1StreamHandlerFactory));
    ioSession.registerProtocol(ApplicationProtocol.HTTP_2.id, new ClientH2UpgradeHandler(http2StreamHandlerFactory));
    switch(versionPolicy) {
        case FORCE_HTTP_2:
            return new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, false);
        case FORCE_HTTP_1:
            return new ClientHttp1IOEventHandler(http1StreamHandlerFactory.create(ioSession));
        default:
            return new HttpProtocolNegotiator(ioSession, null);
    }
}
Also used : ClientH2PrefaceHandler(org.apache.hc.core5.http2.impl.nio.ClientH2PrefaceHandler) ClientHttp1StreamDuplexerFactory(org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory) HttpProtocolNegotiator(org.apache.hc.core5.http2.impl.nio.HttpProtocolNegotiator) ClientH2StreamMultiplexerFactory(org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory) ClientH2UpgradeHandler(org.apache.hc.core5.http2.impl.nio.ClientH2UpgradeHandler) ClientHttp1UpgradeHandler(org.apache.hc.core5.http2.impl.nio.ClientHttp1UpgradeHandler) ClientHttp1IOEventHandler(org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler)

Example 3 with ClientH2StreamMultiplexerFactory

use of org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory in project httpcomponents-core by apache.

the class H2MultiplexingRequesterBootstrap method create.

public H2MultiplexingRequester create() {
    final RequestHandlerRegistry<Supplier<AsyncPushConsumer>> registry = new RequestHandlerRegistry<>(uriPatternType);
    for (final HandlerEntry<Supplier<AsyncPushConsumer>> entry : pushConsumerList) {
        registry.register(entry.hostname, entry.uriPattern, entry.handler);
    }
    final ClientH2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientH2StreamMultiplexerFactory(httpProcessor != null ? httpProcessor : H2Processors.client(), new DefaultAsyncPushConsumerFactory(registry), h2Config != null ? h2Config : H2Config.DEFAULT, charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT, streamListener);
    return new H2MultiplexingRequester(ioReactorConfig, (ioSession, attachment) -> new ClientH2PrefaceHandler(ioSession, http2StreamHandlerFactory, strictALPNHandshake), ioSessionDecorator, exceptionCallback, sessionListener, DefaultAddressResolver.INSTANCE, tlsStrategy != null ? tlsStrategy : new H2ClientTlsStrategy());
}
Also used : RequestHandlerRegistry(org.apache.hc.core5.http.protocol.RequestHandlerRegistry) DefaultAsyncPushConsumerFactory(org.apache.hc.core5.http2.nio.support.DefaultAsyncPushConsumerFactory) ClientH2PrefaceHandler(org.apache.hc.core5.http2.impl.nio.ClientH2PrefaceHandler) ClientH2StreamMultiplexerFactory(org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory) H2ClientTlsStrategy(org.apache.hc.core5.http2.ssl.H2ClientTlsStrategy) Supplier(org.apache.hc.core5.function.Supplier)

Aggregations

ClientH2StreamMultiplexerFactory (org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory)3 Supplier (org.apache.hc.core5.function.Supplier)2 ClientHttp1StreamDuplexerFactory (org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory)2 RequestHandlerRegistry (org.apache.hc.core5.http.protocol.RequestHandlerRegistry)2 ClientH2PrefaceHandler (org.apache.hc.core5.http2.impl.nio.ClientH2PrefaceHandler)2 DefaultAsyncPushConsumerFactory (org.apache.hc.core5.http2.nio.support.DefaultAsyncPushConsumerFactory)2 H2ClientTlsStrategy (org.apache.hc.core5.http2.ssl.H2ClientTlsStrategy)2 HttpHost (org.apache.hc.core5.http.HttpHost)1 ClientHttp1IOEventHandler (org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler)1 DefaultHttpResponseParserFactory (org.apache.hc.core5.http.impl.nio.DefaultHttpResponseParserFactory)1 TlsStrategy (org.apache.hc.core5.http.nio.ssl.TlsStrategy)1 ClientH2UpgradeHandler (org.apache.hc.core5.http2.impl.nio.ClientH2UpgradeHandler)1 ClientHttp1UpgradeHandler (org.apache.hc.core5.http2.impl.nio.ClientHttp1UpgradeHandler)1 ClientHttpProtocolNegotiationStarter (org.apache.hc.core5.http2.impl.nio.ClientHttpProtocolNegotiationStarter)1 HttpProtocolNegotiator (org.apache.hc.core5.http2.impl.nio.HttpProtocolNegotiator)1 DefaultDisposalCallback (org.apache.hc.core5.pool.DefaultDisposalCallback)1 IOEventHandlerFactory (org.apache.hc.core5.reactor.IOEventHandlerFactory)1 IOSession (org.apache.hc.core5.reactor.IOSession)1