Home / Class/ Http2Server Class — netty Architecture

Http2Server Class — netty Architecture

Architecture documentation for the Http2Server class in Http2Server.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  321199ed_00bd_6449_3b19_8db7b5ac9cbf["Http2Server"]
  9097bdae_0bac_1e08_8339_fca4fe4b731d["Http2Server.java"]
  321199ed_00bd_6449_3b19_8db7b5ac9cbf -->|defined in| 9097bdae_0bac_1e08_8339_fca4fe4b731d
  4b7b013e_8c5e_0512_72d6_24da09a83c9c["main()"]
  321199ed_00bd_6449_3b19_8db7b5ac9cbf -->|method| 4b7b013e_8c5e_0512_72d6_24da09a83c9c

Relationship Graph

Source Code

example/src/main/java/io/netty/example/http2/helloworld/frame/server/Http2Server.java lines 46–98

public final class Http2Server {

    static final boolean SSL = System.getProperty("ssl") != null;

    static final int PORT = Integer.parseInt(System.getProperty("port", SSL? "8443" : "8080"));

    public static void main(String[] args) throws Exception {
        // Configure SSL.
        final SslContext sslCtx;
        if (SSL) {
            SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
            X509Bundle ssc = new CertificateBuilder()
                    .subject("cn=localhost")
                    .setIsCertificateAuthority(true)
                    .buildSelfSigned();
            sslCtx = SslContextBuilder.forServer(ssc.toKeyManagerFactory())
                .sslProvider(provider)
                /* NOTE: the cipher filter may not include all ciphers required by the HTTP/2 specification.
                 * Please refer to the HTTP/2 specification for cipher requirements. */
                .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
                .applicationProtocolConfig(new ApplicationProtocolConfig(
                    Protocol.ALPN,
                    // NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers.
                    SelectorFailureBehavior.NO_ADVERTISE,
                    // ACCEPT is currently the only mode supported by both OpenSsl and JDK providers.
                    SelectedListenerFailureBehavior.ACCEPT,
                    ApplicationProtocolNames.HTTP_2,
                    ApplicationProtocolNames.HTTP_1_1))
                .build();
        } else {
            sslCtx = null;
        }
        // Configure the server.
        EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
        try {
            ServerBootstrap b = new ServerBootstrap();
            b.option(ChannelOption.SO_BACKLOG, 1024);
            b.group(group)
             .channel(NioServerSocketChannel.class)
             .handler(new LoggingHandler(LogLevel.INFO))
             .childHandler(new Http2ServerInitializer(sslCtx));

            Channel ch = b.bind(PORT).sync().channel();

            System.err.println("Open your HTTP/2-enabled web browser and navigate to " +
                    (SSL? "https" : "http") + "://127.0.0.1:" + PORT + '/');

            ch.closeFuture().sync();
        } finally {
            group.shutdownGracefully();
        }
    }
}

Frequently Asked Questions

What is the Http2Server class?
Http2Server is a class in the netty codebase, defined in example/src/main/java/io/netty/example/http2/helloworld/frame/server/Http2Server.java.
Where is Http2Server defined?
Http2Server is defined in example/src/main/java/io/netty/example/http2/helloworld/frame/server/Http2Server.java at line 46.

Analyze Your Own Codebase

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

Try Supermodel Free