Revert previous commit, change lookup routes to POSTs

This commit is contained in:
Colin McDonald 2016-10-24 17:08:57 -04:00
parent a610b443e4
commit e082e69063
4 changed files with 15 additions and 56 deletions

View File

@ -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());

View File

@ -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<RoutingContext> {
public class POSTLookupByName implements Handler<RoutingContext> {
private static final MongoCollection<Document> usersCollection = APIv3.getDatabase().getCollection("users");
public void handle(RoutingContext ctx) {
List<String> rawNames = ctx.request().params().getAll("name");
JsonObject requestBody = ctx.getBodyAsJson();
List<String> rawNames = (List<String>) 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<String, String> originalCase = new HashMap<>();

View File

@ -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<RoutingContext> {
public final class POSTLookupByUuid implements Handler<RoutingContext> {
private static final MongoCollection<Document> usersCollection = APIv3.getDatabase().getCollection("users");
public void handle(RoutingContext ctx) {
List<String> rawUuids = ctx.request().params().getAll("uuid");
JsonObject requestBody = ctx.getBodyAsJson();
List<String> rawUuids = (List<String>) 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<String, String> originalInputs = new HashMap<>();

View File

@ -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<RoutingContext> {
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);
}
}
}