-
Notifications
You must be signed in to change notification settings - Fork 5
/
HttpServerVerticle.java
36 lines (30 loc) · 1.04 KB
/
HttpServerVerticle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.genericsystem.watch;
import java.net.BindException;
import java.net.SocketException;
import java.net.UnknownHostException;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
public class HttpServerVerticle extends AbstractVerticle {
public static void main(String[] args) throws UnknownHostException, SocketException {
Vertx.vertx().deployVerticle(new HttpServerVerticle());
}
@Override
public void start(Future<Void> future) throws Exception {
vertx.createHttpServer().requestHandler(req -> {
String fileName = req.path();
String path = DistributedVerticle.BASE_PATH + fileName;
System.out.println("Will send :" + path + " on thread " + Thread.currentThread());
req.response().sendFile(path);
}).listen(8084, ar -> {
if (ar.failed()) {
if (ar.cause() instanceof BindException) {
System.out.println("BindException ignored, HttpServer already started.");
future.complete();
} else
future.fail(ar.cause());
} else
future.complete();
});
}
}