Vertx 3.6.3: невозможно запустить HTTPS-сервер с опцией PFX - PullRequest
0 голосов
/ 26 февраля 2019

Я использую Vertx 3.6.3.Я пытаюсь запустить HTTPS-серверную версию, но, к сожалению, она не развертывается.Не могли бы вы, пожалуйста, сообщить мне, где я делаю это неправильно?

Вот моя вертикаль:

HTTPSВетрика:

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.PfxOptions;

public class HTTPSVerticle extends AbstractVerticle {
    @Override
    public void start(Future<Void> httpsServerStarted) throws Exception {
        int port = config().getJsonObject("http", new JsonObject()).getInteger("port", 8000);
        boolean useSsl = config().getJsonObject("http", new JsonObject()).getBoolean("useSsl", false);
        String sslCertPath = config().getJsonObject("http", new JsonObject()).getString("sslCertPath", "");
        String sslCertPassword = config().getJsonObject("http", new JsonObject()).getString("sslCertPassword", "");

        HttpServerOptions httpServerOptions = new HttpServerOptions();

        System.out.println(useSsl);

        if (useSsl)
            httpServerOptions
                    .setSsl(true)
                    //.setClientAuth(ClientAuth.REQUIRED)
                    .setPfxTrustOptions(
                            new PfxOptions().setPath(sslCertPath).setPassword(sslCertPassword)
                    );

        vertx.createHttpServer(httpServerOptions).requestHandler(httpReq -> {
            httpReq.response().end("Hello encrypted world");
        }).listen(port, fut -> {
            if (fut.succeeded()) {
                System.out.println("Verticle now listening on port: " + port);
                httpsServerStarted.complete();
            }
            else {
                httpsServerStarted.fail(fut.cause());
                System.out.println("Error while starting HTTP server");
            }
        });
    }
}

Вот мойконтрольный пример:

TestHTTPSVerticle:

import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClientOptions;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(VertxUnitRunner.class)
public class TestHTTPSVerticle {
    private static Vertx vertx;

    @BeforeClass
    public static void setUp(TestContext context) {
        DeploymentOptions opts = new DeploymentOptions()
                .setConfig(new JsonObject().put("http", new JsonObject()
                        .put("useSsl", true)
                        .put("sslCertPath", "test.pfx")
                        .put("sslCertPassword", "abcd")));

        vertx = Vertx.vertx();
        vertx.deployVerticle(HTTPSVerticle.class.getName(), opts, context.asyncAssertSuccess());
    }

    @AfterClass
    public static void tearDown(TestContext context) {
        vertx.close(context.asyncAssertSuccess());
    }

    @Test
    public void testHttpsServerMessage(TestContext context) {
        Async async = context.async();

        System.out.println("Connecting to server...");

        vertx.createHttpClient().get(8000, "localhost", "/loremipsum", respHandler -> respHandler.bodyHandler(respBody -> {
            System.out.println(respBody);
            context.assertTrue(respBody.toString().equals("Hello encrypted world"));
            async.complete();
        })).end();
    }
}

Это не позволяет мне представить его без уточнения, поэтому следует избыточная разработка:

  1. IЯ использую механизм конфигурации vertx для получения port, useSsl, sslCertPath и sslCertPassword
  2. Я использую HttpServerOptions для настройки параметров SSL для http-сервера
  3. Когда серверуспешно запущен, он должен вывести Verticle now listening on port: 8000
  4. В случае, если сервер не запускается, он должен вывести Error while starting HTTP server

Но он никогда не вызывает обработчик прослушивания с AsyncResult.

...