Search in sources :

Example 6 with ReferenceCountedOpenSslEngine

use of io.netty.handler.ssl.ReferenceCountedOpenSslEngine in project netty by netty.

the class OcspClientExample method newClientHandler.

private static ChannelInitializer<Channel> newClientHandler(final ReferenceCountedOpenSslContext context, final String host, final Promise<FullHttpResponse> promise) {
    return new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            SslHandler sslHandler = context.newHandler(ch.alloc());
            ReferenceCountedOpenSslEngine engine = (ReferenceCountedOpenSslEngine) sslHandler.engine();
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(sslHandler);
            pipeline.addLast(new ExampleOcspClientHandler(engine));
            pipeline.addLast(new HttpClientCodec());
            pipeline.addLast(new HttpObjectAggregator(1024 * 1024));
            pipeline.addLast(new HttpClientHandler(host, promise));
        }

        @Override
        public void channelInactive(ChannelHandlerContext ctx) throws Exception {
            if (!promise.isDone()) {
                promise.tryFailure(new IllegalStateException("Connection closed and Promise was not done."));
            }
            ctx.fireChannelInactive();
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            if (!promise.tryFailure(cause)) {
                ctx.fireExceptionCaught(cause);
            }
        }
    };
}
Also used : ReferenceCountedOpenSslEngine(io.netty.handler.ssl.ReferenceCountedOpenSslEngine) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelInitializer(io.netty.channel.ChannelInitializer) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) SslHandler(io.netty.handler.ssl.SslHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

ReferenceCountedOpenSslEngine (io.netty.handler.ssl.ReferenceCountedOpenSslEngine)6 SslHandler (io.netty.handler.ssl.SslHandler)6 Channel (io.netty.channel.Channel)4 ChannelInitializer (io.netty.channel.ChannelInitializer)4 ChannelPipeline (io.netty.channel.ChannelPipeline)4 LocalChannel (io.netty.channel.local.LocalChannel)2 LocalServerChannel (io.netty.channel.local.LocalServerChannel)2 SslContext (io.netty.handler.ssl.SslContext)2 Executable (org.junit.jupiter.api.function.Executable)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)1 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)1 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)1