Home / Class/ HttpClientHandler Class — netty Architecture

HttpClientHandler Class — netty Architecture

Architecture documentation for the HttpClientHandler class in OcspClientExample.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  286fbb21_21f0_f764_be9d_2b1afb00251d["HttpClientHandler"]
  78bd9b38_0697_2858_7e74_e153357ddaa0["OcspClientExample.java"]
  286fbb21_21f0_f764_be9d_2b1afb00251d -->|defined in| 78bd9b38_0697_2858_7e74_e153357ddaa0
  28cf4fac_54d5_f010_d80d_800e8c4bfa89["HttpClientHandler()"]
  286fbb21_21f0_f764_be9d_2b1afb00251d -->|method| 28cf4fac_54d5_f010_d80d_800e8c4bfa89
  8392debf_b977_e60f_1948_81448685dbe1["channelActive()"]
  286fbb21_21f0_f764_be9d_2b1afb00251d -->|method| 8392debf_b977_e60f_1948_81448685dbe1
  26b69687_a861_74d4_aa52_509b6cf27905["channelInactive()"]
  286fbb21_21f0_f764_be9d_2b1afb00251d -->|method| 26b69687_a861_74d4_aa52_509b6cf27905
  3af5a6a8_7e47_35a2_dd81_438bc6b0d146["channelRead()"]
  286fbb21_21f0_f764_be9d_2b1afb00251d -->|method| 3af5a6a8_7e47_35a2_dd81_438bc6b0d146
  68c47f62_7713_7342_b31e_d3fd13efdb85["exceptionCaught()"]
  286fbb21_21f0_f764_be9d_2b1afb00251d -->|method| 68c47f62_7713_7342_b31e_d3fd13efdb85

Relationship Graph

Source Code

example/src/main/java/io/netty/example/ocsp/OcspClientExample.java lines 156–205

    private static class HttpClientHandler extends ChannelInboundHandlerAdapter {

        private final String host;

        private final Promise<FullHttpResponse> promise;

        HttpClientHandler(String host, Promise<FullHttpResponse> promise) {
            this.host = host;
            this.promise = promise;
        }

        @Override
        public void channelActive(ChannelHandlerContext ctx) throws Exception {
            FullHttpRequest request = new DefaultFullHttpRequest(
                    HttpVersion.HTTP_1_1, HttpMethod.GET, "/", Unpooled.EMPTY_BUFFER);
            request.headers().set(HttpHeaderNames.HOST, host);
            request.headers().set(HttpHeaderNames.USER_AGENT, "netty-ocsp-example/1.0");

            ctx.writeAndFlush(request).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);

            ctx.fireChannelActive();
        }

        @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 channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
            if (msg instanceof FullHttpResponse) {
                if (!promise.trySuccess((FullHttpResponse) msg)) {
                    ReferenceCountUtil.release(msg);
                }
                return;
            }

            ctx.fireChannelRead(msg);
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            if (!promise.tryFailure(cause)) {
                ctx.fireExceptionCaught(cause);
            }
        }
    }

Frequently Asked Questions

What is the HttpClientHandler class?
HttpClientHandler is a class in the netty codebase, defined in example/src/main/java/io/netty/example/ocsp/OcspClientExample.java.
Where is HttpClientHandler defined?
HttpClientHandler is defined in example/src/main/java/io/netty/example/ocsp/OcspClientExample.java at line 156.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free