hacking into http client trying to fix connectivity problem
This commit is contained in:
parent
787b780960
commit
a750f3cb7e
|
@ -33,7 +33,7 @@ import org.mariotaku.restfu.http.mime.Body;
|
||||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||||
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
|
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
|
||||||
import org.mariotaku.twidere.api.twitter.model.ResponseCode;
|
import org.mariotaku.twidere.api.twitter.model.ResponseCode;
|
||||||
import org.mariotaku.twidere.api.twitter.model.TwitterResponseObject;
|
import org.mariotaku.twidere.api.twitter.model.TwitterResponse;
|
||||||
import org.mariotaku.twidere.api.twitter.model.User;
|
import org.mariotaku.twidere.api.twitter.model.User;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -125,8 +125,8 @@ public class TwitterConverterFactory extends RestConverter.SimpleFactory<Twitter
|
||||||
final InputStream stream = body.stream();
|
final InputStream stream = body.stream();
|
||||||
final Object object = parseOrThrow(stream, type);
|
final Object object = parseOrThrow(stream, type);
|
||||||
checkResponse(type, object, httpResponse);
|
checkResponse(type, object, httpResponse);
|
||||||
if (object instanceof TwitterResponseObject) {
|
if (object instanceof TwitterResponse) {
|
||||||
((TwitterResponseObject) object).processResponseHeader(httpResponse);
|
((TwitterResponse) object).processResponseHeader(httpResponse);
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package okhttp3;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import okhttp3.internal.http.HttpEngine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mariotaku on 16/2/13.
|
||||||
|
*/
|
||||||
|
public class RealCallAccessor {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static HttpEngine getHttpEngine(Call call) {
|
||||||
|
if (call instanceof RealCall) {
|
||||||
|
return ((RealCall) call).engine;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -34,14 +34,15 @@ import java.util.List;
|
||||||
|
|
||||||
import okhttp3.Call;
|
import okhttp3.Call;
|
||||||
import okhttp3.Callback;
|
import okhttp3.Callback;
|
||||||
import okhttp3.ConnectionPool;
|
|
||||||
import okhttp3.Headers;
|
import okhttp3.Headers;
|
||||||
import okhttp3.MediaType;
|
import okhttp3.MediaType;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.RealCallAccessor;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
|
import okhttp3.internal.http.HttpEngine;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
import okio.Okio;
|
import okio.Okio;
|
||||||
|
|
||||||
|
@ -303,13 +304,13 @@ public class OkHttpRestClient implements RestHttpClient {
|
||||||
public Response getResponse() throws IOException {
|
public Response getResponse() throws IOException {
|
||||||
if (exception != null) throw exception;
|
if (exception != null) throw exception;
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
if (!call.isCanceled()) {
|
|
||||||
call.cancel();
|
|
||||||
}
|
|
||||||
if (reachedTimeout()) {
|
if (reachedTimeout()) {
|
||||||
ConnectionPool pool = call.client.client.connectionPool();
|
final SocketTimeoutException exception = new SocketTimeoutException("Request timed out after " + timeout + " ms");
|
||||||
pool.evictAll();
|
final HttpEngine httpEngine = RealCallAccessor.getHttpEngine(call.call);
|
||||||
throw new SocketTimeoutException("Request timed out after " + timeout + " ms");
|
if (httpEngine != null) {
|
||||||
|
httpEngine.streamAllocation.connectionFailed(exception);
|
||||||
|
}
|
||||||
|
throw exception;
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Request cancelled");
|
throw new IOException("Request cancelled");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue