Example usage for io.vertx.core.net SelfSignedCertificate keyCertOptions

List of usage examples for io.vertx.core.net SelfSignedCertificate keyCertOptions

Introduction

In this page you can find the example usage for io.vertx.core.net SelfSignedCertificate keyCertOptions.

Prototype

PemKeyCertOptions keyCertOptions();

Source Link

Document

Provides the KeyCertOptions RSA private key file in PEM format corresponding to the #privateKeyPath()

Usage

From source file:examples.NetExamples.java

License:Open Source License

public void example48(Vertx vertx) throws CertificateException {
    SelfSignedCertificate certificate = SelfSignedCertificate.create();

    NetServerOptions serverOptions = new NetServerOptions().setSsl(true)
            .setKeyCertOptions(certificate.keyCertOptions()).setTrustOptions(certificate.trustOptions());

    NetServer server = vertx.createNetServer(serverOptions)
            .connectHandler(socket -> socket.write("Hello!").end()).listen(1234, "localhost");

    NetClientOptions clientOptions = new NetClientOptions().setSsl(true)
            .setKeyCertOptions(certificate.keyCertOptions()).setTrustOptions(certificate.trustOptions());

    NetClient client = vertx.createNetClient(clientOptions);
    client.connect(1234, "localhost", ar -> {
        if (ar.succeeded()) {
            ar.result().handler(buffer -> System.out.println(buffer));
        } else {/*  w  w w .  ja va2  s .  c  om*/
            System.err.println("Woops: " + ar.cause().getMessage());
        }
    });
}

From source file:examples.NetExamples.java

License:Open Source License

public void example50(Vertx vertx) throws CertificateException {
    SelfSignedCertificate certificate = SelfSignedCertificate.create();

    vertx.createHttpServer(new HttpServerOptions().setSsl(true).setKeyCertOptions(certificate.keyCertOptions())
            .setTrustOptions(certificate.trustOptions())).requestHandler(req -> req.response().end("Hello!"))
            .listen(8080);/*from   w  w w. j a v a  2s  .co m*/
}