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

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

Introduction

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

Prototype

PemTrustOptions trustOptions();

Source Link

Document

Provides the TrustOptions X.509 certificate file in PEM format corresponding to the #certificatePath()

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 {/*from   w  w w .  jav a 2  s .c  o  m*/
            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  ww  w  .ja  v  a  2s  . c om
}