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

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

Introduction

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

Prototype

static SelfSignedCertificate create() 

Source Link

Document

Create a new SelfSignedCertificate instance.

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  ww . j  av  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 w  w w.  ja  v a2s.c  o m
}