Skip to content

Instantly share code, notes, and snippets.

@keesun
Created February 10, 2012 22:39
Show Gist options
  • Save keesun/1793640 to your computer and use it in GitHub Desktop.
Save keesun/1793640 to your computer and use it in GitHub Desktop.
Vert.x HttpServer Demo
package http;
import org.vertx.java.core.Handler;
import org.vertx.java.core.app.VertxApp;
import org.vertx.java.core.http.HttpServer;
import org.vertx.java.core.http.HttpServerRequest;
/**
* @author Keesun Baik
*/
public class HttpWebServer implements VertxApp{
HttpServer httpServer;
@Override
public void start() throws Exception {
httpServer = new HttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
System.out.println(req);
req.response.putHeader("Content-Type", "text/html; charset=UTF-8")
.end("<html><h1>Hello Vert.x</hi></html>");
}
}).listen(8080);
}
@Override
public void stop() throws Exception {
httpServer.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment