com.yahoo.container.handler.AccessLogRequestHandler Maven / Gradle / Ivy
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.handler;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.jdisc.ThreadedHttpRequestHandler;
import com.yahoo.container.logging.CircularArrayAccessLogKeeper;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.concurrent.Executor;
/**
* Exposes access log through http.
*
* @author dybis
*/
public class AccessLogRequestHandler extends ThreadedHttpRequestHandler {
private final CircularArrayAccessLogKeeper circularArrayAccessLogKeeper;
private final JsonFactory jsonFactory = new JsonFactory();
public AccessLogRequestHandler(Executor executor, CircularArrayAccessLogKeeper circularArrayAccessLogKeeper) {
super(executor);
this.circularArrayAccessLogKeeper = circularArrayAccessLogKeeper;
}
@Override
public HttpResponse handle(HttpRequest request) {
final List uris = circularArrayAccessLogKeeper.getUris();
return new HttpResponse(200) {
@Override
public void render(OutputStream outputStream) throws IOException {
JsonGenerator generator = jsonFactory.createGenerator(outputStream);
generator.writeStartObject();
generator.writeArrayFieldStart("entries");
for (String uri : uris) {
generator.writeStartObject();
generator.writeStringField("url", uri);
generator.writeEndObject();
}
generator.writeEndArray();
generator.writeEndObject();
generator.close();
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy