Search in sources :

Example 1 with ClientHttp1IOEventHandler

use of org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler in project httpcomponents-core by apache.

the class ClientHttp1UpgradeHandler method upgrade.

@Override
public void upgrade(final ProtocolIOSession ioSession, final FutureCallback<ProtocolIOSession> callback) {
    final ClientHttp1IOEventHandler eventHandler = new ClientHttp1IOEventHandler(http1StreamHandlerFactory.create(ioSession));
    ioSession.upgrade(eventHandler);
    try {
        eventHandler.connected(ioSession);
        if (callback != null) {
            callback.completed(ioSession);
        }
    } catch (final IOException ex) {
        eventHandler.exception(ioSession, ex);
    }
}
Also used : IOException(java.io.IOException) ClientHttp1IOEventHandler(org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler)

Example 2 with ClientHttp1IOEventHandler

use of org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler in project httpcomponents-core by apache.

the class ClientHttpProtocolNegotiationStarter method createHandler.

@Override
public HttpConnectionEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
    HttpVersionPolicy endpointPolicy = versionPolicy;
    if (attachment instanceof EndpointParameters) {
        final EndpointParameters params = (EndpointParameters) attachment;
        if (tlsStrategy != null && URIScheme.HTTPS.same(params.getScheme())) {
            tlsStrategy.upgrade(ioSession, params, params.getAttachment(), handshakeTimeout, null);
        }
        if (params.getAttachment() instanceof HttpVersionPolicy) {
            endpointPolicy = (HttpVersionPolicy) params.getAttachment();
        }
    }
    ioSession.registerProtocol(ApplicationProtocol.HTTP_1_1.id, new ClientHttp1UpgradeHandler(http1StreamHandlerFactory));
    ioSession.registerProtocol(ApplicationProtocol.HTTP_2.id, new ClientH2UpgradeHandler(http2StreamHandlerFactory));
    switch(endpointPolicy) {
        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 : HttpVersionPolicy(org.apache.hc.core5.http2.HttpVersionPolicy) EndpointParameters(org.apache.hc.core5.reactor.EndpointParameters) ClientHttp1IOEventHandler(org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler)

Example 3 with ClientHttp1IOEventHandler

use of org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler 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)

Aggregations

ClientHttp1IOEventHandler (org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler)3 IOException (java.io.IOException)1 ClientHttp1StreamDuplexerFactory (org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory)1 HttpVersionPolicy (org.apache.hc.core5.http2.HttpVersionPolicy)1 ClientH2PrefaceHandler (org.apache.hc.core5.http2.impl.nio.ClientH2PrefaceHandler)1 ClientH2StreamMultiplexerFactory (org.apache.hc.core5.http2.impl.nio.ClientH2StreamMultiplexerFactory)1 ClientH2UpgradeHandler (org.apache.hc.core5.http2.impl.nio.ClientH2UpgradeHandler)1 ClientHttp1UpgradeHandler (org.apache.hc.core5.http2.impl.nio.ClientHttp1UpgradeHandler)1 HttpProtocolNegotiator (org.apache.hc.core5.http2.impl.nio.HttpProtocolNegotiator)1 EndpointParameters (org.apache.hc.core5.reactor.EndpointParameters)1