summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2019-12-02 14:59:08 +0100
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2019-12-02 15:35:49 +0100
commit313236a5df9390dbd54e37a31665ba6277dd2713 (patch)
treebed3c47132edd855fe880640dc577d9fe2110056
parent39c902f023ba4356a5bc9fd525dacf23b977eb04 (diff)
Build http-utils with jdk8 and remove reflection hack
-rw-r--r--http-utils/pom.xml29
-rw-r--r--http-utils/src/main/java/ai/vespa/util/http/VespaHttpClientBuilder.java2
-rw-r--r--http-utils/src/test/java/ai/vespa/util/http/VespaHttpClientBuilderTest.java3
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/ApacheGatewayConnection.java3
-rw-r--r--vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/VespaTlsAwareClientBuilder.java26
5 files changed, 34 insertions, 29 deletions
diff --git a/http-utils/pom.xml b/http-utils/pom.xml
index aea402aef87..0d340922042 100644
--- a/http-utils/pom.xml
+++ b/http-utils/pom.xml
@@ -11,6 +11,13 @@
<artifactId>http-utils</artifactId>
<packaging>jar</packaging>
<version>7-SNAPSHOT</version>
+
+ <properties>
+ <!-- vespa-http-client targets jdk8 and uses this library -->
+ <!-- TODO remove once vespa-http-client no longer builds against jdk8 -->
+ <maven.compiler.release>8</maven.compiler.release>
+ </properties>
+
<dependencies>
<!-- provided -->
<dependency>
@@ -49,4 +56,26 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <jdkToolchain>
+ <version>${java.version}</version>
+ </jdkToolchain>
+ <source>${java.version}</source>
+ <target>${java.version}</target>
+ <showDeprecation>true</showDeprecation>
+ <compilerArgs>
+ <arg>-Xlint:all</arg>
+ <arg>-Xlint:-serial</arg>
+ <arg>-Werror</arg>
+ </compilerArgs>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/http-utils/src/main/java/ai/vespa/util/http/VespaHttpClientBuilder.java b/http-utils/src/main/java/ai/vespa/util/http/VespaHttpClientBuilder.java
index 529cfdc2aff..a408b0d79ae 100644
--- a/http-utils/src/main/java/ai/vespa/util/http/VespaHttpClientBuilder.java
+++ b/http-utils/src/main/java/ai/vespa/util/http/VespaHttpClientBuilder.java
@@ -71,7 +71,7 @@ public class VespaHttpClientBuilder {
}
private static HttpClientBuilder createBuilder(ConnectionManagerFactory connectionManagerFactory) {
- var builder = HttpClientBuilder.create();
+ HttpClientBuilder builder = HttpClientBuilder.create();
addSslSocketFactory(builder, connectionManagerFactory);
addHttpsRewritingRoutePlanner(builder);
return builder;
diff --git a/http-utils/src/test/java/ai/vespa/util/http/VespaHttpClientBuilderTest.java b/http-utils/src/test/java/ai/vespa/util/http/VespaHttpClientBuilderTest.java
index 85ee0913c58..b9a8fd748d6 100644
--- a/http-utils/src/test/java/ai/vespa/util/http/VespaHttpClientBuilderTest.java
+++ b/http-utils/src/test/java/ai/vespa/util/http/VespaHttpClientBuilderTest.java
@@ -6,6 +6,7 @@ import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.routing.HttpRoutePlanner;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -32,7 +33,7 @@ public class VespaHttpClientBuilderTest {
}
private static void verifyProcessedUriMatchesExpectedOutput(String inputHostString, String expectedHostString) throws HttpException {
- var routePlanner = new VespaHttpClientBuilder.HttpToHttpsRoutePlanner();
+ HttpRoutePlanner routePlanner = new VespaHttpClientBuilder.HttpToHttpsRoutePlanner();
HttpRoute newRoute = routePlanner.determineRoute(HttpHost.create(inputHostString), mock(HttpRequest.class), new HttpClientContext());
HttpHost target = newRoute.getTargetHost();
assertEquals(expectedHostString, target.toURI());
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 00f52d6337f..e7a1e6615f4 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
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. 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 com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yahoo.vespa.http.client.config.ConnectionParams;
@@ -396,7 +397,7 @@ class ApacheGatewayConnection implements GatewayConnection {
public HttpClient createClient() {
HttpClientBuilder clientBuilder;
if (connectionParams.useTlsConfigFromEnvironment()) {
- clientBuilder = VespaTlsAwareClientBuilder.createHttpClientBuilder();
+ clientBuilder = VespaHttpClientBuilder.create();
} else {
clientBuilder = HttpClientBuilder.create();
if (useSsl && connectionParams.getSslContext() != null) {
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 be67e11963e..00000000000
--- a/vespa-http-client/src/main/java/com/yahoo/vespa/http/client/core/communication/VespaTlsAwareClientBuilder.java
+++ /dev/null
@@ -1,26 +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 org.apache.http.impl.client.HttpClientBuilder;
-
-/**
- * A static factory for VespaHttpClientBuilder.
- * The main purpose of this class is to avoid references to classes not compiled with JDK8.
- *
- * @author bjorncs
- */
-// 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+.
-class VespaTlsAwareClientBuilder {
-
- private VespaTlsAwareClientBuilder() {}
-
- static HttpClientBuilder createHttpClientBuilder() {
- try {
- Class<?> builderClass = Class.forName("ai.vespa.util.http.VespaHttpClientBuilder");
- return (HttpClientBuilder) builderClass.getMethod("create").invoke(null);
- } catch (ReflectiveOperationException e) {
- throw new RuntimeException(e);
- }
- }
-}