summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApi.java
blob: be8209bcc4e397a13bbf119e77123002d1421c3e (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
52
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.jersey;

import com.yahoo.config.model.producer.AbstractConfigProducer;

/**
 * Represents a rest-api
 *
 * @author gjoranv
 */
public class RestApi extends AbstractConfigProducer<AbstractConfigProducer<?>> {

    private final String bindingPath;
    private final Jersey2Servlet jerseyServlet;
    private RestApiContext restApiContext;

    public RestApi(String bindingPath) {
        super(idFromPath(bindingPath));
        this.bindingPath = bindingPath;

        jerseyServlet = createJersey2Servlet(this.bindingPath);
        addChild(jerseyServlet);
    }

    public static String idFromPath(String path) {
        return path.replaceAll("/", "|");
    }

    private Jersey2Servlet createJersey2Servlet(String bindingPath) {
        return new Jersey2Servlet(bindingPath);
    }

    public String getBindingPath() {
        return bindingPath;
    }

    public void setRestApiContext(RestApiContext restApiContext) {
        this.restApiContext = restApiContext;
        addChild(restApiContext);
        jerseyServlet.inject(restApiContext);
    }

    public RestApiContext getContext() { return restApiContext; }

    public Jersey2Servlet getJersey2Servlet() {
        return jerseyServlet;
    }

    public void prepare() {
        restApiContext.prepare();
    }
}