Home / Class/ JdkAlpnSslEngine Class — netty Architecture

JdkAlpnSslEngine Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  d8cb79d3_c5a5_3f8e_f6cb_0f6af1b8dc77["JdkAlpnSslEngine"]
  69cf3d4a_9aaa_8f16_811c_d0f7b92e1125["JdkAlpnSslEngine.java"]
  d8cb79d3_c5a5_3f8e_f6cb_0f6af1b8dc77 -->|defined in| 69cf3d4a_9aaa_8f16_811c_d0f7b92e1125
  d4048a74_84a2_23f7_b9f4_1bbd8bb6d1d7["JdkAlpnSslEngine()"]
  d8cb79d3_c5a5_3f8e_f6cb_0f6af1b8dc77 -->|method| d4048a74_84a2_23f7_b9f4_1bbd8bb6d1d7
  4cffc5c1_c0d5_210b_a134_7061cd50e24c["SSLEngineResult()"]
  d8cb79d3_c5a5_3f8e_f6cb_0f6af1b8dc77 -->|method| 4cffc5c1_c0d5_210b_a134_7061cd50e24c
  4e8fd2ee_d878_56f2_3546_9c7c02ad2f0a["setNegotiatedApplicationProtocol()"]
  d8cb79d3_c5a5_3f8e_f6cb_0f6af1b8dc77 -->|method| 4e8fd2ee_d878_56f2_3546_9c7c02ad2f0a
  7d1cbdd5_8a4c_2b0e_50bd_f5714cad6ebe["String()"]
  d8cb79d3_c5a5_3f8e_f6cb_0f6af1b8dc77 -->|method| 7d1cbdd5_8a4c_2b0e_50bd_f5714cad6ebe
  05804058_11a3_ef8b_a929_ad3f2f11d38d["setHandshakeApplicationProtocolSelector()"]
  d8cb79d3_c5a5_3f8e_f6cb_0f6af1b8dc77 -->|method| 05804058_11a3_ef8b_a929_ad3f2f11d38d
  7111e3fa_586f_6ed6_3578_8cd547663724["getHandshakeApplicationProtocolSelector()"]
  d8cb79d3_c5a5_3f8e_f6cb_0f6af1b8dc77 -->|method| 7111e3fa_586f_6ed6_3578_8cd547663724

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java lines 33–208

class JdkAlpnSslEngine extends JdkSslEngine {
    private final ProtocolSelectionListener selectionListener;
    private final AlpnSelector alpnSelector;

    final class AlpnSelector implements BiFunction<SSLEngine, List<String>, String> {
        private final ProtocolSelector selector;
        private boolean called;

        AlpnSelector(ProtocolSelector selector) {
            this.selector = selector;
        }

        @Override
        public String apply(SSLEngine sslEngine, List<String> strings) {
            assert !called;
            called = true;

            try {
                String selected = selector.select(strings);
                return selected == null ? StringUtil.EMPTY_STRING : selected;
            } catch (Exception cause) {
                // Returning null means we want to fail the handshake.
                //
                // See https://download.java.net/java/jdk9/docs/api/javax/net/ssl/
                // SSLEngine.html#setHandshakeApplicationProtocolSelector-java.util.function.BiFunction-
                return null;
            }
        }

        void checkUnsupported() {
            if (called) {
                // ALPN message was received by peer and so apply(...) was called.
                // See:
                // https://hg.openjdk.java.net/jdk9/dev/jdk/file/65464a307408/src/
                // java.base/share/classes/sun/security/ssl/ServerHandshaker.java#l933
                return;
            }
            String protocol = getApplicationProtocol();
            assert protocol != null;

            if (protocol.isEmpty()) {
                // ALPN is not supported
                selector.unsupported();
            }
        }
    }

    JdkAlpnSslEngine(SSLEngine engine,
                     @SuppressWarnings("deprecation") JdkApplicationProtocolNegotiator applicationNegotiator,
                     boolean isServer, BiConsumer<SSLEngine, AlpnSelector> setHandshakeApplicationProtocolSelector,
                     BiConsumer<SSLEngine, List<String>> setApplicationProtocols) {
        super(engine);
        if (isServer) {
            selectionListener = null;
            alpnSelector = new AlpnSelector(applicationNegotiator.protocolSelectorFactory().
                    newSelector(this, new LinkedHashSet<String>(applicationNegotiator.protocols())));
            setHandshakeApplicationProtocolSelector.accept(engine, alpnSelector);
        } else {
            selectionListener = applicationNegotiator.protocolListenerFactory()
                    .newListener(this, applicationNegotiator.protocols());
            alpnSelector = null;
            setApplicationProtocols.accept(engine, applicationNegotiator.protocols());
        }
    }

    JdkAlpnSslEngine(SSLEngine engine,
                     @SuppressWarnings("deprecation") JdkApplicationProtocolNegotiator applicationNegotiator,
                     boolean isServer) {
       this(engine, applicationNegotiator, isServer,
               new BiConsumer<SSLEngine, AlpnSelector>() {
                   @Override
                   public void accept(SSLEngine e, AlpnSelector s) {
                       JdkAlpnSslUtils.setHandshakeApplicationProtocolSelector(e, s);
                   }
               },
               new BiConsumer<SSLEngine, List<String>>() {
                   @Override
                   public void accept(SSLEngine e, List<String> p) {
                       JdkAlpnSslUtils.setApplicationProtocols(e, p);
                   }
               });

Frequently Asked Questions

What is the JdkAlpnSslEngine class?
JdkAlpnSslEngine is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java.
Where is JdkAlpnSslEngine defined?
JdkAlpnSslEngine is defined in handler/src/main/java/io/netty/handler/ssl/JdkAlpnSslEngine.java at line 33.

Analyze Your Own Codebase

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

Try Supermodel Free