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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// 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.http.xml;
import com.yahoo.config.model.builder.xml.XmlHelper;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.text.XML;
import com.yahoo.vespa.model.builder.xml.dom.VespaDomBuilder;
import com.yahoo.vespa.model.container.component.SimpleComponent;
import com.yahoo.vespa.model.container.http.ConnectorFactory;
import com.yahoo.vespa.model.container.http.ssl.CustomSslProvider;
import com.yahoo.vespa.model.container.http.ssl.DefaultSslProvider;
import com.yahoo.vespa.model.container.http.ssl.LegacySslProvider;
import org.w3c.dom.Element;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author Einar M R Rosenvinge
* @author mortent
*/
public class JettyConnectorBuilder extends VespaDomBuilder.DomConfigProducerBuilder<ConnectorFactory> {
private static final Logger log = Logger.getLogger(JettyConnectorBuilder.class.getName());
@Override
protected ConnectorFactory doBuild(DeployState deployState, AbstractConfigProducer ancestor, Element serverSpec) {
String name = XmlHelper.getIdString(serverSpec);
int port = HttpBuilder.readPort(serverSpec, deployState.isHosted(), deployState.getDeployLogger());
Element legacyServerConfig = XML.getChild(serverSpec, "config");
if (legacyServerConfig != null) {
String configName = legacyServerConfig.getAttribute("name");
if (configName.equals("container.jdisc.config.http-server")) {
deployState.getDeployLogger().log(Level.WARNING, "The config 'container.jdisc.config.http-server' is deprecated and will be removed in a later version of Vespa."
+ " Please use 'jdisc.http.connector' instead, see http://docs.vespa.ai/documentation/jdisc/http-server-and-filters.html#configuring-jetty-server");
} else {
legacyServerConfig = null;
}
}
SimpleComponent sslProviderComponent = getSslConfigComponents(name, serverSpec);
return new ConnectorFactory(name, port, legacyServerConfig, sslProviderComponent);
}
SimpleComponent getSslConfigComponents(String serverName, Element serverSpec) {
Element sslConfigurator = XML.getChild(serverSpec, "ssl");
Element sslProviderConfigurator = XML.getChild(serverSpec, "ssl-provider");
if (sslConfigurator != null) {
String privateKeyFile = XML.getValue(XML.getChild(sslConfigurator, "private-key-file"));
String certificateFile = XML.getValue(XML.getChild(sslConfigurator, "certificate-file"));
Optional<String> caCertificateFile = XmlHelper.getOptionalChildValue(sslConfigurator, "ca-certificates-file");
Optional<String> clientAuthentication = XmlHelper.getOptionalChildValue(sslConfigurator, "client-authentication");
return new DefaultSslProvider(
serverName,
privateKeyFile,
certificateFile,
caCertificateFile.orElse(null),
clientAuthentication.orElse(null));
} else if (sslProviderConfigurator != null) {
String className = sslProviderConfigurator.getAttribute("class");
String bundle = sslProviderConfigurator.getAttribute("bundle");
return new CustomSslProvider(serverName, className, bundle);
} else {
return new LegacySslProvider(serverName);
}
}
}
|