【发布时间】:2019-08-21 12:07:22
【问题描述】:
我已经在vert.x创建了HTTPS服务器。
vertx.createHttpServer(
new HttpServerOptions()
.setSsl(true)
.setKeyStoreOptions(new JksOptions()
.setPath("path/to/keystore")
.setPassword("password")
)
).requestHandler( (HttpServerRequest req) -> {
System.out.println("Access.");
req.response().putHeader("Content-Type", "text/html; charset=utf-8");
req.response().end("Hello world!");
// ...
}).listen(80, "localhost");
我已经使用keytool 创建了密钥库。
keytool -genkeypair -keystore keystore -storetype jks
我已经成功部署了verticle。但是服务器没有响应。
对https://localhost 的访问没有任何作用。连日志都没有打印出来。
怎么了?
我已经尝试了以下一些选项。
vertx.createHttpServer(
new HttpServerOptions()
.setSsl(true)
.setKeyStoreOptions(new JksOptions()
.setPath("path/to/keystore")
.setPassword("password")
)
// .setUseAlpn(true)
// .setTrustOptions(new JksOptions()
// .setPath("C:/Recoeve/keystore")
// .setPassword("Xs41Kipid$ps15")
// )
// .setClientAuthRequired(false)
// .setClientAuth(ClientAuth.NONE)
// .addEnabledSecureTransportProtocol(TCPSSLOptions.DEFAULT_ENABLED_SECURE_TRANSPORT_PROTOCOLS.get(1))
// .addEnabledSecureTransportProtocol("TLSv1.3")
// .setEnabledSecureTransportProtocols(TCPSSLOptions.DEFAULT_ENABLED_SECURE_TRANSPORT_PROTOCOLS)
).requestHandler( (HttpServerRequest req) -> {
// ...
}).listen(80, "localhost");
但是代码给出了运行时异常。
【问题讨论】:
-
尝试使用
setLogActivity(true)并使用日志库查看调试日志。 -
您希望将日志打印到哪里? “什么都不给”到底是什么意思?提供的源代码不应作为对 SSL/TLS 请求的响应。
-
@metaphori setLogActivity(true) 给出了这个错误。 null:警告:在类型“io.vertx.codegen.annotations.VertxGen”中找不到注释方法“concrete()”:找不到 io.vertx.codegen.annotations.VertxGen 的类文件 C:\Recoeve\Recoeve.java: 58:错误:找不到符号 .setLogActivity(true) ^ 符号:方法 setLogActivity(boolean) 位置:类 io.vertx.core.http.HttpServerOptions
-
@tmarwen 如果没有 SSL/TLS 设置,此代码可以很好地响应浏览器的 localhost 访问。但是使用 SSL/TLS 设置,它什么也没有。连
System.out.println("Access.")都没有打印出来。 -
如果服务器提供 https/ssl 它也应该监听端口 443。使用 https 地址时,Web 浏览器访问服务器端口 443。或者您是否尝试过访问
https://localhost:80?
标签: java ssl https tls1.2 vert.x