package de.predbo.vertx;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.StaticHandler;

public class HelloWorldVerticle extends AbstractVerticle {
	
	private static final Logger logger = LoggerFactory.getLogger(HelloWorldVerticle.class);

	@Override
	public void start() {

		createHttpServerOldSchool();

		createHttpServerJava8Style();
		
		createHttpServerUsingVertxWeb();
		
		createHttpServerUsingStaticHandler();
	}

	
	
	private void createHttpServerOldSchool() {
		HttpServer server = vertx.createHttpServer();

		server.requestHandler(new Handler<HttpServerRequest>() {
			public void handle(HttpServerRequest request) {
				logger.info("A request has arrived on port 8080 (old school)!");
				request.response().end("Hello World!");
			}
		});

		server.listen(8080, "localhost");
	}
	
	private void createHttpServerJava8Style() {
		vertx.createHttpServer().requestHandler(request -> {
			logger.info("A request has arrived on port 8081 (Java 8 style)!");
				request.response().end("Hello World!");
		}).listen(8081);
	}

	private void createHttpServerUsingVertxWeb() {
		HttpServer server = vertx.createHttpServer();

		Router router = Router.router(vertx);
		
		router.route().handler(routingContext -> {
			logger.info("A request has arrived on port 8082 (vertx-web)!");

			HttpServerResponse response = routingContext.response();
			response.putHeader("content-type", "text/plain");
			response.end("Hello World from Vert.x-Web!");
		});

		server.requestHandler(router::accept).listen(8082);
	}
	
	private void createHttpServerUsingStaticHandler() {
		HttpServer server = vertx.createHttpServer();

		Router router = Router.router(vertx);
		
		router.route("/*").handler(StaticHandler.create().setCachingEnabled(false));
		
		router.route().handler(routingContext -> {
			logger.info("A request has arrived on port 8083 (vertx-web with static content)!");
		});
		
		server.requestHandler(router::accept).listen(8083);
	}

}
@@ -2042,35 +2042,52 @@
 outer.route(
-).handler(r
+%22/*%22).failureHandler(failedR
 outingContex
@@ -2096,93 +2096,259 @@
 -%3E %7B
+ 
 %0A%09%09%09
-logger.info(%22A request has arrived on port 8083 (vertx-web with static content)!%22
+if (failedRoutingContext.failed()) %7B%0A%09%09%09%09int statusCode = failedRoutingContext.statusCode();%0A%09%09%09%09if (statusCode == 404) %7B%0A%09%09%09%09%09logger.info(%22file not found '%22 + failedRoutingContext.normalisedPath() + %22'%22);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09failedRoutingContext.next(
 );%0A%09
@@ -2355,16 +2355,19 @@
 %09%7D);%0A%09%09%0A
+%09%09%0A
 %09%09server

Add failureHandler and log 404 in logfile