aboutsummaryrefslogtreecommitdiffstats
path: root/vespa-http-client/src/main/java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2020-01-07 12:36:14 +0100
committerJon Bratseth <bratseth@verizonmedia.com>2020-01-07 12:36:14 +0100
commitcf98aea5e47f823fe3efc87073010e39d1048956 (patch)
tree9d70ea83f29350ce1091154d6e8ed7fc20cfb130 /vespa-http-client/src/main/java
parent0854f7fdfa6e23ed66f176c75dfc49a19b198589 (diff)
Validate hostnames on setup
Diffstat (limited to 'vespa-http-client/src/main/java')
-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..2faa6d86426 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 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: