Fix URL length limit, filter lookup URLs in log entries (for length)
This commit is contained in:
parent
af8dd4d925
commit
a610b443e4
|
@ -101,6 +101,7 @@ import net.frozenorb.apiv3.serialization.jackson.InstantJsonSerializer;
|
||||||
import net.frozenorb.apiv3.serialization.jackson.UuidJsonDeserializer;
|
import net.frozenorb.apiv3.serialization.jackson.UuidJsonDeserializer;
|
||||||
import net.frozenorb.apiv3.serialization.jackson.UuidJsonSerializer;
|
import net.frozenorb.apiv3.serialization.jackson.UuidJsonSerializer;
|
||||||
import net.frozenorb.apiv3.serialization.mongodb.UuidCodecProvider;
|
import net.frozenorb.apiv3.serialization.mongodb.UuidCodecProvider;
|
||||||
|
import net.frozenorb.apiv3.unsorted.FilteringLoggerHandler;
|
||||||
import net.frozenorb.apiv3.util.EmailUtils;
|
import net.frozenorb.apiv3.util.EmailUtils;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.codecs.BsonValueCodecProvider;
|
import org.bson.codecs.BsonValueCodecProvider;
|
||||||
|
@ -283,7 +284,9 @@ public final class APIv3 extends AbstractVerticle {
|
||||||
|
|
||||||
private void setupHttpServer() {
|
private void setupHttpServer() {
|
||||||
HttpServerOptions httpServerOptions = new HttpServerOptions();
|
HttpServerOptions httpServerOptions = new HttpServerOptions();
|
||||||
|
|
||||||
httpServerOptions.setCompressionSupported(true);
|
httpServerOptions.setCompressionSupported(true);
|
||||||
|
httpServerOptions.setMaxInitialLineLength(Integer.MAX_VALUE);
|
||||||
|
|
||||||
if (!config.getProperty("http.keystoreFile").isEmpty()) {
|
if (!config.getProperty("http.keystoreFile").isEmpty()) {
|
||||||
httpServerOptions.setSsl(true);
|
httpServerOptions.setSsl(true);
|
||||||
|
@ -297,7 +300,7 @@ public final class APIv3 extends AbstractVerticle {
|
||||||
HttpServer webServer = vertx.createHttpServer(httpServerOptions);
|
HttpServer webServer = vertx.createHttpServer(httpServerOptions);
|
||||||
Router http = Router.router(vertx); // we just name this http to make the route declarations easier to read
|
Router http = Router.router(vertx); // we just name this http to make the route declarations easier to read
|
||||||
|
|
||||||
http.route().handler(LoggerHandler.create(LoggerFormat.TINY));
|
http.route().handler(new FilteringLoggerHandler());
|
||||||
http.route().handler(TimeoutHandler.create(TimeUnit.SECONDS.toMillis(5)));
|
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().method(HttpMethod.PUT).method(HttpMethod.POST).method(HttpMethod.DELETE).handler(BodyHandler.create());
|
||||||
http.route().handler(new ActorAttributeHandler());
|
http.route().handler(new ActorAttributeHandler());
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue