]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7741 upgrade OK HTTP to 3.3.1
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 27 Jun 2016 15:31:44 +0000 (17:31 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 11 Jul 2016 10:09:16 +0000 (12:09 +0200)
15 files changed:
it/it-tests/pom.xml
it/it-tests/src/test/java/it/analysis/ReportDumpTest.java
it/it-tests/src/test/java/it/http/HttpHeadersTest.java
it/it-tests/src/test/java/it/user/OAuth2IdentityProviderTest.java
pom.xml
server/sonar-process/pom.xml
server/sonar-process/src/test/java/org/sonar/process/systeminfo/SystemInfoHttpServerTest.java
server/sonar-server/pom.xml
server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/ProcessSystemInfoClientTest.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/BatchWsClientProviderTest.java
sonar-ws/pom.xml
sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java
sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java
sonar-ws/src/test/java/org/sonarqube/ws/client/HttpConnectorTest.java

index 4c5deaff0379cc3812f85ce95b313f696e813691..fb7418301cf2c3c2b196b0067339bfff2773f11e 100644 (file)
@@ -93,9 +93,9 @@
       <version>1.8.3</version>
     </dependency>
     <dependency>
-      <groupId>com.squareup.okhttp</groupId>
+      <groupId>com.squareup.okhttp3</groupId>
       <artifactId>mockwebserver</artifactId>
-      <version>2.6.0</version>
+      <version>3.3.1</version>
     </dependency>
 
     <!-- Email notifications -->
index 1000dc18c889e87ed40fce6141e954ad3bac25d8..2232dfba8971bbbb2a4845e15d80f736ad5fd0d4 100644 (file)
@@ -21,10 +21,10 @@ package it.analysis;
 
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
-import com.squareup.okhttp.HttpUrl;
-import com.squareup.okhttp.OkHttpClient;
-import com.squareup.okhttp.Request;
-import com.squareup.okhttp.Response;
+import okhttp3.HttpUrl;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
 import it.Category3Suite;
 import org.apache.commons.io.FileUtils;
 import org.junit.ClassRule;
index c03ab8536cf9fad583c66f844a1279572e529b11..d578717da30f9ba138b3c3f4bf9435a7e97f1788 100644 (file)
@@ -22,10 +22,10 @@ package it.http;
 
 import com.google.common.base.Throwables;
 import com.sonar.orchestrator.Orchestrator;
-import com.squareup.okhttp.CacheControl;
-import com.squareup.okhttp.OkHttpClient;
-import com.squareup.okhttp.Request;
-import com.squareup.okhttp.Response;
+import okhttp3.CacheControl;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
 import it.Category4Suite;
 import java.io.IOException;
 import org.junit.ClassRule;
index 7ca114f194ce726be6b830af25df8b33d69465ee..c7645ef00b06b402b43277674f6d5bce6ede2751 100644 (file)
@@ -20,8 +20,8 @@
 package it.user;
 
 import com.sonar.orchestrator.Orchestrator;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
 import it.Category4Suite;
 import java.net.HttpURLConnection;
 import org.junit.After;
diff --git a/pom.xml b/pom.xml
index 5d85db456fd6379d6385645f5c6302313927222f..ee93ce5e762fbc8b2a65e2c1c2b4ec2bf6f98375 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -67,7 +67,7 @@
     <tomcat.version>8.0.32</tomcat.version>
     <elasticsearch.version>2.3.3</elasticsearch.version>
     <orchestrator.version>3.11</orchestrator.version>
-    <okhttp.version>2.6.0</okhttp.version>
+    <okhttp.version>3.3.1</okhttp.version>
     <jackson.version>2.6.6</jackson.version>
 
     <protobuf.version>3.0.0-beta-2</protobuf.version>
         <version>${tomcat.version}</version>
       </dependency>
       <dependency>
-        <groupId>com.squareup.okhttp</groupId>
+        <groupId>com.squareup.okhttp3</groupId>
         <artifactId>okhttp</artifactId>
         <version>${okhttp.version}</version>
       </dependency>
       <dependency>
-        <groupId>com.squareup.okhttp</groupId>
+        <groupId>com.squareup.okhttp3</groupId>
         <artifactId>mockwebserver</artifactId>
         <version>${okhttp.version}</version>
       </dependency>
index 441c429fd85d01b5ee5f43e38db39df4aa2bb184..3453e17204792957f1bfaec26df4a9541fc37ddb 100644 (file)
@@ -72,7 +72,7 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>com.squareup.okhttp</groupId>
+      <groupId>com.squareup.okhttp3</groupId>
       <artifactId>okhttp</artifactId>
       <scope>test</scope>
     </dependency>
index 31f7f48f08f6282d024ddcb5763a1bc335b04cb3..04df2a6d850d10e40a9a50342bca72a461fff591 100644 (file)
@@ -19,9 +19,9 @@
  */
 package org.sonar.process.systeminfo;
 
-import com.squareup.okhttp.OkHttpClient;
-import com.squareup.okhttp.Request;
-import com.squareup.okhttp.Response;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
 import java.io.IOException;
 import java.net.ConnectException;
 import java.util.Arrays;
index 579e4f8d88b767aff00cb724c6ae76dc5cab35ae..b753ff7dd24337be07f000d61bf592d7751bf8f0 100644 (file)
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>com.squareup.okhttp</groupId>
+      <groupId>com.squareup.okhttp3</groupId>
       <artifactId>mockwebserver</artifactId>
       <scope>test</scope>
     </dependency>
index ff3016a7dfcd4b9e24ca2783676e53bd0e384892..8020168d4939a81a7ad3fa8d717491b6264e5a76 100644 (file)
@@ -20,8 +20,8 @@
 package org.sonar.server.platform.monitoring;
 
 import com.google.common.base.Optional;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
 import java.io.File;
 import okio.Buffer;
 import org.junit.Before;
index f5f22cd911e5b0d471843718f494e1aea488bfd2..e184fd3629279709e92c98471330de9340618170 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.scanner.report;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Throwables;
 import com.google.common.io.Files;
-import com.squareup.okhttp.HttpUrl;
+import okhttp3.HttpUrl;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
index 89ae90492604c6e89aafb0792de82bc5648957c8..8fb927c62059982ad9f2575c053efa0f4d1cf5a5 100644 (file)
@@ -45,9 +45,9 @@ public class BatchWsClientProviderTest {
     assertThat(client.baseUrl()).isEqualTo("http://localhost:9000/");
     HttpConnector httpConnector = (HttpConnector) client.wsConnector();
     assertThat(httpConnector.baseUrl()).isEqualTo("http://localhost:9000/");
-    assertThat(httpConnector.okHttpClient().getProxy()).isNull();
-    assertThat(httpConnector.okHttpClient().getConnectTimeout()).isEqualTo(5_000);
-    assertThat(httpConnector.okHttpClient().getReadTimeout()).isEqualTo(60_000);
+    assertThat(httpConnector.okHttpClient().proxy()).isNull();
+    assertThat(httpConnector.okHttpClient().connectTimeoutMillis()).isEqualTo(5_000);
+    assertThat(httpConnector.okHttpClient().readTimeoutMillis()).isEqualTo(60_000);
     assertThat(httpConnector.userAgent()).isEqualTo("Maven Plugin/2.3");
   }
 
@@ -65,7 +65,7 @@ public class BatchWsClientProviderTest {
     assertThat(client).isNotNull();
     HttpConnector httpConnector = (HttpConnector) client.wsConnector();
     assertThat(httpConnector.baseUrl()).isEqualTo("https://here/sonarqube/");
-    assertThat(httpConnector.okHttpClient().getProxy()).isNull();
+    assertThat(httpConnector.okHttpClient().proxy()).isNull();
     assertThat(httpConnector.userAgent()).isEqualTo("Maven Plugin/2.3");
   }
 
index 553c52f8314ff476dc91b19b9a841f546c4451b2..bdb55eb31060de4f0e364bb326c24f3578e7421a 100644 (file)
@@ -27,7 +27,7 @@
       <artifactId>guava</artifactId>
     </dependency>
     <dependency>
-      <groupId>com.squareup.okhttp</groupId>
+      <groupId>com.squareup.okhttp3</groupId>
       <artifactId>okhttp</artifactId>
     </dependency>
     <dependency>
@@ -54,7 +54,7 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>com.squareup.okhttp</groupId>
+      <groupId>com.squareup.okhttp3</groupId>
       <artifactId>mockwebserver</artifactId>
       <scope>test</scope>
     </dependency>
index faa1d4e19e3f6acbf6f3f7b3a6c900ac3cf56cde..0e4af282debe709bd4e2766a0d685918355efc5b 100644 (file)
 package org.sonarqube.ws.client;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.squareup.okhttp.Call;
-import com.squareup.okhttp.ConnectionSpec;
-import com.squareup.okhttp.Credentials;
-import com.squareup.okhttp.Headers;
-import com.squareup.okhttp.HttpUrl;
-import com.squareup.okhttp.MediaType;
-import com.squareup.okhttp.MultipartBuilder;
-import com.squareup.okhttp.OkHttpClient;
-import com.squareup.okhttp.Request;
-import com.squareup.okhttp.RequestBody;
-import com.squareup.okhttp.Response;
 import java.io.IOException;
 import java.net.Proxy;
 import java.util.Map;
@@ -38,6 +27,17 @@ import java.util.concurrent.TimeUnit;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import javax.net.ssl.SSLSocketFactory;
+import okhttp3.Call;
+import okhttp3.ConnectionSpec;
+import okhttp3.Credentials;
+import okhttp3.Headers;
+import okhttp3.HttpUrl;
+import okhttp3.MediaType;
+import okhttp3.MultipartBody;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Strings.isNullOrEmpty;
@@ -63,7 +63,7 @@ public class HttpConnector implements WsConnector {
   private final String userAgent;
   private final String credentials;
   private final String proxyCredentials;
-  private final OkHttpClient okHttpClient = new OkHttpClient();
+  private final OkHttpClient okHttpClient;
 
   private HttpConnector(Builder builder, JavaVersion javaVersion) {
     this.baseUrl = HttpUrl.parse(builder.url.endsWith("/") ? builder.url : format("%s/", builder.url));
@@ -78,27 +78,33 @@ public class HttpConnector implements WsConnector {
       // the Basic credentials consider an empty password.
       this.credentials = Credentials.basic(builder.login, nullToEmpty(builder.password));
     }
-
-    if (builder.proxy != null) {
-      this.okHttpClient.setProxy(builder.proxy);
-    }
     // proxy credentials can be used on system-wide proxies, so even if builder.proxy is null
     if (isNullOrEmpty(builder.proxyLogin)) {
       this.proxyCredentials = null;
     } else {
       this.proxyCredentials = Credentials.basic(builder.proxyLogin, nullToEmpty(builder.proxyPassword));
     }
+    this.okHttpClient = buildClient(builder, javaVersion);
+  }
+
+  private static OkHttpClient buildClient(Builder builder, JavaVersion javaVersion) {
+    OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
+    if (builder.proxy != null) {
+      okHttpClientBuilder.proxy(builder.proxy);
+    }
 
-    this.okHttpClient.setConnectTimeout(builder.connectTimeoutMs, TimeUnit.MILLISECONDS);
-    this.okHttpClient.setReadTimeout(builder.readTimeoutMs, TimeUnit.MILLISECONDS);
+    okHttpClientBuilder.connectTimeout(builder.connectTimeoutMs, TimeUnit.MILLISECONDS);
+    okHttpClientBuilder.readTimeout(builder.readTimeoutMs, TimeUnit.MILLISECONDS);
 
     ConnectionSpec tls = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
       .allEnabledTlsVersions()
       .allEnabledCipherSuites()
       .supportsTlsExtensions(true)
       .build();
-    this.okHttpClient.setConnectionSpecs(asList(tls, ConnectionSpec.CLEARTEXT));
-    this.okHttpClient.setSslSocketFactory(createSslSocketFactory(javaVersion));
+    okHttpClientBuilder.connectionSpecs(asList(tls, ConnectionSpec.CLEARTEXT));
+    okHttpClientBuilder.sslSocketFactory(createSslSocketFactory(javaVersion));
+
+    return okHttpClientBuilder.build();
   }
 
   private static SSLSocketFactory createSslSocketFactory(JavaVersion javaVersion) {
@@ -162,14 +168,15 @@ public class HttpConnector implements WsConnector {
     if (parts.isEmpty()) {
       okRequestBuilder.post(RequestBody.create(null, ""));
     } else {
-      MultipartBuilder body = new MultipartBuilder().type(MultipartBuilder.FORM);
+      MultipartBody.Builder bodyBuilder = new MultipartBody.Builder();
+      bodyBuilder.setType(MultipartBody.FORM);
       for (Map.Entry<String, PostRequest.Part> param : parts.entrySet()) {
         PostRequest.Part part = param.getValue();
-        body.addPart(
+        bodyBuilder.addPart(
           Headers.of("Content-Disposition", format("form-data; name=\"%s\"", param.getKey())),
           RequestBody.create(MediaType.parse(part.getMediaType()), part.getFile()));
       }
-      okRequestBuilder.post(body.build());
+      okRequestBuilder.post(bodyBuilder.build());
     }
 
     return doCall(okRequestBuilder.build());
@@ -209,7 +216,7 @@ public class HttpConnector implements WsConnector {
       Response okResponse = call.execute();
       return new OkHttpResponse(okResponse);
     } catch (IOException e) {
-      throw new IllegalStateException("Fail to request " + okRequest.urlString(), e);
+      throw new IllegalStateException("Fail to request " + okRequest.url(), e);
     }
   }
 
index 30217f166811bdf97f07028f8c0cd5e45a2e84ab..c2a6babc7149792b83016cdf47f8ff286a6d43f7 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonarqube.ws.client;
 
-import com.squareup.okhttp.Response;
+import okhttp3.Response;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Reader;
@@ -39,7 +39,7 @@ class OkHttpResponse extends BaseResponse {
 
   @Override
   public String requestUrl() {
-    return okResponse.request().urlString();
+    return okResponse.request().url().toString();
   }
 
   @Override
@@ -52,11 +52,7 @@ class OkHttpResponse extends BaseResponse {
    */
   @Override
   public InputStream contentStream() {
-    try {
-      return okResponse.body().byteStream();
-    } catch (IOException e) {
-      throw fail(e);
-    }
+    return okResponse.body().byteStream();
   }
 
   /**
@@ -66,11 +62,7 @@ class OkHttpResponse extends BaseResponse {
    */
   @Override
   public Reader contentReader() {
-    try {
-      return okResponse.body().charStream();
-    } catch (IOException e) {
-      throw fail(e);
-    }
+    return okResponse.body().charStream();
   }
 
   @Override
index 3df29b0567295f601f06c87a52af76871e734457..96925c0d709baa715b25531bb2f5be030142c878 100644 (file)
  */
 package org.sonarqube.ws.client;
 
-import com.squareup.okhttp.ConnectionSpec;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-import com.squareup.okhttp.mockwebserver.RecordedRequest;
+import okhttp3.ConnectionSpec;
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import okhttp3.mockwebserver.RecordedRequest;
 import java.io.File;
 import java.util.List;
 import javax.net.ssl.SSLSocketFactory;
@@ -36,7 +36,7 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.sonarqube.ws.MediaTypes;
 
-import static com.squareup.okhttp.Credentials.basic;
+import static okhttp3.Credentials.basic;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
@@ -72,8 +72,8 @@ public class HttpConnectorTest {
     WsResponse response = underTest.call(request);
 
     // verify default timeouts on client
-    assertThat(underTest.okHttpClient().getConnectTimeout()).isEqualTo(HttpConnector.DEFAULT_CONNECT_TIMEOUT_MILLISECONDS);
-    assertThat(underTest.okHttpClient().getReadTimeout()).isEqualTo(HttpConnector.DEFAULT_READ_TIMEOUT_MILLISECONDS);
+    assertThat(underTest.okHttpClient().connectTimeoutMillis()).isEqualTo(HttpConnector.DEFAULT_CONNECT_TIMEOUT_MILLISECONDS);
+    assertThat(underTest.okHttpClient().readTimeoutMillis()).isEqualTo(HttpConnector.DEFAULT_READ_TIMEOUT_MILLISECONDS);
 
     // verify response
     assertThat(response.hasContent()).isTrue();
@@ -162,8 +162,8 @@ public class HttpConnectorTest {
       .connectTimeoutMilliseconds(74)
       .build();
 
-    assertThat(underTest.okHttpClient().getReadTimeout()).isEqualTo(42);
-    assertThat(underTest.okHttpClient().getConnectTimeout()).isEqualTo(74);
+    assertThat(underTest.okHttpClient().readTimeoutMillis()).isEqualTo(42);
+    assertThat(underTest.okHttpClient().connectTimeoutMillis()).isEqualTo(74);
   }
 
   @Test
@@ -287,7 +287,7 @@ public class HttpConnectorTest {
 
     assertTlsAndClearTextSpecifications(underTest);
     // enable TLS 1.0, 1.1 and 1.2
-    assertThat(underTest.okHttpClient().getSslSocketFactory()).isNotNull().isInstanceOf(Tls12Java7SocketFactory.class);
+    assertThat(underTest.okHttpClient().sslSocketFactory()).isNotNull().isInstanceOf(Tls12Java7SocketFactory.class);
   }
 
   @Test
@@ -296,11 +296,11 @@ public class HttpConnectorTest {
     underTest = HttpConnector.newBuilder().url(serverUrl).build(javaVersion);
 
     assertTlsAndClearTextSpecifications(underTest);
-    assertThat(underTest.okHttpClient().getSslSocketFactory()).isInstanceOf(SSLSocketFactory.getDefault().getClass());
+    assertThat(underTest.okHttpClient().sslSocketFactory()).isInstanceOf(SSLSocketFactory.getDefault().getClass());
   }
 
   private void assertTlsAndClearTextSpecifications(HttpConnector underTest) {
-    List<ConnectionSpec> connectionSpecs = underTest.okHttpClient().getConnectionSpecs();
+    List<ConnectionSpec> connectionSpecs = underTest.okHttpClient().connectionSpecs();
     assertThat(connectionSpecs).hasSize(2);
 
     // TLS. tlsVersions()==null means all TLS versions