File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
WordPress/src/main/java/org/wordpress/android/networking Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 1111import java .io .IOException ;
1212import java .util .HashMap ;
1313import java .util .Map ;
14+ import java .util .concurrent .TimeUnit ;
1415
1516import okhttp3 .Call ;
1617import okhttp3 .Callback ;
18+ import okhttp3 .ConnectionPool ;
1719import okhttp3 .Interceptor ;
1820import okhttp3 .MultipartBody ;
1921import okhttp3 .OkHttpClient ;
2224
2325public class GravatarApi {
2426 public static final String API_BASE_URL = "https://api.gravatar.com/v1/" ;
27+ private static final int DEFAULT_TIMEOUT = 15000 ;
2528
2629 public interface GravatarUploadListener {
2730 void onSuccess ();
@@ -31,7 +34,14 @@ public interface GravatarUploadListener {
3134
3235 private static OkHttpClient createClient (final String accessToken ) {
3336 OkHttpClient .Builder httpClientBuilder = new OkHttpClient .Builder ();
34-
37+ // This should help with recovery from the SocketTimeoutException
38+ // https://github.com/square/okhttp/issues/3146#issuecomment-311158567
39+ httpClientBuilder .connectTimeout (DEFAULT_TIMEOUT , TimeUnit .MILLISECONDS )
40+ .retryOnConnectionFailure (true )
41+ .readTimeout (DEFAULT_TIMEOUT , TimeUnit .MILLISECONDS )
42+ .connectionPool (
43+ new ConnectionPool (0 , 1 , TimeUnit .NANOSECONDS )
44+ );
3545 // // uncomment the following line to add logcat logging
3646 // httpClientBuilder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY));
3747
You can’t perform that action at this time.
0 commit comments