Home / Function/ testSniWithAlpnHandler() — netty Function Reference

testSniWithAlpnHandler() — netty Function Reference

Architecture documentation for the testSniWithAlpnHandler() function in SniHandlerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  925607e8_a787_e27e_c903_01fcc053a644["testSniWithAlpnHandler()"]
  00b45f27_cbf5_af92_430f_7f0426117fa5["SniHandlerTest"]
  925607e8_a787_e27e_c903_01fcc053a644 -->|defined in| 00b45f27_cbf5_af92_430f_7f0426117fa5
  495097de_5185_3185_66b9_43abc32cf9ab["releaseAll()"]
  925607e8_a787_e27e_c903_01fcc053a644 -->|calls| 495097de_5185_3185_66b9_43abc32cf9ab
  style 925607e8_a787_e27e_c903_01fcc053a644 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

handler/src/test/java/io/netty/handler/ssl/SniHandlerTest.java lines 398–483

    @ParameterizedTest(name = "{index}: sslProvider={0}")
    @MethodSource("data")
    public void testSniWithAlpnHandler(SslProvider provider) throws Exception {
        SslContext nettyContext = makeSslContext(provider, true);
        SslContext sniContext = makeSslContext(provider, true);
        final SslContext clientContext = makeSslClientContext(provider, true);
        try {
            final AtomicBoolean serverAlpnCtx = new AtomicBoolean(false);
            final AtomicBoolean clientAlpnCtx = new AtomicBoolean(false);
            final CountDownLatch serverAlpnDoneLatch = new CountDownLatch(1);
            final CountDownLatch clientAlpnDoneLatch = new CountDownLatch(1);

            final DomainNameMapping<SslContext> mapping = new DomainNameMappingBuilder<SslContext>(nettyContext)
                    .add("*.netty.io", nettyContext)
                    .add("sni.fake.site", sniContext).build();
            final SniHandler handler = new SniHandler(mapping);
            EventLoopGroup group = new MultiThreadIoEventLoopGroup(2, NioIoHandler.newFactory());
            Channel serverChannel = null;
            Channel clientChannel = null;
            try {
                ServerBootstrap sb = new ServerBootstrap();
                sb.group(group);
                sb.channel(NioServerSocketChannel.class);
                sb.childHandler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        // Server side SNI.
                        p.addLast(handler);
                        // Catch the notification event that ALPN has completed successfully.
                        p.addLast(new ApplicationProtocolNegotiationHandler("foo") {
                            @Override
                            protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
                                // addresses issue #9131
                                serverAlpnCtx.set(ctx.pipeline().context(this) != null);
                                serverAlpnDoneLatch.countDown();
                            }
                        });
                    }
                });

                Bootstrap cb = new Bootstrap();
                cb.group(group);
                cb.channel(NioSocketChannel.class);
                cb.handler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel ch) throws Exception {
                        ch.pipeline().addLast(new SslHandler(clientContext.newEngine(
                                ch.alloc(), "sni.fake.site", -1)));
                        // Catch the notification event that ALPN has completed successfully.
                        ch.pipeline().addLast(new ApplicationProtocolNegotiationHandler("foo") {
                            @Override
                            protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
                                // addresses issue #9131
                                clientAlpnCtx.set(ctx.pipeline().context(this) != null);
                                clientAlpnDoneLatch.countDown();
                            }
                        });
                    }
                });

                serverChannel = sb.bind(new InetSocketAddress(0)).sync().channel();

                ChannelFuture ccf = cb.connect(serverChannel.localAddress());
                assertTrue(ccf.awaitUninterruptibly().isSuccess());
                clientChannel = ccf.channel();

                assertTrue(serverAlpnDoneLatch.await(5, TimeUnit.SECONDS));
                assertTrue(clientAlpnDoneLatch.await(5, TimeUnit.SECONDS));
                assertTrue(serverAlpnCtx.get());
                assertTrue(clientAlpnCtx.get());
                assertEquals("sni.fake.site", handler.hostname());
                assertEquals(sniContext, handler.sslContext());
            } finally {
                if (serverChannel != null) {
                    serverChannel.close().sync();
                }
                if (clientChannel != null) {
                    clientChannel.close().sync();
                }
                group.shutdownGracefully(0, 0, TimeUnit.MICROSECONDS);

Domain

Subdomains

Calls

Frequently Asked Questions

What does testSniWithAlpnHandler() do?
testSniWithAlpnHandler() is a function in the netty codebase, defined in handler/src/test/java/io/netty/handler/ssl/SniHandlerTest.java.
Where is testSniWithAlpnHandler() defined?
testSniWithAlpnHandler() is defined in handler/src/test/java/io/netty/handler/ssl/SniHandlerTest.java at line 398.
What does testSniWithAlpnHandler() call?
testSniWithAlpnHandler() calls 1 function(s): releaseAll.

Analyze Your Own Codebase

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

Try Supermodel Free