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);
}
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();
}
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();
}
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);
}
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;
}
Aggregations