Skip to content

Commit a56e829

Browse files
Nicolás HormazábalKarl Rieb
authored andcommitted
Updated OKHttp to v3
1 parent f738c9f commit a56e829

5 files changed

Lines changed: 25 additions & 21 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ dependencies {
7373
compile 'com.fasterxml.jackson.core:jackson-core:2.7.4'
7474

7575
compileOnly 'javax.servlet:servlet-api:2.5'
76-
compileOnly 'com.squareup.okhttp:okhttp:2.7.5'
76+
compileOnly 'com.squareup.okhttp3:okhttp:3.3.1'
7777
compileOnly 'com.google.android:android:4.1.1.4'
7878

7979
testCompile 'org.testng:testng:6.9.10'
8080
testCompile 'org.mockito:mockito-core:1.10.19'
8181
testCompile 'org.openjdk.jmh:jmh-core:1.12'
8282
testCompile 'org.openjdk.jmh:jmh-generator-annprocess:1.12'
83-
testCompile 'com.squareup.okhttp:okhttp:2.7.5'
83+
testCompile 'com.squareup.okhttp3:okhttp:3.3.1'
8484
}
8585

8686
processResources {

examples/android/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ dependencies {
6262
compile 'com.android.support:design:23.1.1'
6363
compile 'com.android.support:recyclerview-v7:23.1.1'
6464
compile 'com.fasterxml.jackson.core:jackson-core:2.7.4'
65+
// picasso 2.5.2 doesn't have OkHttp3 support (although it exists on master). Must use both
66+
// OkHttp v2 and v3 until new picasso release.
6567
compile 'com.squareup.picasso:picasso:2.5.2'
66-
compile 'com.squareup.okhttp:okhttp:2.4.0'
68+
compile 'com.squareup.okhttp:okhttp:2.7.5'
69+
compile 'com.squareup.okhttp3:okhttp:3.3.1'
6770
}
6871

6972
apply plugin: 'com.getkeepsafe.dexcount'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-keep class com.dropbox.core.test.proguard.Main { *** main(...); }
22
-keepattributes SourceFile,LineNumberTable
33

4-
-dontwarn com.squareup.okhttp.**
4+
-dontwarn okhttp3.**
55
-dontwarn com.dropbox**.android.**
66
-dontwarn org.testng.**
77
-dontwarn bsh.**

src/main/java/com/dropbox/core/http/OkHttpRequestor.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.dropbox.core.http;
22

3-
import com.squareup.okhttp.Call;
4-
import com.squareup.okhttp.Headers;
5-
import com.squareup.okhttp.MediaType;
6-
import com.squareup.okhttp.OkHttpClient;
7-
import com.squareup.okhttp.Request;
8-
import com.squareup.okhttp.RequestBody;
9-
import com.squareup.okhttp.internal.Util;
3+
import okhttp3.Call;
4+
import okhttp3.Headers;
5+
import okhttp3.MediaType;
6+
import okhttp3.OkHttpClient;
7+
import okhttp3.Request;
8+
import okhttp3.RequestBody;
9+
import okhttp3.internal.Util;
1010

1111
import java.io.IOException;
1212
import java.util.HashMap;
@@ -37,11 +37,11 @@ public class OkHttpRequestor extends HttpRequestor {
3737
private final OkHttpClient client;
3838

3939
private static OkHttpClient defaultOkHttpClient() {
40-
OkHttpClient client = new OkHttpClient();
41-
client.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
42-
client.setReadTimeout(DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
43-
client.setWriteTimeout(DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
44-
return client;
40+
return new OkHttpClient.Builder()
41+
.connectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
42+
.readTimeout(DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
43+
.writeTimeout(DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
44+
.build();
4545
}
4646

4747
public OkHttpRequestor(OkHttpClient client) {
@@ -56,7 +56,7 @@ public OkHttpClient getClient() {
5656
public Response doGet(String url, Iterable<Header> headers) throws IOException {
5757
Request.Builder builder = new Request.Builder().get().url(url);
5858
toOkHttpHeaders(headers, builder);
59-
com.squareup.okhttp.Response response = client.newCall(builder.build()).execute();
59+
okhttp3.Response response = client.newCall(builder.build()).execute();
6060
Map<String, List<String>> responseHeaders = fromOkHttpHeaders(response.headers());
6161
return new Response(response.code(), response.body().byteStream(), responseHeaders);
6262
}
@@ -120,7 +120,7 @@ public void abort() {
120120

121121
@Override
122122
public Response finish() throws IOException {
123-
com.squareup.okhttp.Response response = call.execute();
123+
okhttp3.Response response = call.execute();
124124
Map<String, List<String>> responseHeaders = fromOkHttpHeaders(response.headers());
125125
return new Response(response.code(), response.body().byteStream(), responseHeaders);
126126
}

src/test/java/com/dropbox/core/ITUtil.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.util.TimeZone;
1212
import java.util.concurrent.TimeUnit;
1313

14-
import com.squareup.okhttp.OkHttpClient;
14+
import okhttp3.OkHttpClient;
1515

1616
import org.testng.annotations.AfterSuite;
1717
import org.testng.annotations.BeforeSuite;
@@ -59,8 +59,9 @@ public static DbxRequestConfig.Builder newRequestConfig() {
5959
}
6060

6161
public static HttpRequestor newOkHttpRequestor() {
62-
OkHttpClient httpClient = OkHttpRequestor.INSTANCE.getClient().clone();
63-
httpClient.setReadTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS);
62+
OkHttpClient httpClient = OkHttpRequestor.INSTANCE.getClient().newBuilder()
63+
.readTimeout(READ_TIMEOUT, TimeUnit.MILLISECONDS)
64+
.build();
6465
return new OkHttpRequestor(httpClient);
6566
}
6667

0 commit comments

Comments
 (0)