Skip to content

Instantly share code, notes, and snippets.

@alexeypro
Created May 6, 2012 15:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexeypro/2622909 to your computer and use it in GitHub Desktop.
Save alexeypro/2622909 to your computer and use it in GitHub Desktop.
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