Created
May 15, 2015 15:32
-
-
Save jtruelove/7a1a4021b1acf0960aa4 to your computer and use it in GitHub Desktop.
Failure Handler Issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.netty.handler.codec.http.HttpResponseStatus; | |
import io.vertx.core.AbstractVerticle; | |
import io.vertx.core.Future; | |
import io.vertx.core.http.HttpServerOptions; | |
import io.vertx.ext.apex.Route; | |
import io.vertx.ext.apex.Router; | |
import io.vertx.ext.apex.handler.LoggerHandler; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class TestServer extends AbstractVerticle { | |
private static final Logger logger = LoggerFactory.getLogger(TestServer.class); | |
@Override | |
public void start(final Future<Void> onStartup) { | |
Router testRouter1 = Router.router(vertx); | |
// Test case 1, I'd expect to get log lines but only the LoggerHandler gets hit | |
// 1) send something to /foo ie curl "http://localhost:8000/foo" | |
Route testRoute = testRouter1.route(); | |
testRoute.handler(LoggerHandler.create()); | |
testRoute.failureHandler(routingContext -> { | |
logger.warn("Test case 1, no path found for {}", routingContext.request().uri()); | |
routingContext.request().response().setStatusCode(HttpResponseStatus.NOT_FOUND.code()).end(); | |
}); | |
vertx.createHttpServer(new HttpServerOptions().setHost("0.0.0.0").setPort(8000)) | |
.requestHandler(testRouter1::accept).listen(startupResult -> { | |
logger.info("start - thread: {} starting to handle http requests on 8000", Thread.currentThread().getId()); | |
}); | |
onStartup.complete(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment