Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Failure Handler Issue
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
You can’t perform that action at this time.