diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index 150a6e2..46649d2 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -76,8 +76,8 @@ import net.frozenorb.apiv3.route.ipBans.GETIpBansId; import net.frozenorb.apiv3.route.ipBans.POSTIpBans; import net.frozenorb.apiv3.route.ipIntel.GETIpInteld; import net.frozenorb.apiv3.route.ipLog.GETIpLogId; -import net.frozenorb.apiv3.route.lookup.GETLookupByName; -import net.frozenorb.apiv3.route.lookup.GETLookupByUuid; +import net.frozenorb.apiv3.route.lookup.POSTLookupByName; +import net.frozenorb.apiv3.route.lookup.POSTLookupByUuid; import net.frozenorb.apiv3.route.notificationTemplates.DELETENotificationTemplatesId; import net.frozenorb.apiv3.route.notificationTemplates.GETNotificationTemplates; import net.frozenorb.apiv3.route.notificationTemplates.GETNotificationTemplatesId; @@ -101,7 +101,6 @@ import net.frozenorb.apiv3.serialization.jackson.InstantJsonSerializer; import net.frozenorb.apiv3.serialization.jackson.UuidJsonDeserializer; import net.frozenorb.apiv3.serialization.jackson.UuidJsonSerializer; import net.frozenorb.apiv3.serialization.mongodb.UuidCodecProvider; -import net.frozenorb.apiv3.unsorted.FilteringLoggerHandler; import net.frozenorb.apiv3.util.EmailUtils; import org.bson.Document; import org.bson.codecs.BsonValueCodecProvider; @@ -286,7 +285,6 @@ public final class APIv3 extends AbstractVerticle { HttpServerOptions httpServerOptions = new HttpServerOptions(); httpServerOptions.setCompressionSupported(true); - httpServerOptions.setMaxInitialLineLength(Integer.MAX_VALUE); if (!config.getProperty("http.keystoreFile").isEmpty()) { httpServerOptions.setSsl(true); @@ -300,7 +298,7 @@ public final class APIv3 extends AbstractVerticle { HttpServer webServer = vertx.createHttpServer(httpServerOptions); Router http = Router.router(vertx); // we just name this http to make the route declarations easier to read - http.route().handler(new FilteringLoggerHandler()); + http.route().handler(LoggerHandler.create(LoggerFormat.TINY)); http.route().handler(TimeoutHandler.create(TimeUnit.SECONDS.toMillis(5))); http.route().method(HttpMethod.PUT).method(HttpMethod.POST).method(HttpMethod.DELETE).handler(BodyHandler.create()); http.route().handler(new ActorAttributeHandler()); @@ -361,8 +359,8 @@ public final class APIv3 extends AbstractVerticle { http.get("/ipLog/:id").handler(new GETIpLogId()); - http.get("/lookup/byName").blockingHandler(new GETLookupByName()); - http.get("/lookup/byUuid").blockingHandler(new GETLookupByUuid()); + http.post("/lookup/byName").blockingHandler(new POSTLookupByName()); + http.post("/lookup/byUuid").blockingHandler(new POSTLookupByUuid()); http.get("/notificationTemplates/:notificationTemplateId").handler(new GETNotificationTemplatesId()); http.get("/notificationTemplates").handler(new GETNotificationTemplates()); diff --git a/src/main/java/net/frozenorb/apiv3/route/lookup/GETLookupByName.java b/src/main/java/net/frozenorb/apiv3/route/lookup/POSTLookupByName.java similarity index 86% rename from src/main/java/net/frozenorb/apiv3/route/lookup/GETLookupByName.java rename to src/main/java/net/frozenorb/apiv3/route/lookup/POSTLookupByName.java index 35ad49c..55204ef 100644 --- a/src/main/java/net/frozenorb/apiv3/route/lookup/GETLookupByName.java +++ b/src/main/java/net/frozenorb/apiv3/route/lookup/POSTLookupByName.java @@ -4,6 +4,8 @@ import com.google.common.collect.ImmutableMap; import com.mongodb.async.client.MongoCollection; import io.vertx.core.Handler; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.util.ErrorUtils; @@ -15,12 +17,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class GETLookupByName implements Handler { +public class POSTLookupByName implements Handler { private static final MongoCollection usersCollection = APIv3.getDatabase().getCollection("users"); public void handle(RoutingContext ctx) { - List rawNames = ctx.request().params().getAll("name"); + JsonObject requestBody = ctx.getBodyAsJson(); + List rawNames = (List) requestBody.getJsonArray("names", new JsonArray()).getList(); // because we accept names in any case, we store the lower case -> // how we were given the name, so we can return it to clients properly Map originalCase = new HashMap<>(); diff --git a/src/main/java/net/frozenorb/apiv3/route/lookup/GETLookupByUuid.java b/src/main/java/net/frozenorb/apiv3/route/lookup/POSTLookupByUuid.java similarity index 86% rename from src/main/java/net/frozenorb/apiv3/route/lookup/GETLookupByUuid.java rename to src/main/java/net/frozenorb/apiv3/route/lookup/POSTLookupByUuid.java index 8f01528..f70d4db 100644 --- a/src/main/java/net/frozenorb/apiv3/route/lookup/GETLookupByUuid.java +++ b/src/main/java/net/frozenorb/apiv3/route/lookup/POSTLookupByUuid.java @@ -2,6 +2,8 @@ package net.frozenorb.apiv3.route.lookup; import com.mongodb.async.client.MongoCollection; import io.vertx.core.Handler; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.util.ErrorUtils; @@ -11,12 +13,13 @@ import org.bson.Document; import java.util.*; -public final class GETLookupByUuid implements Handler { +public final class POSTLookupByUuid implements Handler { private static final MongoCollection usersCollection = APIv3.getDatabase().getCollection("users"); public void handle(RoutingContext ctx) { - List rawUuids = ctx.request().params().getAll("uuid"); + JsonObject requestBody = ctx.getBodyAsJson(); + List rawUuids = (List) requestBody.getJsonArray("uuids", new JsonArray()).getList(); // because we accept uuids with/without dashes, we store the actual uuid -> // how we were given the uuid, so we can return it to clients properly Map originalInputs = new HashMap<>(); diff --git a/src/main/java/net/frozenorb/apiv3/unsorted/FilteringLoggerHandler.java b/src/main/java/net/frozenorb/apiv3/unsorted/FilteringLoggerHandler.java deleted file mode 100644 index e2850ee..0000000 --- a/src/main/java/net/frozenorb/apiv3/unsorted/FilteringLoggerHandler.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.frozenorb.apiv3.unsorted; - -import io.vertx.core.Handler; -import io.vertx.core.http.HttpMethod; -import io.vertx.core.http.HttpServerRequest; -import io.vertx.core.logging.Logger; -import io.vertx.core.logging.LoggerFactory; -import io.vertx.ext.web.RoutingContext; - -public final class FilteringLoggerHandler implements Handler { - - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Override - public void handle(RoutingContext ctx) { - long timestamp = System.currentTimeMillis(); - HttpMethod method = ctx.request().method(); - String uri = ctx.request().uri(); - - if (uri.startsWith("/lookup/byUuid") || uri.startsWith("/lookup/byName")) { - ctx.next(); - return; - } - - ctx.addBodyEndHandler(v -> log(ctx, timestamp, method, uri)); - ctx.next(); - } - - private void log(RoutingContext context, long timestamp, HttpMethod method, String uri) { - HttpServerRequest request = context.request(); - long contentLength = request.response().bytesWritten(); - int status = request.response().getStatusCode(); - - String message = String.format("%s %s %d %d - %d ms", method, uri, status, contentLength, System.currentTimeMillis() - timestamp); - - if (status >= 500) { - logger.error(message); - } else if(status >= 400) { - logger.warn(message); - } else { - logger.info(message); - } - } - -} \ No newline at end of file