From 53aa9ce3683e89309f89c5b63869286a5f7f42a7 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Sun, 10 Jul 2016 12:18:07 -0400 Subject: [PATCH] Remove debug code from main class, use vertx's timeout handler instead of our debugging version --- src/main/java/net/frozenorb/apiv3/APIv3.java | 23 ++++---------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index a2cd62b..c63b3bf 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -30,6 +30,7 @@ import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.handler.BodyHandler; import io.vertx.ext.web.handler.LoggerFormat; import io.vertx.ext.web.handler.LoggerHandler; +import io.vertx.ext.web.handler.TimeoutHandler; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import net.frozenorb.apiv3.handler.ActorAttributeHandler; @@ -102,6 +103,7 @@ import java.time.Instant; import java.util.List; import java.util.Properties; import java.util.UUID; +import java.util.concurrent.TimeUnit; @Slf4j public final class APIv3 extends AbstractVerticle { @@ -242,22 +244,10 @@ public final class APIv3 extends AbstractVerticle { Router http = Router.router(vertx); http.route().handler(LoggerHandler.create(LoggerFormat.TINY)); - //http.route().handler(TimeoutHandler.create(TimeUnit.SECONDS.toMillis(5))); - http.route().handler((ctx) -> { - long tid = ctx.vertx().setTimer(5000, (t) -> { - log.error(ctx.getBodyAsString()); - ctx.fail(503); - }); - - ctx.addBodyEndHandler((v) -> { - ctx.vertx().cancelTimer(tid); - }); - - ctx.next(); - }); - http.route().method(HttpMethod.PUT).method(HttpMethod.POST).method(HttpMethod.DELETE).handler(BodyHandler.create()); + http.route().handler(TimeoutHandler.create(TimeUnit.SECONDS.toMillis(5))); http.route().handler(new ActorAttributeHandler()); http.route().handler(new AuthorizationHandler()); + http.route().method(HttpMethod.PUT).method(HttpMethod.POST).method(HttpMethod.DELETE).handler(BodyHandler.create()); http.exceptionHandler(Throwable::printStackTrace); // TODO: The commented out routes @@ -365,11 +355,6 @@ public final class APIv3 extends AbstractVerticle { public static void respondJson(RoutingContext ctx, int code, Object response) { ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()); ctx.response().setStatusCode(code); - - if (!ctx.request().path().contains("dumps")) { - //log.info(gson.toJson(response)); - } - ctx.response().end(gson.toJson(response)); }