Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Server.java example for vert.x
import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.deploy.Verticle;
/*
Compile:
$ javac Server.java -Xlint:unchecked -cp $VERTX_HOME/lib/jars/vert.x-core.jar:$VERTX_HOME/lib/jars/vert.x-platform.jar
Run
$ vertx run Server
$ curl http://localhost:8080
*/
public class Server extends Verticle {
@SuppressWarnings("unchecked")
public void start() {
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
System.out.println("A request has arrived on the server!");
req.response.putHeader("Content-Type", "text/plain");
req.response.end("Hello World!");
}
}).listen(8080);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment