case "certPath": if (member.getValue() instanceof String) { obj.setCertPath((String)member.getValue());
@Override public PemKeyCertOptions keyCertOptions() { return new PemKeyCertOptions() .setKeyPath(privateKeyPath()) .setCertPath(certificatePath()); }
setUseAlpn(true). setSsl(true). setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("server-key.pem").setCertPath("server-cert.pem") ));
@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); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(new HttpServerOptions(). setUseAlpn(true). setSsl(true). setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("server-key.pem").setCertPath("server-cert.pem") )); server.requestHandler(req -> { req.response().putHeader("content-type", "text/html").end("<html><body>" + "<h1>Hello from vert.x!</h1>" + "<p>version = " + req.version() + "</p>" + "</body></html>"); }).listen(8443); } }
@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); } }
@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(new HttpServerOptions(). setUseAlpn(true). setSsl(true). setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("server-key.pem").setCertPath("server-cert.pem") )); server.requestHandler(req -> { HttpServerResponse resp = req.response(); req.customFrameHandler(frame -> { System.out.println("Received client frame " + frame.payload().toString("UTF-8")); // Write the sam resp.writeCustomFrame(10, 0, Buffer.buffer("pong")); }); }).listen(8443); } }
@Test public void testKeyCertInvalidCertPath() { testInvalidKeyStore(Cert.SERVER_PEM.get().setCertPath("/invalid.pem"), "java.nio.file.NoSuchFileException: ", "invalid.pem"); }
@Test public void testKeyCertMissingCertPath() { testInvalidKeyStore(Cert.SERVER_PEM.get().setCertPath(null), "Missing X.509 certificate", null); }
.setPemKeyCertOptions(new PemKeyCertOptions() .setKeyPath("server-key.pem") .setCertPath("server-cert.pem")) .setSsl(true);
@Override public void start() throws Exception { final Image image = new Image(vertx, "coin.png"); Router router = Router.router(vertx); router.get("/").handler(ctx -> { ctx.response() .putHeader("Content-Type", "text/html") .end(image.generateHTML(16)); }); router.get("/img/:x/:y").handler(ctx -> { ctx.response() .putHeader("Content-Type", "image/png") .end(image.getPixel(Integer.parseInt(ctx.pathParam("x")), Integer.parseInt(ctx.pathParam("y")))); }); vertx.createHttpServer( new HttpServerOptions() .setSsl(true) .setUseAlpn(true) .setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("tls/server-key.pem").setCertPath("tls/server-cert.pem"))).requestHandler(router) .listen(8443); } }
options.setKeyPath(keyPath1); options.setKeyValue(keyValue1); options.setCertPath(certPath1); options.setCertValue(certValue1); options = new PemKeyCertOptions(options);
@Test public void testKeyCertOptions() throws Exception { PemKeyCertOptions options = new PemKeyCertOptions(); assertNull(options.getKeyPath()); String randString = TestUtils.randomAlphaString(100); assertEquals(options, options.setKeyPath(randString)); assertEquals(randString, options.getKeyPath()); assertNull(options.getCertPath()); randString = TestUtils.randomAlphaString(100); assertEquals(options, options.setCertPath(randString)); assertEquals(randString, options.getCertPath()); }
@Override public PemKeyCertOptions keyCertOptions() { return new PemKeyCertOptions() .setKeyPath(privateKeyPath()) .setCertPath(certificatePath()); }
@Test public void testKeyCertInvalidCertPath() { testInvalidKeyStore(Cert.SERVER_PEM.get().setCertPath("/invalid.pem"), "java.nio.file.NoSuchFileException: ", "invalid.pem"); }
@Test public void testKeyCertMissingCertPath() { testInvalidKeyStore(Cert.SERVER_PEM.get().setCertPath(null), "Missing X.509 certificate", null); }
.setUseAlpn(true) .setSsl(true) .setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("tls/server-key.pem").setCertPath("tls/server-cert.pem"))); http2Server.requestHandler(router).listen(8443);
options.setKeyPath(keyPath1); options.setKeyValue(keyValue1); options.setCertPath(certPath1); options.setCertValue(certValue1); options = new PemKeyCertOptions(options);
@Test public void testKeyCertOptions() throws Exception { PemKeyCertOptions options = new PemKeyCertOptions(); assertNull(options.getKeyPath()); String randString = TestUtils.randomAlphaString(100); assertEquals(options, options.setKeyPath(randString)); assertEquals(randString, options.getKeyPath()); assertNull(options.getCertPath()); randString = TestUtils.randomAlphaString(100); assertEquals(options, options.setCertPath(randString)); assertEquals(randString, options.getCertPath()); }
@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", onSuccess(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(); }