Skip to content

Instantly share code, notes, and snippets.

@nscavell nscavell/Server.java
Last active Aug 29, 2015

Embed
What would you like to do?
OpenShift Server.java Example
import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.platform.Verticle;
public class Server extends Verticle {
@Override
public void start() {
String ip = container.env().get("OPENSHIFT_VERTX_IP");
if (ip == null) {
ip = "127.0.0.1";
}
String port = container.env().get("OPENSHIFT_VERTX_PORT");
if (port == null) {
port = "8080";
}
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
@Override
public void handle(final HttpServerRequest request) {
if (request.path().equals("/hello")) {
request.response().end("Hello from Java !!!");
} else {
String file = request.path().equals("/") ? "index.html" : request.path();
request.response().sendFile("webroot/" + file);
}
}
}).listen(Integer.parseInt(port), ip);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.