Java Grizzly 2嵌入式Https服务器?

Java Grizzly 2嵌入式Https服务器?,java,https,grizzly,Java,Https,Grizzly,我正在尝试运行一个简单的https嵌入式服务器。这是一个测试原型,所以真正的安全性在这一点上并不重要,伪造或省略证书也可以,但我的情况需要https与常规http 这段代码似乎调用了正确的API,它运行,但客户端浏览器得到“SSL连接错误”: 您是否尝试在服务器端启用ssl调试信息?-Djavax.net.debug=all查看以下答案: public class SimpleHttps { public static final String SERVER_NAME = "https:

我正在尝试运行一个简单的https嵌入式服务器。这是一个测试原型,所以真正的安全性在这一点上并不重要,伪造或省略证书也可以,但我的情况需要https与常规http

这段代码似乎调用了正确的API,它运行,但客户端浏览器得到“SSL连接错误”:


您是否尝试在服务器端启用ssl调试信息?-Djavax.net.debug=all查看以下答案:
public class SimpleHttps {
    public static final String SERVER_NAME = "https://localhost:8090";
    public static final URI BASE_URI = URI.create(SERVER_NAME);

    private static class TrustAllCerts implements X509TrustManager {
        @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { }
        @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { }
        @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
    }

    private final static TrustManager[] trustAllCerts = new TrustManager[] { new TrustAllCerts() };

    public static SSLEngineConfigurator getSslEngineConfig() throws KeyManagementException, NoSuchAlgorithmException {
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, trustAllCerts, new SecureRandom());
        SSLEngineConfigurator sslEngineConfigurator = new SSLEngineConfigurator(sc, false, false, false);
        return sslEngineConfigurator;
    }

    public static void main(String[] args) throws Exception {
        final ResourceConfig rc = new ResourceConfig().register(MyResource.class);
        HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, rc, true, getSslEngineConfig());

        System.in.read();

        httpServer.stop();
    }
}