diff --git a/vertx/src/main/java/com/baeldung/HelloVerticle.java b/vertx/src/main/java/com/baeldung/HelloVerticle.java index 98d1b336a3..59baceb0d8 100644 --- a/vertx/src/main/java/com/baeldung/HelloVerticle.java +++ b/vertx/src/main/java/com/baeldung/HelloVerticle.java @@ -10,6 +10,11 @@ import io.vertx.core.Vertx; public class HelloVerticle extends AbstractVerticle { private static final Logger LOGGER = LoggerFactory.getLogger(HelloVerticle.class); + public static void main(String[] args) { + Vertx vertx = Vertx.vertx(); + vertx.deployVerticle(new HelloVerticle()); + } + @Override public void start(Future future) { LOGGER.info("Welcome to Vertx"); @@ -19,10 +24,5 @@ public class HelloVerticle extends AbstractVerticle { public void stop() { LOGGER.info("Shutting down application"); } - - public static void main(String[] args) { - Vertx vertx = Vertx.vertx(); - vertx.deployVerticle(new HelloVerticle()); - } } diff --git a/vertx/src/main/java/com/baeldung/SimpleServerVerticle.java b/vertx/src/main/java/com/baeldung/SimpleServerVerticle.java index 2cee37903b..6b56896860 100644 --- a/vertx/src/main/java/com/baeldung/SimpleServerVerticle.java +++ b/vertx/src/main/java/com/baeldung/SimpleServerVerticle.java @@ -4,21 +4,21 @@ import io.vertx.core.AbstractVerticle; import io.vertx.core.Future; public class SimpleServerVerticle extends AbstractVerticle { - + @Override public void start(Future future) { vertx.createHttpServer() - .requestHandler(request -> { - request.response() - .end("Welcome to Vert.x Intro"); - }) - .listen(config().getInteger("http.port", 8080), result -> { - if (result.succeeded()) { - future.complete(); - } else { - future.fail(result.cause()); - } - }); + .requestHandler(request -> { + request.response() + .end("Welcome to Vert.x Intro"); + }) + .listen(config().getInteger("http.port", 8080), result -> { + if (result.succeeded()) { + future.complete(); + } else { + future.fail(result.cause()); + } + }); } } diff --git a/vertx/src/main/java/com/baledung/rest/RestServiceVerticle.java b/vertx/src/main/java/com/baledung/rest/RestServiceVerticle.java index 181b3007d5..802f74942e 100644 --- a/vertx/src/main/java/com/baledung/rest/RestServiceVerticle.java +++ b/vertx/src/main/java/com/baledung/rest/RestServiceVerticle.java @@ -14,28 +14,28 @@ public class RestServiceVerticle extends AbstractVerticle { Router router = Router.router(vertx); router.get("/api/baeldung/articles/article/:id") - .handler(this::getArticles); + .handler(this::getArticles); vertx.createHttpServer() - .requestHandler(router::accept) - .listen(config().getInteger("http.port", 8080), result -> { - if (result.succeeded()) { - future.complete(); - } else { - future.fail(result.cause()); - } - }); + .requestHandler(router::accept) + .listen(config().getInteger("http.port", 8080), result -> { + if (result.succeeded()) { + future.complete(); + } else { + future.fail(result.cause()); + } + }); } private void getArticles(RoutingContext routingContext) { String articleId = routingContext.request() - .getParam("id"); + .getParam("id"); Article article = new Article(articleId, "This is an intro to vertx", "baeldung", "01-02-2017", 1578); routingContext.response() - .putHeader("content-type", "application/json") - .setStatusCode(200) - .end(Json.encodePrettily(article)); + .putHeader("content-type", "application/json") + .setStatusCode(200) + .end(Json.encodePrettily(article)); } } diff --git a/vertx/src/test/java/com/baeldung/RestServiceVerticleTest.java b/vertx/src/test/java/com/baeldung/RestServiceVerticleTest.java index 8eebe1396d..b5be0734f4 100644 --- a/vertx/src/test/java/com/baeldung/RestServiceVerticleTest.java +++ b/vertx/src/test/java/com/baeldung/RestServiceVerticleTest.java @@ -34,13 +34,13 @@ public class RestServiceVerticleTest { final Async async = testContext.async(); vertx.createHttpClient() - .getNow(8080, "localhost", "/api/baeldung/articles/article/12345", response -> { - response.handler(responseBody -> { - testContext.assertTrue(responseBody.toString() - .contains("\"id\" : \"12345\"")); - async.complete(); + .getNow(8080, "localhost", "/api/baeldung/articles/article/12345", response -> { + response.handler(responseBody -> { + testContext.assertTrue(responseBody.toString() + .contains("\"id\" : \"12345\"")); + async.complete(); + }); }); - }); } } diff --git a/vertx/src/test/java/com/baeldung/SimpleServerVerticleTest.java b/vertx/src/test/java/com/baeldung/SimpleServerVerticleTest.java index 177f8d8435..189d2f6604 100644 --- a/vertx/src/test/java/com/baeldung/SimpleServerVerticleTest.java +++ b/vertx/src/test/java/com/baeldung/SimpleServerVerticleTest.java @@ -20,8 +20,8 @@ public class SimpleServerVerticleTest { public void setup(TestContext testContext) { vertx = Vertx.vertx(); - vertx.deployVerticle(SimpleServerVerticle.class.getName(), - testContext.asyncAssertSuccess()); + vertx.deployVerticle(SimpleServerVerticle.class.getName(), + testContext.asyncAssertSuccess()); } @After @@ -34,13 +34,13 @@ public class SimpleServerVerticleTest { final Async async = testContext.async(); vertx.createHttpClient() - .getNow(8080, "localhost", "/", response -> { - response.handler(responseBody -> { - testContext.assertTrue(responseBody.toString() - .contains("Welcome")); - async.complete(); + .getNow(8080, "localhost", "/", response -> { + response.handler(responseBody -> { + testContext.assertTrue(responseBody.toString() + .contains("Welcome")); + async.complete(); + }); }); - }); } }