<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 -->
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;
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;
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;
<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>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.squareup.okhttp</groupId>
+ <groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<scope>test</scope>
</dependency>
*/
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;
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.squareup.okhttp</groupId>
+ <groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
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;
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;
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");
}
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");
}
<artifactId>guava</artifactId>
</dependency>
<dependency>
- <groupId>com.squareup.okhttp</groupId>
+ <groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.squareup.okhttp</groupId>
+ <groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
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;
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;
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));
// 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) {
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());
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);
}
}
*/
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;
@Override
public String requestUrl() {
- return okResponse.request().urlString();
+ return okResponse.request().url().toString();
}
@Override
*/
@Override
public InputStream contentStream() {
- try {
- return okResponse.body().byteStream();
- } catch (IOException e) {
- throw fail(e);
- }
+ return okResponse.body().byteStream();
}
/**
*/
@Override
public Reader contentReader() {
- try {
- return okResponse.body().charStream();
- } catch (IOException e) {
- throw fail(e);
- }
+ return okResponse.body().charStream();
}
@Override
*/
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;
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;
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();
.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
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
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