summaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/container/handler/test/MockServiceHandler.java
blob: a06422a1bf47dbd53697ba1cd59f6bfcf0d0248e (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.handler.test;

import com.yahoo.api.annotations.Beta;
import com.yahoo.container.jdisc.HttpRequest;

/**
 * A service handler that is able to map a request to a key and retrieve a value given a key.
 *
 * @author Ulf Lilleengen
 */
@Beta
public interface MockServiceHandler {

    /**
     * Create a custom Key given a http request. This will be called for each request, and allows a handler
     * to customize its key format.
     * @param request The client http request.
     * @return a {@link Key} used to query for the value.
     */
    Key createKey(HttpRequest request);

    /**
     * Lookup a {@link Value} for a {@link Key}. Returns null if the key is not found.
     *
     * @param key The {@link Key} to look up.
     * @return A {@link Value} used as response.
     */
    Value get(Key key);

    final class Value {

        public final int returnCode;
        public final byte[] data;
        public final String contentType;

        public Value(int returnCode, byte[] data, String contentType) {
            this.returnCode = returnCode;
            this.data = data;
            this.contentType = contentType;
        }

    }

    interface Key {

        int hashCode();
        boolean equals(Object other);

    }
}