Search in sources :

Example 11 with HttpServer

use of io.vertx.core.http.HttpServer in project vertx-examples by vert-x3.

the class Server method start.

@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);
}
Also used : OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) AbstractVerticle(io.vertx.core.AbstractVerticle) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Runner(io.vertx.example.util.Runner) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions)

Example 12 with HttpServer

use of io.vertx.core.http.HttpServer in project vertx-examples by vert-x3.

the class Server method start.

@Override
public void start(Future<Void> startFuture) throws Exception {
    HttpServer server = vertx.createHttpServer(new HttpServerOptions().setUseAlpn(true).setKeyCertOptions(new JksOptions().setPath("io/vertx/example/java9/server-keystore.jks").setPassword("wibble")).setSsl(true));
    server.requestHandler(req -> {
        req.response().end("Hello " + req.version());
    }).listen(8080, ar -> startFuture.handle(ar.mapEmpty()));
}
Also used : AbstractVerticle(io.vertx.core.AbstractVerticle) HttpServer(io.vertx.core.http.HttpServer) JksOptions(io.vertx.core.net.JksOptions) Vertx(io.vertx.core.Vertx) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Future(io.vertx.core.Future) JksOptions(io.vertx.core.net.JksOptions) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions)

Example 13 with HttpServer

use of io.vertx.core.http.HttpServer 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).setKeyStoreOptions(new JksOptions().setPath("server-keystore.jks").setPassword("wibble")));
    server.requestHandler(req -> {
        req.response().putHeader("content-type", "text/html").end("<html><body><h1>Hello from vert.x!</h1></body></html>");
    }).listen(4443);
}
Also used : AbstractVerticle(io.vertx.core.AbstractVerticle) HttpServer(io.vertx.core.http.HttpServer) JksOptions(io.vertx.core.net.JksOptions) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Runner(io.vertx.example.util.Runner) JksOptions(io.vertx.core.net.JksOptions) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions)

Example 14 with HttpServer

use of io.vertx.core.http.HttpServer in project vertx-examples by vert-x3.

the class ParameterizedTest method test.

@Test
public void test(TestContext context) {
    HttpServer server = vertx.createHttpServer().requestHandler(req -> {
        context.assertEquals(port, req.localAddress().port());
        req.response().end();
    });
    server.listen(port, "localhost", context.asyncAssertSuccess(s -> {
        HttpClient client = vertx.createHttpClient();
        Async async = context.async();
        HttpClientRequest req = client.get(port, "localhost", "/", resp -> {
            context.assertEquals(200, resp.statusCode());
            async.complete();
        });
        req.exceptionHandler(context::fail);
        req.end();
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) HttpServer(io.vertx.core.http.HttpServer) Vertx(io.vertx.core.Vertx) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) VertxUnitRunnerWithParametersFactory(io.vertx.ext.unit.junit.VertxUnitRunnerWithParametersFactory) HttpClientRequest(io.vertx.core.http.HttpClientRequest) After(org.junit.After) Parameterized(org.junit.runners.Parameterized) HttpClient(io.vertx.core.http.HttpClient) Before(org.junit.Before) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Async(io.vertx.ext.unit.Async) HttpClient(io.vertx.core.http.HttpClient) HttpServer(io.vertx.core.http.HttpServer) Test(org.junit.Test)

Example 15 with HttpServer

use of io.vertx.core.http.HttpServer in project incubator-servicecomb-java-chassis by apache.

the class MockForRestServerVerticle method mockRestServerVerticle.

public void mockRestServerVerticle() {
    final HttpServer server = Mockito.mock(HttpServer.class);
    new MockUp<RestServerVerticle>() {

        @Mock
        private void startListen(HttpServer server, IpPort ipPort, Future<Void> startFuture) {
        }

        @Mock
        private HttpServer createHttpServer(boolean isHttp_2) {
            return server;
        }
    };
}
Also used : HttpServer(io.vertx.core.http.HttpServer) Future(io.vertx.core.Future) MockUp(mockit.MockUp) IpPort(org.apache.servicecomb.foundation.common.net.IpPort)

Aggregations

HttpServer (io.vertx.core.http.HttpServer)81 Router (io.vertx.ext.web.Router)37 HttpServerOptions (io.vertx.core.http.HttpServerOptions)33 Test (org.junit.Test)22 JsonObject (io.vertx.core.json.JsonObject)17 HttpClient (io.vertx.core.http.HttpClient)13 Future (io.vertx.core.Future)12 Vertx (io.vertx.core.Vertx)12 HttpServerResponse (io.vertx.core.http.HttpServerResponse)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 Buffer (io.vertx.core.buffer.Buffer)11 HttpMethod (io.vertx.core.http.HttpMethod)10 Handler (io.vertx.core.Handler)9 VertxOptions (io.vertx.core.VertxOptions)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 HttpClientOptions (io.vertx.core.http.HttpClientOptions)8 List (java.util.List)8 AbstractVerticle (io.vertx.core.AbstractVerticle)7 File (java.io.File)7 AsyncResult (io.vertx.core.AsyncResult)6