Search in sources :

Example 16 with PemKeyCertOptions

use of io.vertx.core.net.PemKeyCertOptions in project vertx-examples by vert-x3.

the class Server method start.

@Override
public void start() throws Exception {
    HttpServer server = vertx.createHttpServer(new HttpServerOptions().setSsl(true).setUseAlpn(true).setPemKeyCertOptions(new PemKeyCertOptions().setCertPath("server-cert.pem").setKeyPath("server-key.pem")));
    server.requestHandler(req -> {
        req.response().putHeader("content-type", "text/html").end("Hello using HTTP " + req.version());
    });
    server.listen(8443);
}
Also used : PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions)

Example 17 with PemKeyCertOptions

use of io.vertx.core.net.PemKeyCertOptions in project vertx-web by vert-x3.

the class StaticHandlerTest method testNoHttp2Push.

@Test
public void testNoHttp2Push() throws Exception {
    stat.setWebRoot("webroot/somedir3");
    router.route().handler(stat);
    HttpServer http2Server = vertx.createHttpServer(new HttpServerOptions().setUseAlpn(true).setSsl(true).setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("tls/server-key.pem").setCertPath("tls/server-cert.pem")));
    http2Server.requestHandler(router).listen(8443);
    HttpClientOptions options = new HttpClientOptions().setSsl(true).setUseAlpn(true).setProtocolVersion(HttpVersion.HTTP_2).setPemTrustOptions(new PemTrustOptions().addCertPath("tls/server-cert.pem"));
    HttpClient client = vertx.createHttpClient(options);
    HttpClientRequest request = client.get(8443, "localhost", "/testLinkPreload.html", resp -> {
        assertEquals(200, resp.statusCode());
        assertEquals(HttpVersion.HTTP_2, resp.version());
        resp.bodyHandler(this::assertNotNull);
        testComplete();
    });
    request.pushHandler(pushedReq -> pushedReq.handler(pushedResp -> {
        fail();
    }));
    request.end();
    await();
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) HttpServer(io.vertx.core.http.HttpServer) Router(io.vertx.ext.web.Router) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Utils(io.vertx.ext.web.impl.Utils) HttpVersion(io.vertx.core.http.HttpVersion) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) PemTrustOptions(io.vertx.core.net.PemTrustOptions) WebTestBase(io.vertx.ext.web.WebTestBase) DateFormat(java.text.DateFormat) Set(java.util.Set) Test(org.junit.Test) File(java.io.File) JsonArray(io.vertx.core.json.JsonArray) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Http2PushMapping(io.vertx.ext.web.Http2PushMapping) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClient(io.vertx.core.http.HttpClient) HttpClientRequest(io.vertx.core.http.HttpClientRequest) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) HttpClient(io.vertx.core.http.HttpClient) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) PemTrustOptions(io.vertx.core.net.PemTrustOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 18 with PemKeyCertOptions

use of io.vertx.core.net.PemKeyCertOptions in project vertx-web by vert-x3.

the class StaticHandlerTest method testHttp2Push.

@Test
public void testHttp2Push() throws Exception {
    List<Http2PushMapping> mappings = new ArrayList<>();
    mappings.add(new Http2PushMapping("style.css", "style", false));
    mappings.add(new Http2PushMapping("coin.png", "image", false));
    stat.setHttp2PushMapping(mappings).setWebRoot("webroot/somedir3");
    router.route().handler(stat);
    HttpServer http2Server = vertx.createHttpServer(new HttpServerOptions().setUseAlpn(true).setSsl(true).setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("tls/server-key.pem").setCertPath("tls/server-cert.pem")));
    http2Server.requestHandler(router).listen(8443);
    HttpClientOptions options = new HttpClientOptions().setSsl(true).setUseAlpn(true).setProtocolVersion(HttpVersion.HTTP_2).setPemTrustOptions(new PemTrustOptions().addCertPath("tls/server-cert.pem"));
    HttpClient client = vertx.createHttpClient(options);
    HttpClientRequest request = client.get(8443, "localhost", "/testLinkPreload.html", resp -> {
        assertEquals(200, resp.statusCode());
        assertEquals(HttpVersion.HTTP_2, resp.version());
        resp.bodyHandler(this::assertNotNull);
    });
    CountDownLatch latch = new CountDownLatch(2);
    request.pushHandler(pushedReq -> pushedReq.handler(pushedResp -> {
        assertNotNull(pushedResp);
        pushedResp.bodyHandler(this::assertNotNull);
        latch.countDown();
    }));
    request.end();
    latch.await();
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) HttpServer(io.vertx.core.http.HttpServer) Router(io.vertx.ext.web.Router) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Utils(io.vertx.ext.web.impl.Utils) HttpVersion(io.vertx.core.http.HttpVersion) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) PemTrustOptions(io.vertx.core.net.PemTrustOptions) WebTestBase(io.vertx.ext.web.WebTestBase) DateFormat(java.text.DateFormat) Set(java.util.Set) Test(org.junit.Test) File(java.io.File) JsonArray(io.vertx.core.json.JsonArray) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Http2PushMapping(io.vertx.ext.web.Http2PushMapping) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClient(io.vertx.core.http.HttpClient) HttpClientRequest(io.vertx.core.http.HttpClientRequest) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) Http2PushMapping(io.vertx.ext.web.Http2PushMapping) HttpClient(io.vertx.core.http.HttpClient) ArrayList(java.util.ArrayList) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) CountDownLatch(java.util.concurrent.CountDownLatch) PemTrustOptions(io.vertx.core.net.PemTrustOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 19 with PemKeyCertOptions

use of io.vertx.core.net.PemKeyCertOptions in project vertx-openshift-it by cescoffier.

the class MqttBroker method start.

@Override
public void start() {
    MqttServerOptions options = new MqttServerOptions().setKeyCertOptions(new PemKeyCertOptions().setKeyPath("private.pem").setCertPath("public.pem")).setSsl(true).setPort(8883);
    MqttServer.create(vertx, options).endpointHandler(this::configureEndpoint).listen(start -> {
        if (start.succeeded()) {
            System.out.println("MQTT secured server is listening on port " + start.result().actualPort());
        } else {
            System.out.println("Error on starting the secured server");
            start.cause().printStackTrace();
        }
    });
    MqttServer.create(vertx).endpointHandler(this::configureEndpoint).listen(start -> {
        if (start.succeeded()) {
            System.out.println("MQTT insecure server is listening on port " + start.result().actualPort());
        } else {
            System.out.println("Error on starting the insecure server");
            start.cause().printStackTrace();
        }
    });
    // Just for healthcheck purposes
    Router router = Router.router(vertx);
    router.get("/").handler(this::healthcheck);
    vertx.createHttpServer().requestHandler(router::accept).listen(8080);
}
Also used : PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) MqttServerOptions(io.vertx.mqtt.MqttServerOptions) Router(io.vertx.ext.web.Router)

Example 20 with PemKeyCertOptions

use of io.vertx.core.net.PemKeyCertOptions in project georocket by georocket.

the class GeoRocket method createHttpServerOptions.

/**
 * Create an {@link HttpServerOptions} object and modify it according to the
 * configuration. Sub-classes may override this method to further modify the
 * object.
 * @return the created {@link HttpServerOptions}
 */
protected HttpServerOptions createHttpServerOptions() {
    boolean compress = config().getBoolean(ConfigConstants.HTTP_COMPRESS, true);
    HttpServerOptions serverOptions = new HttpServerOptions().setCompressionSupported(compress);
    boolean ssl = config().getBoolean(ConfigConstants.HTTP_SSL, false);
    if (ssl) {
        serverOptions.setSsl(ssl);
        String certPath = config().getString(ConfigConstants.HTTP_CERT_PATH, null);
        String keyPath = config().getString(ConfigConstants.HTTP_KEY_PATH, null);
        PemKeyCertOptions pemKeyCertOptions = new PemKeyCertOptions().setCertPath(certPath).setKeyPath(keyPath);
        serverOptions.setPemKeyCertOptions(pemKeyCertOptions);
    }
    boolean alpn = config().getBoolean(ConfigConstants.HTTP_ALPN, false);
    if (alpn) {
        if (!ssl) {
            log.warn("ALPN is enabled but SSL is not! In order for ALPN to work " + "correctly, SSL is required.");
        }
        serverOptions.setUseAlpn(alpn);
    }
    return serverOptions;
}
Also used : PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) HttpServerOptions(io.vertx.core.http.HttpServerOptions)

Aggregations

PemKeyCertOptions (io.vertx.core.net.PemKeyCertOptions)22 Test (org.junit.Test)10 HttpServerOptions (io.vertx.core.http.HttpServerOptions)9 HttpServer (io.vertx.core.http.HttpServer)7 AbstractVerticle (io.vertx.core.AbstractVerticle)4 Buffer (io.vertx.core.buffer.Buffer)4 PfxOptions (io.vertx.core.net.PfxOptions)4 Router (io.vertx.ext.web.Router)4 HttpServerResponse (io.vertx.core.http.HttpServerResponse)3 JsonObject (io.vertx.core.json.JsonObject)3 JksOptions (io.vertx.core.net.JksOptions)3 HttpClient (io.vertx.core.http.HttpClient)2 HttpClientOptions (io.vertx.core.http.HttpClientOptions)2 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 HttpMethod (io.vertx.core.http.HttpMethod)2 HttpVersion (io.vertx.core.http.HttpVersion)2 JsonArray (io.vertx.core.json.JsonArray)2 OpenSSLEngineOptions (io.vertx.core.net.OpenSSLEngineOptions)2 PemTrustOptions (io.vertx.core.net.PemTrustOptions)2 KeyStoreHelper (io.vertx.core.net.impl.KeyStoreHelper)2