aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/container/xml/DocumentApiOptionsBuilder.java
blob: 1d022381d4bd82c5a10d22b4cb4450e8ea531b33 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.xml;

import com.yahoo.text.XML;
import com.yahoo.vespa.model.clients.ContainerDocumentApi;
import org.w3c.dom.Element;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Logger;

/**
 * @author Einar M R Rosenvinge
 */
public class DocumentApiOptionsBuilder {

    private static final Logger log = Logger.getLogger(DocumentApiOptionsBuilder.class.getName());

    public static ContainerDocumentApi.HandlerOptions build(Element spec) {
        return new ContainerDocumentApi.HandlerOptions(getBindings(spec), XML.getChild(spec, "http-client-api"));
    }

    private static List<String> getBindings(Element spec) {
        Collection<Element> bindingElems =  XML.getChildren(spec, "binding");
        if (bindingElems.isEmpty())
            return List.of();
        List<String> bindings = new ArrayList<>();
        for (Element e :bindingElems) {
            String binding = getBinding(e);
            bindings.add(binding);
        }
        return bindings;
    }

    private static String getBinding(Element e) {
        String binding = XML.getValue(e);
        if (! binding.endsWith("/")) {
            log.warning("Adding a trailing '/' to the document-api binding: " + binding + " -> " + binding + "/");
            binding = binding + "/";
        }
        return binding;
    }

}