diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2019-07-18 12:55:14 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2019-07-18 12:55:14 +0200 |
commit | 57f00111e19e3a7e9543d9f7f4f5ee78697fb30e (patch) | |
tree | 364f8ad7e9da783acfc0b87c559b6fa44a839383 /vespa-http-client/src | |
parent | e495f76befbffc97f5cf8201aab19aa259eb8a7f (diff) |
Revert "Add Vespa TLS support to vespa-http-client"
This reverts commit 4ed7063aa9a5c3d961231484178945ed3ecef441.
Diffstat (limited to 'vespa-http-client/src')
4 files changed, 21 insertions, 89 deletions
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java index adf61b124ab..f503190864b 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/config/ConnectionParams.java @@ -43,16 +43,6 @@ public final class ConnectionParams { private int traceLevel = 0; private int traceEveryXOperation = 0; private boolean printTraceToStdErr = true; - private boolean useTlsConfigFromEnvironment = false; - - /** - * Use TLS configuration through the standard Vespa environment variables. - * Setting this to 'true' will override any other TLS/HTTPS related configuration. - */ - public Builder setUseTlsConfigFromEnvironment(boolean useTlsConfigFromEnvironment) { - this.useTlsConfigFromEnvironment = useTlsConfigFromEnvironment; - return this; - } /** * Sets the SSLContext for the connection to the gateway when SSL is enabled for Endpoint. @@ -243,8 +233,7 @@ public final class ConnectionParams { dryRun, traceLevel, traceEveryXOperation, - printTraceToStdErr, - useTlsConfigFromEnvironment); + printTraceToStdErr); } public int getNumPersistentConnectionsPerEndpoint() { @@ -284,10 +273,6 @@ public final class ConnectionParams { public HostnameVerifier getHostnameVerifier() { return hostnameVerifier; } - - public boolean useTlsConfigFromEnvironment() { - return useTlsConfigFromEnvironment; - } } private final SSLContext sslContext; private final HostnameVerifier hostnameVerifier; @@ -303,7 +288,6 @@ public final class ConnectionParams { private final int traceLevel; private final int traceEveryXOperation; private final boolean printTraceToStdErr; - private final boolean useTlsConfigFromEnvironment; private ConnectionParams( SSLContext sslContext, @@ -319,11 +303,9 @@ public final class ConnectionParams { boolean dryRun, int traceLevel, int traceEveryXOperation, - boolean printTraceToStdErr, - boolean useTlsConfigFromEnvironment) { + boolean printTraceToStdErr) { this.sslContext = sslContext; this.hostnameVerifier = hostnameVerifier; - this.useTlsConfigFromEnvironment = useTlsConfigFromEnvironment; this.headers.putAll(headers); this.headerProviders.putAll(headerProviders); this.numPersistentConnectionsPerEndpoint = numPersistentConnectionsPerEndpoint; @@ -396,10 +378,6 @@ public final class ConnectionParams { return printTraceToStdErr; } - public boolean useTlsConfigFromEnvironment() { - return useTlsConfigFromEnvironment; - } - /** * A header provider that provides a header value. {@link #getHeaderValue()} is called each time a new HTTP request * is constructed by {@link com.yahoo.vespa.http.client.FeedClient}. diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java index fcb5e03878d..5289a7a562a 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java @@ -17,8 +17,14 @@ import org.apache.http.StatusLine; import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpPost; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.message.BasicHeader; import java.io.ByteArrayInputStream; @@ -394,26 +400,25 @@ class ApacheGatewayConnection implements GatewayConnection { } public HttpClient createClient() { - HttpClientBuilder clientBuilder; - if (connectionParams.useTlsConfigFromEnvironment()) { - // Note: connection settings are confgured in createVespaTlsAwareClientBuilder. - clientBuilder = createVespaTlsAwareClientBuilder(); - } else { - clientBuilder = HttpClientBuilder.create(); - if (useSsl && connectionParams.getSslContext() != null) { - clientBuilder.setSslcontext(connectionParams.getSslContext()); - clientBuilder.setSSLHostnameVerifier(connectionParams.getHostnameVerifier()); - } - clientBuilder.setMaxConnPerRoute(1); - clientBuilder.setMaxConnTotal(1); - clientBuilder.setConnectionTimeToLive(15, TimeUnit.SECONDS); - } + HttpClientBuilder clientBuilder = HttpClientBuilder.create(); + if (useSsl && connectionParams.getSslContext() != null) { + Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() + .register("https", new SSLConnectionSocketFactory( + connectionParams.getSslContext(), connectionParams.getHostnameVerifier())) + .register("http", PlainConnectionSocketFactory.INSTANCE) + .build(); + PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry); + clientBuilder.setConnectionManager(connMgr); + } clientBuilder.setUserAgent(String.format("vespa-http-client (%s)", Vtag.currentVersion)); clientBuilder.setDefaultHeaders(Collections.singletonList(new BasicHeader(Headers.CLIENT_VERSION, Vtag.currentVersion))); + clientBuilder.setMaxConnPerRoute(1); + clientBuilder.setMaxConnTotal(1); clientBuilder.disableContentCompression(); // Try to disable the disabling to see if system tests become stable again. // clientBuilder.disableAutomaticRetries(); + clientBuilder.setConnectionTimeToLive(15, TimeUnit.SECONDS); { RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); requestConfigBuilder.setSocketTimeout(0); @@ -431,19 +436,6 @@ class ApacheGatewayConnection implements GatewayConnection { ); return clientBuilder.build(); } - - // TODO Remove use of reflection once vespa-http-client only targets JDK11 - // The VespaTlsAwareClientBuilder class refers to classes in security-utils / http-utils that targets JDK11+. - // We cannot use VespaTlsAwareClientBuilder because the classloader might load it even when the createHttpClientBuilder is not invoked. - private HttpClientBuilder createVespaTlsAwareClientBuilder() { - try { - Class<?> builderClass = - Class.forName("com.yahoo.vespa.http.client.core.communication.VespaTlsAwareClientBuilder"); - return (HttpClientBuilder) builderClass.getMethod("createHttpClientBuilder").invoke(null); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } } } diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/VespaTlsAwareClientBuilder.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/VespaTlsAwareClientBuilder.java deleted file mode 100644 index 08da9dfbe2f..00000000000 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/VespaTlsAwareClientBuilder.java +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.http.client.core.communication; - -import ai.vespa.util.http.VespaHttpClientBuilder; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; - -import java.util.concurrent.TimeUnit; - -/** - * A static factory for VespaHttpClientBuilder. The main purpose of this class is to isolate references to classes targeting JDK11+. - * - * @author bjorncs - */ -// TODO Inline once vespa-http-client no longer targets JDK8 -@SuppressWarnings("unused") // used through reflection from ApacheGatewayConnection -public class VespaTlsAwareClientBuilder { - - private VespaTlsAwareClientBuilder() {} - - @SuppressWarnings("unused") // used through reflection from ApacheGatewayConnection - public static HttpClientBuilder createHttpClientBuilder() { - return VespaHttpClientBuilder.create(socketFactoryRegistry -> { - PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager( - socketFactoryRegistry, - null, null, null, - 15, TimeUnit.SECONDS); - manager.setDefaultMaxPerRoute(1); - manager.setMaxTotal(1); - return manager; - }); - } -} diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/CommandLineArguments.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/CommandLineArguments.java index ea0b3f29509..4e2c8f1509e 100644 --- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/CommandLineArguments.java +++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/runner/CommandLineArguments.java @@ -209,10 +209,6 @@ public class CommandLineArguments { description = "Add http header to every request. Header must have the format '<Name>: <Value>'. Use this parameter multiple times for multiple headers") private List<String> headers = new ArrayList<>(); - @Option(name = {"--vespaTls"}, - description = "BETA! Use Vespa TLS configuration from environment if available. Other HTTPS/TLS configuration will be ignored if this is set.") - private boolean useTlsConfigFromEnvironment = false; - private final List<Header> parsedHeaders = new ArrayList<>(); int getWhenVerboseEnabledPrintMessageForEveryXDocuments() { @@ -256,7 +252,6 @@ public class CommandLineArguments { .setTraceEveryXOperation(traceEveryXOperation) .setPrintTraceToStdErr(traceArg > 0) .setNumPersistentConnectionsPerEndpoint(numPersistentConnectionsPerEndpoint) - .setUseTlsConfigFromEnvironment(useTlsConfigFromEnvironment) .build() ) // Enable dynamic throttling. |