Search in sources :

Example 6 with IOEventHandler

use of org.apache.hc.core5.reactor.IOEventHandler in project httpcomponents-core by apache.

the class ServerHttp1IOEventHandlerFactory method createHandler.

@Override
public IOEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
    String endpointScheme = URIScheme.HTTP.id;
    if (attachment instanceof EndpointParameters) {
        final EndpointParameters params = (EndpointParameters) attachment;
        endpointScheme = params.getScheme();
        if (tlsStrategy != null && URIScheme.HTTPS.same(endpointScheme)) {
            tlsStrategy.upgrade(ioSession, params, params.getAttachment(), handshakeTimeout, null);
        }
    } else {
        tlsStrategy.upgrade(ioSession, null, attachment, handshakeTimeout, null);
    }
    return new ServerHttp1IOEventHandler(streamDuplexerFactory.create(endpointScheme, ioSession));
}
Also used : EndpointParameters(org.apache.hc.core5.reactor.EndpointParameters)

Example 7 with IOEventHandler

use of org.apache.hc.core5.reactor.IOEventHandler in project httpcomponents-core by apache.

the class SSLIOSession method ensureHandler.

private IOEventHandler ensureHandler() {
    final IOEventHandler handler = session.getHandler();
    Asserts.notNull(handler, "IO event handler");
    return handler;
}
Also used : IOEventHandler(org.apache.hc.core5.reactor.IOEventHandler)

Example 8 with IOEventHandler

use of org.apache.hc.core5.reactor.IOEventHandler in project httpcomponents-core by apache.

the class InternalDataChannel method onException.

@Override
void onException(final Exception cause) {
    final IOSession currentSession = currentSessionRef.get();
    if (sessionListener != null) {
        sessionListener.exception(currentSession, cause);
    }
    final IOEventHandler handler = currentSession.getHandler();
    if (handler != null) {
        handler.exception(currentSession, cause);
    }
}
Also used : SSLIOSession(org.apache.hc.core5.reactor.ssl.SSLIOSession)

Example 9 with IOEventHandler

use of org.apache.hc.core5.reactor.IOEventHandler 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 10 with IOEventHandler

use of org.apache.hc.core5.reactor.IOEventHandler in project httpcomponents-core by apache.

the class InternalServerProtocolNegotiationStarter method createHandler.

@Override
public IOEventHandler createHandler(final ProtocolIOSession ioSession, final Object attachment) {
    if (sslContext != null) {
        ioSession.startTls(sslContext, null, null, sslSessionInitializer, sslSessionVerifier, null);
    }
    final ServerHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ServerHttp1StreamDuplexerFactory(httpProcessor != null ? httpProcessor : HttpProcessors.server(), exchangeHandlerFactory, http1Config, charCodingConfig, LoggingHttp1StreamListener.INSTANCE_SERVER);
    final ServerH2StreamMultiplexerFactory http2StreamHandlerFactory = new ServerH2StreamMultiplexerFactory(httpProcessor != null ? httpProcessor : H2Processors.server(), exchangeHandlerFactory, h2Config, charCodingConfig, LoggingH2StreamListener.INSTANCE);
    ioSession.registerProtocol(ApplicationProtocol.HTTP_1_1.id, new ServerHttp1UpgradeHandler(http1StreamHandlerFactory));
    ioSession.registerProtocol(ApplicationProtocol.HTTP_2.id, new ServerH2UpgradeHandler(http2StreamHandlerFactory));
    switch(versionPolicy) {
        case FORCE_HTTP_2:
            return new ServerH2PrefaceHandler(ioSession, http2StreamHandlerFactory);
        case FORCE_HTTP_1:
            return new ServerHttp1IOEventHandler(http1StreamHandlerFactory.create(sslContext != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id, ioSession));
        default:
            return new HttpProtocolNegotiator(ioSession, null);
    }
}
Also used : ServerHttp1StreamDuplexerFactory(org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory) ServerH2PrefaceHandler(org.apache.hc.core5.http2.impl.nio.ServerH2PrefaceHandler) HttpProtocolNegotiator(org.apache.hc.core5.http2.impl.nio.HttpProtocolNegotiator) ServerH2StreamMultiplexerFactory(org.apache.hc.core5.http2.impl.nio.ServerH2StreamMultiplexerFactory) ServerHttp1IOEventHandler(org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler) ServerHttp1UpgradeHandler(org.apache.hc.core5.http2.impl.nio.ServerHttp1UpgradeHandler) ServerH2UpgradeHandler(org.apache.hc.core5.http2.impl.nio.ServerH2UpgradeHandler)

Aggregations

SSLIOSession (org.apache.hc.core5.reactor.ssl.SSLIOSession)4 IOEventHandler (org.apache.hc.core5.reactor.IOEventHandler)3 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 HttpProtocolNegotiator (org.apache.hc.core5.http2.impl.nio.HttpProtocolNegotiator)2 File (java.io.File)1 SocketAddress (java.net.SocketAddress)1 ByteChannel (java.nio.channels.ByteChannel)1 Lock (java.util.concurrent.locks.Lock)1 SSLContext (javax.net.ssl.SSLContext)1 Header (org.apache.hc.core5.http.Header)1 HttpConnection (org.apache.hc.core5.http.HttpConnection)1 HttpRequest (org.apache.hc.core5.http.HttpRequest)1 HttpResponse (org.apache.hc.core5.http.HttpResponse)1 Http1StreamListener (org.apache.hc.core5.http.impl.Http1StreamListener)1 HttpAsyncRequester (org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester)1 ClientHttp1IOEventHandler (org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler)1 ClientHttp1StreamDuplexerFactory (org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory)1 ServerHttp1IOEventHandler (org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler)1 ServerHttp1StreamDuplexerFactory (org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory)1