Как отладить «com.android.okhttp»
В android kitkat реализация URLConnection была заменена на OkHttp. Как это можно отладить?
OkHttp находится в этом каталоге:external/okhttp/android/main/java/com/squareup/okhttp
Когда я звонюUrlInstance.openConnection().getClass().getName()
, оно настоящееcom.android.okhttp.internal.http.HttpURLConnectionImpl
Как я могу отладить его? Кажется, я не могу связать/android/main/java/com/squareup/okhttp/*
кcom.android.okhttp.*
Когда код оправдываетreturn streamHandler.openConnection(this);
/**
* Returns a new connection to the resource referred to by this URL.
*
* @throws IOException if an error occurs while opening the connection.
*/
public URLConnection openConnection() throws IOException {
return streamHandler.openConnection(this);
}
Идите дальше, но не можете копаться вcom.squareup.okhttp.HttpHandler#openConnection
Выделенная нить в отладчике на рисунке ниже серого цвета.
package com.squareup.okhttp;
import java.io.IOException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
public class HttpHandler extends URLStreamHandler {
@Override protected URLConnection openConnection(URL url) throws IOException {
return newOkHttpClient(null /* proxy */).open(url);
}
@Override protected URLConnection openConnection(URL url, Proxy proxy) throws IOException {
if (url == null || proxy == null) {
throw new IllegalArgumentException("url == null || proxy == null");
}
return newOkHttpClient(proxy).open(url);
}
@Override protected int getDefaultPort() {
return 80;
}
protected OkHttpClient newOkHttpClient(Proxy proxy) {
OkHttpClient client = new OkHttpClient();
client.setFollowProtocolRedirects(false);
if (proxy != null) {
client.setProxy(proxy);
}
return client;
}
}