Closed Maragues closed 10 years ago
Not really something I can do about in the code as it's part of the framework.
However I'm thinking in adding support for OkHttp if it's in your project. (the same way picasso does) Aka if OkHttp is bundled in your app as a library, it will be used over HttpUrlConnection.
That'd be great!
I'm getting a new error under StrictMode which might be related
05-30 13:54:10.687: E/StrictMode(4344): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
05-30 13:54:10.687: E/StrictMode(4344): java.lang.Throwable: Explicit termination method 'close' not called
05-30 13:54:10.687: E/StrictMode(4344): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
05-30 13:54:10.687: E/StrictMode(4344): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:272)
05-30 13:54:10.687: E/StrictMode(4344): at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
05-30 13:54:10.687: E/StrictMode(4344): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
05-30 13:54:10.687: E/StrictMode(4344): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
05-30 13:54:10.687: E/StrictMode(4344): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
05-30 13:54:10.687: E/StrictMode(4344): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
05-30 13:54:10.687: E/StrictMode(4344): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:282)
05-30 13:54:10.687: E/StrictMode(4344): at libcore.net.http.HttpURLConnectionImpl.getHeaderField(HttpURLConnectionImpl.java:139)
05-30 13:54:10.687: E/StrictMode(4344): at libcore.net.http.HttpsURLConnectionImpl.getHeaderField(HttpsURLConnectionImpl.java:246)
05-30 13:54:10.687: E/StrictMode(4344): at com.foxykeep.datadroid.internal.network.NetworkConnectionImpl.execute(NetworkConnectionImpl.java:233)
05-30 13:54:10.687: E/StrictMode(4344): at com.foxykeep.datadroid.network.NetworkConnection.execute(NetworkConnection.java:241)
05-30 13:54:10.687: E/StrictMode(4344): at com.microhealth.hemophilia.data.operations.alarm.GetAlarmsOperation.execute(GetAlarmsOperation.java:54)
05-30 13:54:10.687: E/StrictMode(4344): at com.foxykeep.datadroid.service.RequestService.onHandleIntent(RequestService.java:148)
05-30 13:54:10.687: E/StrictMode(4344): at com.foxykeep.datadroid.service.MultiThreadedIntentService$IntentRunnable.run(MultiThreadedIntentService.java:170)
05-30 13:54:10.687: E/StrictMode(4344): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
05-30 13:54:10.687: E/StrictMode(4344): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-30 13:54:10.687: E/StrictMode(4344): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-30 13:54:10.687: E/StrictMode(4344): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-30 13:54:10.687: E/StrictMode(4344): at java.lang.Thread.run(Thread.java:856)
05-30 13:54:10.695: W/System.err(4344): StrictMode VmPolicy violation with POLICY_DEATH; shutting down.
Hi Nicolas,
I've integrated OkHttp into DataDroid using reflection, just as Picasso does but in a less elegant way.
Here's the gist with the modified code, I'll make a pull request if you are ok with it (I'd create a separate class for the Factory)
https://gist.github.com/Maragues/6776295
This is the fast way to integrate, but I guess that there's some code that's no longer needed (such as the SSLSocketFactory), but I won't touch it as I'm not confident I won't break anything.
Maybe it'd make more sense to interface the execute call and create an OkHttpConnectionImpl, something similar to Picasso's implementation (https://github.com/square/picasso/blob/master/picasso/src/main/java/com/squareup/picasso/Utils.java)
static Downloader createDefaultDownloader(Context context) {
try {
Class.forName("com.squareup.okhttp.OkHttpClient");
return OkHttpLoaderCreator.create(context);
} catch (ClassNotFoundException e) {
return new UrlConnectionDownloader(context);
}
}
Go for the pull request :)
Nicolas KLEIN aka Foxykeep
On Tue, Oct 1, 2013 at 3:11 AM, Miguel Aragues notifications@github.comwrote:
Hi Nicolas,
I've integrated OkHttp into DataDroid using reflection, just as Picasso does.
Here's the gist with the modified code, I'll make a pull request if you are ok with it (I'd create a separate class for the Factory)
https://gist.github.com/Maragues/6776295
— Reply to this email directly or view it on GitHubhttps://github.com/foxykeep/DataDroid/issues/32#issuecomment-25438183 .
Hi, I'm randomly getting EOFExceptions on some requests. It looks like it's an Android bug related with the HTTP Client and the keep-alive header
https://code.google.com/p/google-http-java-client/issues/detail?id=116
In the comments, its said that the square team fixed it in this commit
https://github.com/square/okhttp/pull/24/files
and here's some discussion on the topic
http://stackoverflow.com/questions/13182519/spring-rest-template-usage-causes-eofexception
I don't know how much work it would be to change the HttpClient or to create a fix, but it's really giving me a headache. If I have time, I may try to create the fix myself. Please let me know if you start working on it.
Thanks!