如何使用org.jboss.resteasy.plugins.server.netty.NettyJaxrsServer启用https?

时间:2016-05-28 12:03:33

标签: java https netty resteasy sslcontext

当我尝试使用resteasy-netty4升级https服务器时遇到问题(http服务没问题)

----> resteasy版本3.0.16.Final,java版本1.8)

通过从stackoverflow和google搜索,我得到了一些解决方案,例如, Simple Java HTTPS server

YEAH,最初的演示已经成功运行,但不幸的是,在我与NettyJaxrsServer集成后它没有工作。

我创建了一个sslcontext,如下所示:

public SSLContext getSSLContext1() throws Exception {
    SSLContext sslContext = SSLContext.getInstance("TLS");

    // initialise the keystore
    char[] password = "password".toCharArray();
    KeyStore ks = KeyStore.getInstance("JKS");
    FileInputStream fis = new FileInputStream("{PARENT_PATH}\\testkey.jks");
    ks.load(fis, password);

    // setup the key manager factory
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(ks, password);

    // setup the trust manager factory
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
    tmf.init(ks);

    // setup the HTTPS context and parameters
    sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

    return SSLContext.getDefault();
}

并调用org.immortal.hydra.gateway.server.JaxrsGatewayServer #setSSLContext启用https服务器。

启动时没关系,但未能提供服务。

Caused by: javax.net.ssl.SSLHandshakeException: no cipher suites in common
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1666)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:304)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:292)
at sun.security.ssl.ServerHandshaker.chooseCipherSuite(ServerHandshaker.java:1036)
at sun.security.ssl.ServerHandshaker.clientHello(ServerHandshaker.java:739)
at sun.security.ssl.ServerHandshaker.processMessage(ServerHandshaker.java:221)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
at sun.security.ssl.Handshaker$1.run(Handshaker.java:919)
at sun.security.ssl.Handshaker$1.run(Handshaker.java:916)
at java.security.AccessController.doPrivileged(Native Method)
at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1369)
at io.netty.handler.ssl.SslHandler.runDelegatedTasks(SslHandler.java:1124)
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1009)

如果您有任何解决此问题的建议,请告知我们。?

1 个答案:

答案 0 :(得分:0)

看起来您正在设置SSL上下文,但随后返回默认值。尝试更改

return SSLContext.getDefault();

return sslContext;

通过启用SSL日志记录来学习如何调试ssl也很有用:http://docs.oracle.com/javase/7/docs/technotes/guides/security/jsse/ReadDebug.html