aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/auditlog/AuditLoggingRequestHandler.java
blob: cb2fca3e4110fdbd0028c96b074d115c8dac2229 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.auditlog;

import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.jdisc.ThreadedHttpRequestHandler;
import com.yahoo.jdisc.handler.ContentChannel;

/**
 * A handler that logs requests to the audit log. Handlers that need audit logging should extend this and implement
 * {@link AuditLoggingRequestHandler#auditAndHandle(HttpRequest)}.
 *
 * @author mpolden
 */
public abstract class AuditLoggingRequestHandler extends ThreadedHttpRequestHandler {

    private final AuditLogger auditLogger;

    public AuditLoggingRequestHandler(Context ctx, AuditLogger auditLogger) {
        super(ctx);
        this.auditLogger = auditLogger;
    }

    @Override
    public final HttpResponse handle(HttpRequest request) {
        return auditAndHandle(auditLogger.log(request));
    }

    @Override
    public final HttpResponse handle(HttpRequest request, ContentChannel channel) {
        return super.handle(request, channel);
    }

    public abstract HttpResponse auditAndHandle(HttpRequest request);

}