[Java 11503] (#12626)
* [JAVA-11503] Created new vertx-modules * [JAVA-11503] Moved vertx(sub-module) to vertx-modules(parent) * [JAVA-11503] Moved spring-vertx(sub-module) to vertx-modules(parent) * [JAVA-11503] Moved vertx-and-java(sub-module) to vertx-modules(parent) * [JAVA-11503] deleted modules that were moved Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.core.Future;
|
||||
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<Void> future) {
|
||||
LOGGER.info("Welcome to Vertx");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
LOGGER.info("Shutting down application");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung;
|
||||
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.core.Future;
|
||||
|
||||
public class SimpleServerVerticle extends AbstractVerticle {
|
||||
|
||||
@Override
|
||||
public void start(Future<Void> future) {
|
||||
vertx.createHttpServer()
|
||||
.requestHandler(
|
||||
r -> r.response().end("Welcome to Vert.x Intro"))
|
||||
.listen(config().getInteger("http.port", 8080), result -> {
|
||||
if (result.succeeded()) {
|
||||
future.complete();
|
||||
} else {
|
||||
future.fail(result.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.baeldung.model;
|
||||
|
||||
public class Article {
|
||||
private String id;
|
||||
private String content;
|
||||
private String author;
|
||||
private String datePublished;
|
||||
private int wordCount;
|
||||
|
||||
public Article(String id, String content, String author, String datePublished, int wordCount) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
this.author = author;
|
||||
this.datePublished = datePublished;
|
||||
this.wordCount = wordCount;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getDatePublished() {
|
||||
return datePublished;
|
||||
}
|
||||
|
||||
public void setDatePublished(String datePublished) {
|
||||
this.datePublished = datePublished;
|
||||
}
|
||||
|
||||
public int getWordCount() {
|
||||
return wordCount;
|
||||
}
|
||||
|
||||
public void setWordCount(int wordCount) {
|
||||
this.wordCount = wordCount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.baeldung.rest;
|
||||
|
||||
import com.baeldung.model.Article;
|
||||
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.json.Json;
|
||||
import io.vertx.ext.web.Router;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
|
||||
public class RestServiceVerticle extends AbstractVerticle {
|
||||
@Override
|
||||
public void start(Future<Void> future) {
|
||||
|
||||
Router router = Router.router(vertx);
|
||||
router.get("/api/baeldung/articles/article/:id")
|
||||
.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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void getArticles(RoutingContext routingContext) {
|
||||
String articleId = routingContext.request()
|
||||
.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));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user