org.eclipse.jetty.alpn.ALPN Java Examples

The following examples show how to use org.eclipse.jetty.alpn.ALPN. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JettyAlpnProvider.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
static SSLEngine setProtocols(final SSLEngine engine, final String[] protocols) {
    if (engine.getUseClientMode()) {
        ALPN.put(engine, new ALPNClientSelectionProvider(Arrays.asList(protocols), engine));
    } else {
        ALPN.put(engine, new ALPN.ServerProvider() {
            @Override
            public void unsupported() {
                ALPN.remove(engine);
            }

            @Override
            public String select(List<String> strings) {
                ALPN.remove(engine);
                for (String p : protocols) {
                    if (strings.contains(p)) {
                        engine.getHandshakeSession().putValue(PROTOCOL_KEY, p);
                        return p;
                    }
                }
                return null;
            }
        });
    }
    return engine;
}
 
Example #2
Source File: JettyAlpnSslEngine.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
ClientEngine(SSLEngine engine, final JdkApplicationProtocolNegotiator applicationNegotiator) {
    super(engine);
    checkNotNull(applicationNegotiator, "applicationNegotiator");
    final ProtocolSelectionListener protocolListener = checkNotNull(applicationNegotiator
                    .protocolListenerFactory().newListener(this, applicationNegotiator.protocols()),
            "protocolListener");
    ALPN.put(engine, new ALPN.ClientProvider() {
        @Override
        public List<String> protocols() {
            return applicationNegotiator.protocols();
        }

        @Override
        public void selected(String protocol) throws SSLException {
            try {
                protocolListener.selected(protocol);
            } catch (Throwable t) {
                throw toSSLHandshakeException(t);
            }
        }

        @Override
        public void unsupported() {
            protocolListener.unsupported();
        }
    });
}
 
Example #3
Source File: JettyAlpnSslEngine.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public void closeInbound() throws SSLException {
    try {
        ALPN.remove(getWrappedEngine());
    } finally {
        super.closeInbound();
    }
}
 
Example #4
Source File: JettyAlpnSslEngine.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public void closeOutbound() {
    try {
        ALPN.remove(getWrappedEngine());
    } finally {
        super.closeOutbound();
    }
}
 
Example #5
Source File: JettyAlpnSslEngine.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public void closeInbound() throws SSLException {
    try {
        ALPN.remove(getWrappedEngine());
    } finally {
        super.closeInbound();
    }
}
 
Example #6
Source File: JettyAlpnSslEngine.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public void closeOutbound() {
    try {
        ALPN.remove(getWrappedEngine());
    } finally {
        super.closeOutbound();
    }
}
 
Example #7
Source File: ServerBuilder.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
public Server build() throws Exception {
    Server server = new Server();

    // Register servlets
    ServletContextHandler context = new ServletContextHandler(server, contextUrn, ServletContextHandler.SESSIONS);
    servletHandlers.forEach((uri, servletHolder) -> { context.addServlet(servletHolder, uri);});
    // Register servlet filters
    filters.forEach((urn, filterHolder) -> { context.addFilter(filterHolder, urn,
            EnumSet.of(DispatcherType.REQUEST)); });
    // Register EventListener instances
    sessionEventListeners.forEach( listener -> { context.getSessionHandler().addEventListener(listener); });

    // Register jersey rest services
    ServletContainer restServletContainer = new ServletContainer(resourceConfig);
    ServletHolder restServletHolder = new ServletHolder(restServletContainer);
    context.addServlet(restServletHolder, restUriPrefix);

    // Register static resources (html pages, images, javascripts, ...)
    String externalResource = this.getClass().getResource(staticResourceBasePath).toExternalForm();
    DefaultServlet defaultServlet = new DefaultServlet();
    ServletHolder holderPwd = new ServletHolder("default", defaultServlet);
    holderPwd.setInitParameter("resourceBase", externalResource);
    context.addServlet(holderPwd, staticResourceBaseUrn);

    server.setHandler(context);

    // HTTP Configuration
    HttpConfiguration httpConfig = new HttpConfiguration();
    httpConfig.setSecureScheme("https");
    httpConfig.setSecurePort(secureHttpPort);
    httpConfig.setSendXPoweredBy(true);
    httpConfig.setSendServerVersion(true);

    // HTTP Connector
    HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(httpConfig);
    HTTP2CServerConnectionFactory http2CServerConnectionFactory = new HTTP2CServerConnectionFactory(httpConfig);
    ServerConnector http = new ServerConnector(server, httpConnectionFactory, http2CServerConnectionFactory);
    http.setPort(httpPort);
    server.addConnector(http);

    // SSL Context Factory for HTTPS and HTTP/2
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setTrustStore(keyStore);
    sslContextFactory.setTrustStorePassword(keyStorePassword);
    sslContextFactory.setKeyStore(keyStore);
    sslContextFactory.setKeyStorePassword(keyStorePassword);
    sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);

    // HTTPS Configuration
    HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());

    // HTTP/2 Connection Factory
    ServerConnectionFactory h2 = new ServerConnectionFactory(httpsConfig, streamProcessors);

    //NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol(http.getDefaultProtocol());

    // SSL Connection Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());

    // HTTP/2 Connector
    ServerConnector http2Connector =
            new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(httpsConfig));
    http2Connector.setPort(secureHttpPort);
    server.addConnector(http2Connector);

    ALPN.debug=false;

    return server;
}
 
Example #8
Source File: JettyAlpnProvider.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void unsupported() {
    ALPN.remove(sslEngine);
    selected = "";
}
 
Example #9
Source File: JettyAlpnProvider.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void selected(String s) {
    ALPN.remove(sslEngine);
    selected = s;
    sslEngine.getHandshakeSession().putValue(PROTOCOL_KEY, selected);
}
 
Example #10
Source File: Http2Server.java    From http2-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String... args) throws Exception {
    Server server = new Server();

    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new Servlet()), "/");
    server.setHandler(context);

    // HTTP Configuration
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);

    // SSL Context Factory for HTTPS and HTTP/2
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStoreResource(newClassPathResource("keystore"));
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);

    // HTTPS Configuration
    HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());

    // HTTP/2 Connection Factory
    HTTP2ServerConnectionFactory h2 = new MyConnectionFactory(https_config);

    NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol("h2");

    // SSL Connection Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory,alpn.getProtocol());

    // HTTP/2 Connector
    ServerConnector http2Connector =
            new ServerConnector(server,ssl,alpn,h2,new HttpConnectionFactory(https_config));
    http2Connector.setPort(8443);
    server.addConnector(http2Connector);

    ALPN.debug=false;

    server.start();
    server.join();
}
 
Example #11
Source File: Http2EchoServer.java    From http2-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String... args) throws Exception
{
    Server server = new Server();

    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new PushEchoServlet()), "/");
    server.setHandler(context);

    // HTTP Configuration
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);

    // SSL Context Factory for HTTPS and HTTP/2
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStoreResource(newClassPathResource("keystore"));
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);

    // HTTPS Configuration
    HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());

    // HTTP/2 Connection Factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);

    NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol("h2");

    // SSL Connection Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory,alpn.getProtocol());

    // HTTP/2 Connector
    ServerConnector http2Connector =
            new ServerConnector(server,ssl,alpn,h2,new HttpConnectionFactory(https_config));
    http2Connector.setPort(8443);
    server.addConnector(http2Connector);

    ALPN.debug=false;

    server.start();
    server.join();
}
 
Example #12
Source File: Http2Server.java    From http2-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String... args) throws Exception {
    Server server = new Server();

    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new Servlet()), "/");
    server.setHandler(context);

    // HTTP Configuration
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);

    // SSL Context Factory for HTTPS and HTTP/2
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStoreResource(newClassPathResource("keystore"));
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);

    // HTTPS Configuration
    HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());

    // HTTP/2 Connection Factory
    HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
    NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
    ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    alpn.setDefaultProtocol("h2");

    // SSL Connection Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory,alpn.getProtocol());

    // HTTP/2 Connector
    ServerConnector http2Connector =
            new ServerConnector(server,ssl,alpn,h2,new HttpConnectionFactory(https_config));
    http2Connector.setPort(8443);
    server.addConnector(http2Connector);

    ALPN.debug=false;

    server.start();
    server.join();
}
 
Example #13
Source File: JdkAlpnSslEngine.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
public void closeInbound() throws SSLException {
    ALPN.remove(getWrappedEngine());
    super.closeInbound();
}
 
Example #14
Source File: JdkAlpnSslEngine.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
public void closeOutbound() {
    ALPN.remove(getWrappedEngine());
    super.closeOutbound();
}