package test.vertx;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.vertx.java.core.*;import org.vertx.java.core.http.HttpServer;import org.vertx.java.core.http.HttpServerRequest;import java.io.IOException;public class VertxDriver {private static final Logger logger = LoggerFactory.getLogger(VertxDriver.class);public static void main(String[] args) {VertxDriver driver = new VertxDriver();Vertx vertx = VertxFactory.newVertx();HttpServer httpServer = vertx.createHttpServer();httpServer.requestHandler(driver.new FileRequestHandler(vertx));httpServer.listen(9999,"localhost");try {System.in.read();} catch (IOException e) {e.printStackTrace();}}class FileRequestHandler implements Handler<HttpServerRequest> {private Vertx vertx;FileRequestHandler(Vertx vertx) {this.vertx = vertx;}@Overridepublic void handle(HttpServerRequest httpServerRequest) {String file = "";if(httpServerRequest.path().equals("/")) {file = "index.html";}logger.info("File being served is: "+file);httpServerRequest.response().sendFile("web/"+file);}}}
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks Tim. That helped - would be awesome if there's a way on the APIs to pass in a file or stream object - because this is in the resources folder but sounds like vertx isn't reading it from there (even though it's on the classpath). Or may be I'm wrong and there's a way - I'm just getting started.
I didn't want to run 'vertx' from the command prompt and I wanted to be in control of how to kickstart the program, hence I took this approach of embedding it. To me, embedding is the best way to integrate vertx into bigger projects that I'm working on. I'm learning and I might be more comfortable as I spend more time with this. But overall from what I read - it's awesome. Thanks for this great work.