Created
May 6, 2012 15:25
-
-
Save alexeypro/2622909 to your computer and use it in GitHub Desktop.
Server.java example for vert.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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