Skip to content

Instantly share code, notes, and snippets.

@vietj
Created July 14, 2016 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vietj/9a27b6515f771ff88c096dc10dfdd1b0 to your computer and use it in GitHub Desktop.
Save vietj/9a27b6515f771ff88c096dc10dfdd1b0 to your computer and use it in GitHub Desktop.
public class Main {
@Path("/")
public static class Controller
{
@GET
@Path("/{path:.*}")
@Produces("text/plain")
public String context(
@PathParam("path") String id,
@Context io.vertx.core.Context context,
@Context io.vertx.core.Vertx vertx,
@Context io.vertx.core.http.HttpServerRequest req,
@Context io.vertx.core.http.HttpServerResponse resp) {
if (context != null && vertx != null && req != null && resp != null) {
return Thread.currentThread().getName();
} else {
return "fail";
}
}
}
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
HttpServer server = vertx.createHttpServer();
VertxResteasyDeployment deployment = new VertxResteasyDeployment();
deployment.start();
deployment.getRegistry().addPerInstanceResource(Controller.class);
server.requestHandler(new VertxRequestHandler(vertx, deployment));
server.listen(8080, "localhost", ar -> {
if (ar.succeeded()) {
System.out.println("started");
} else {
ar.cause().printStackTrace();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment