summaryrefslogtreecommitdiffstats
path: root/vespa-http-client/src/main
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2020-01-07 14:57:19 +0100
committerGitHub <noreply@github.com>2020-01-07 14:57:19 +0100
commiteb0520f9114f4555d0636e9e0effcdfea40a1395 (patch)
treebbfc124c595ed9981b202a4859f0b244b0a685ed /vespa-http-client/src/main
parent9ebceeaf35519f3f1edf8ad70d86a6b754feb457 (diff)
parenta11412b2f0184c2cc0c102c38d9701aff1bb27ae (diff)
Merge pull request #11672 from vespa-engine/bratseth/validate-hostnames
Validate hostnames on setup
Diffstat (limited to 'vespa-http-client/src/main')
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java31
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/IOThread.java1
2 files changed, 21 insertions, 11 deletions
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 e95044ce6d2..0e7488c8927 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
@@ -27,6 +27,8 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -75,7 +77,7 @@ class ApacheGatewayConnection implements GatewayConnection {
HttpClientFactory httpClientFactory,
String clientId) {
SUPPORTED_VERSIONS.add(3);
- this.endpoint = endpoint;
+ this.endpoint = validate(endpoint);
this.feedParams = feedParams;
this.clusterSpecificRoute = clusterSpecificRoute;
this.httpClientFactory = httpClientFactory;
@@ -90,8 +92,17 @@ class ApacheGatewayConnection implements GatewayConnection {
endOfFeed = END_OF_FEED_XML;
}
this.clientId = clientId;
- if (this.clientId == null) {
- throw new RuntimeException("Got no client Id.");
+ if (this.clientId == null)
+ throw new IllegalArgumentException("Got no client Id.");
+ }
+
+ private static Endpoint validate(Endpoint endpoint) {
+ try {
+ InetAddress.getByName(endpoint.getHostname());
+ return endpoint;
+ }
+ catch (UnknownHostException e) {
+ throw new IllegalArgumentException("Unknown host: " + endpoint);
}
}
@@ -390,7 +401,7 @@ class ApacheGatewayConnection implements GatewayConnection {
final ConnectionParams connectionParams;
final boolean useSsl;
- public HttpClientFactory(final ConnectionParams connectionParams, final boolean useSsl) {
+ public HttpClientFactory(ConnectionParams connectionParams, boolean useSsl) {
this.connectionParams = connectionParams;
this.useSsl = useSsl;
}
@@ -426,14 +437,12 @@ class ApacheGatewayConnection implements GatewayConnection {
clientBuilder.disableContentCompression();
// Try to disable the disabling to see if system tests become stable again.
// clientBuilder.disableAutomaticRetries();
- {
- RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
- requestConfigBuilder.setSocketTimeout(0);
- if (connectionParams.getProxyHost() != null) {
- requestConfigBuilder.setProxy(new HttpHost(connectionParams.getProxyHost(), connectionParams.getProxyPort()));
- }
- clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
+ RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
+ requestConfigBuilder.setSocketTimeout(0);
+ if (connectionParams.getProxyHost() != null) {
+ requestConfigBuilder.setProxy(new HttpHost(connectionParams.getProxyHost(), connectionParams.getProxyPort()));
}
+ clientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
log.fine("Creating HttpClient: " + " ConnectionTimeout "
+ " SocketTimeout 0 secs "
diff --git a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/IOThread.java b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/IOThread.java
index 643b7641e68..77ed8464284 100644
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/IOThread.java
+++ b/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/IOThread.java
@@ -298,6 +298,7 @@ class IOThread implements Runnable, AutoCloseable {
return processResponse;
}
+ /** Given a current thread state, take the appropriate action and return the resulting new thread state */
private ThreadState cycle(ThreadState threadState) {
switch(threadState) {
case DISCONNECTED: