diff options
author | gjoranv <gv@verizonmedia.com> | 2022-01-15 02:14:51 +0100 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2022-01-17 17:01:58 +0100 |
commit | 1d2723348ba097db19b77efca99cd7fd09a0f4c3 (patch) | |
tree | cc23523ba87f572ea6198e40028964c41dd91fc1 | |
parent | 2d3c29896e0c7ad2d61c518c23775b215b68d4ef (diff) |
Allow Response to populate the access log from ThreadedHttpReqHndlr
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java b/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java index 722f1850013..8986fa596b8 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java @@ -3,6 +3,7 @@ package com.yahoo.container.jdisc; import com.google.inject.Inject; import com.yahoo.container.logging.AccessLog; +import com.yahoo.container.logging.AccessLogEntry; import com.yahoo.jdisc.Metric; import com.yahoo.jdisc.Request; import com.yahoo.jdisc.handler.BufferedContentChannel; @@ -10,7 +11,10 @@ import com.yahoo.jdisc.handler.CompletionHandler; import com.yahoo.jdisc.handler.ContentChannel; import com.yahoo.jdisc.handler.UnsafeContentInputStream; import com.yahoo.jdisc.handler.ResponseHandler; +import com.yahoo.jdisc.http.server.jetty.AccessLoggingRequestHandler; +import com.yahoo.yolean.Exceptions; +import java.util.Optional; import java.util.logging.Level; import java.io.IOException; @@ -244,7 +248,7 @@ public abstract class ThreadedHttpRequestHandler extends ThreadedRequestHandler HttpResponse response, HttpRequest httpRequest, ContentChannelOutputStream rendererWiring) { - return null; + return new ResponseLogger(httpRequest, response); } protected com.yahoo.jdisc.http.HttpRequest asHttpRequest(Request request) { @@ -287,4 +291,39 @@ public abstract class ThreadedHttpRequestHandler extends ThreadedRequestHandler } + + private class ResponseLogger implements LoggingCompletionHandler { + + private final com.yahoo.jdisc.http.HttpRequest jdiscRequest; + private final HttpResponse httpResponse; + + ResponseLogger(HttpRequest httpRequest, HttpResponse httpResponse) { + this.jdiscRequest = httpRequest.getJDiscRequest(); + this.httpResponse = httpResponse; + } + + @Override + public void markCommitStart() { } + + @Override + public void completed() { + writeToAccessLog(); + } + + @Override + public void failed(Throwable throwable) { + writeToAccessLog(); + log.log(Level.FINE, () -> "Got exception when writing to client: " + Exceptions.toMessageString(throwable)); + } + + private void writeToAccessLog() { + Optional<AccessLogEntry> jdiscReqAccessLogEntry = AccessLoggingRequestHandler.getAccessLogEntry(jdiscRequest); + AccessLogEntry entry; + if (jdiscReqAccessLogEntry.isPresent()) { + entry = jdiscReqAccessLogEntry.get(); + httpResponse.populateAccessLogEntry(entry); + } + } + } + } |