Home / Class/ ServerHandler Class — netty Architecture

ServerHandler Class — netty Architecture

Architecture documentation for the ServerHandler class in SocketSslGreetingTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  d0bc3222_da2e_450c_0129_fd542f55e428["ServerHandler"]
  4fe0c873_7a28_068c_869b_b9cc2be31bae["SocketSslGreetingTest.java"]
  d0bc3222_da2e_450c_0129_fd542f55e428 -->|defined in| 4fe0c873_7a28_068c_869b_b9cc2be31bae
  08e167ed_7b65_a3d2_fe9f_81db8622cbeb["channelRead0()"]
  d0bc3222_da2e_450c_0129_fd542f55e428 -->|method| 08e167ed_7b65_a3d2_fe9f_81db8622cbeb
  c0f5816d_a251_16e0_21ce_ed7b55cbc940["channelActive()"]
  d0bc3222_da2e_450c_0129_fd542f55e428 -->|method| c0f5816d_a251_16e0_21ce_ed7b55cbc940
  c9e8eba7_0abb_6e43_3675_24061410a872["exceptionCaught()"]
  d0bc3222_da2e_450c_0129_fd542f55e428 -->|method| c9e8eba7_0abb_6e43_3675_24061410a872
  106e5b64_19d2_7ac7_fe65_900eb7a1b833["userEventTriggered()"]
  d0bc3222_da2e_450c_0129_fd542f55e428 -->|method| 106e5b64_19d2_7ac7_fe65_900eb7a1b833

Relationship Graph

Source Code

testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSslGreetingTest.java lines 217–278

    private static class ServerHandler extends SimpleChannelInboundHandler<String> {
        volatile Channel channel;
        final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
            // discard
        }

        @Override
        public void channelActive(ChannelHandlerContext ctx)
                throws Exception {
            channel = ctx.channel();
            channel.writeAndFlush(ctx.alloc().buffer().writeByte('a'));
        }

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx,
                                    Throwable cause) throws Exception {
            if (logger.isWarnEnabled()) {
                logger.warn("Unexpected exception from the server side", cause);
            }

            exception.compareAndSet(null, cause);
            ctx.close();
        }

        @Override
        public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) throws Exception {
            if (evt instanceof SslHandshakeCompletionEvent) {
                final SslHandshakeCompletionEvent event = (SslHandshakeCompletionEvent) evt;
                if (event.isSuccess()) {
                    SSLSession session = ctx.pipeline().get(SslHandler.class).engine().getSession();
                    try {
                        session.getPeerCertificates();
                        fail();
                    } catch (SSLPeerUnverifiedException e) {
                        // expected
                    }
                    try {
                        session.getPeerCertificateChain();
                        fail();
                    } catch (SSLPeerUnverifiedException e) {
                        // expected
                    } catch (UnsupportedOperationException e) {
                        // Starting from Java15 this method throws UnsupportedOperationException as it was
                        // deprecated before and getPeerCertificates() should be used
                        if (PlatformDependent.javaVersion() < 15) {
                            throw e;
                        }
                    }
                    try {
                        session.getPeerPrincipal();
                        fail();
                    } catch (SSLPeerUnverifiedException e) {
                        // expected
                    }
                }
            }
            ctx.fireUserEventTriggered(evt);
        }
    }

Frequently Asked Questions

What is the ServerHandler class?
ServerHandler is a class in the netty codebase, defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSslGreetingTest.java.
Where is ServerHandler defined?
ServerHandler is defined in testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketSslGreetingTest.java at line 217.

Analyze Your Own Codebase

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

Try Supermodel Free