Search in sources :

Example 26 with HttpServer

use of io.vertx.core.http.HttpServer in project vertx-openshift-it by cescoffier.

the class SenderVerticle method startHttpServer.

private Future<HttpServer> startHttpServer() {
    Future<HttpServer> future = Future.future();
    Router router = setupRouter();
    vertx.createHttpServer().requestHandler(router::accept).listen(8080, future);
    return future;
}
Also used : HttpServer(io.vertx.core.http.HttpServer) Router(io.vertx.ext.web.Router)

Example 27 with HttpServer

use of io.vertx.core.http.HttpServer in project vertx-openshift-it by cescoffier.

the class EdgeVerticle method start.

@Override
public void start() throws Exception {
    client = WebClient.create(vertx, new WebClientOptions().setProtocolVersion(HttpVersion.HTTP_2).setSsl(true).setUseAlpn(true).setTrustAll(true));
    Router router = Router.router(vertx);
    router.get("/").handler(this::hello);
    router.get("/health").handler(rc -> rc.response().end("OK"));
    router.get("/aloha").handler(this::front);
    router.get("/hello").handler(this::grpc);
    HttpServer server = vertx.createHttpServer(new HttpServerOptions());
    server.requestHandler(router::accept).listen(8080);
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Router(io.vertx.ext.web.Router)

Example 28 with HttpServer

use of io.vertx.core.http.HttpServer in project vertx-openshift-it by cescoffier.

the class HelloHttp2Verticle method start.

@Override
public void start() throws Exception {
    vertx.exceptionHandler(Throwable::printStackTrace);
    HttpServer server = vertx.createHttpServer(new HttpServerOptions().setUseAlpn(true).setSsl(true).setPemKeyCertOptions(new PemKeyCertOptions().setKeyPath("server-key.pem").setCertPath("server-cert.pem")));
    server.requestHandler(req -> {
        System.out.println("Handling request on Aloha " + req.version());
        req.response().putHeader("content-type", "text/html").end("<html><body>" + "<h1>Aloha from vert.x!</h1>" + "<p>version = " + req.version() + "</p>" + "</body></html>");
    }).listen(8081);
}
Also used : PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) AbstractVerticle(io.vertx.core.AbstractVerticle) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions)

Example 29 with HttpServer

use of io.vertx.core.http.HttpServer in project vert.x by eclipse.

the class SimpleServer method start.

@Override
public void start(Promise<Void> startPromise) throws Exception {
    HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
    server.requestHandler(req -> req.response().end());
    server.listen(res -> {
        if (res.succeeded()) {
            startPromise.complete();
        } else {
            startPromise.fail(res.cause());
        }
    });
}
Also used : HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions)

Example 30 with HttpServer

use of io.vertx.core.http.HttpServer in project vert.x by eclipse.

the class HttpConnectionEarlyResetTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    CountDownLatch listenLatch = new CountDownLatch(1);
    Context ctx = vertx.getOrCreateContext();
    httpServer = vertx.createHttpServer().requestHandler(request -> {
    }).exceptionHandler(t -> {
        assertSame(ctx, Vertx.currentContext());
        caught.set(t);
        resetLatch.countDown();
    });
    ctx.runOnContext(v -> {
        httpServer.listen(8080, onSuccess(server -> listenLatch.countDown()));
    });
    awaitLatch(listenLatch);
}
Also used : Context(io.vertx.core.Context) HttpServerImpl(io.vertx.core.http.impl.HttpServerImpl) CountDownLatch(java.util.concurrent.CountDownLatch) CoreMatchers(org.hamcrest.CoreMatchers) HttpServer(io.vertx.core.http.HttpServer) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) IOException(java.io.IOException) Context(io.vertx.core.Context) VertxTestBase(io.vertx.test.core.VertxTestBase) AtomicReference(java.util.concurrent.atomic.AtomicReference) NetClientOptions(io.vertx.core.net.NetClientOptions) NetSocket(io.vertx.core.net.NetSocket) CountDownLatch(java.util.concurrent.CountDownLatch)

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