如何使用 vertx 连接 http 服务器 websocket 和 ssl?

How to connect http server websocket with ssl using vertx?

我创建了两个 类 服务器和客户端。以 ssl 开头的服务器如下

HttpServer server =
  vertx.createHttpServer(new HttpServerOptions().setSsl(true).setKeyStoreOptions(
    new JksOptions().setPath("server-keystore.jks").setPassword("wibble")
  ));

还有一位客户

vertx.createHttpClient(new HttpClientOptions().setSsl(true)).getNow(4443, "localhost", "/", resp -> {
      System.out.println("Got response " + resp.statusCode());
      resp.bodyHandler(body -> System.out.println("Got data " + body.toString("ISO-8859-1")));
    });

虽然 运行 在客户端我得到 "Failed to create SSL connection"。有没有办法配置任何与ssl相关的东西?

To enable ssl in vertx you can use keystore.jks file

然后使用以下配置:

HttpServerOptions secureOptions = new HttpServerOptions();
    if (Configuration.SSL_enabled) {
        LOG.debug("Secure Transport Protocol [ SSL/TLS ] has been enabled !!! ");
        secureOptions.setSsl(true)
                .setKeyStoreOptions(new JksOptions().setPath(Configuration.SSL_filename)
                        .setPassword(Configuration.SSL_password))
                .setTrustStoreOptions(new JksOptions().setPath(Configuration.SSL_filename)
                        .setPassword(Configuration.SSL_password))
                .addEnabledSecureTransportProtocol(Constants.TLS_VERSION_1)
                .addEnabledSecureTransportProtocol(Constants.TLS_VERSION_2);

    }

   vertx.createHttpServer(secureOptions).requestHandler(router::accept).listen(Configuration.port);

I hope this will help you :)