Can I use Stetho with Spring RestTemplate for Android?

175 Views Asked by At

Facebook's stetho seems to only have great support for OKHTTP and very little for all the other networking frameworks for Android: http://facebook.github.io/stetho/#integrations

I'm using Spring RestTemplate and I'm wondering how I can get stetho to play nicely with Spring. I do know I can use OKHTTP with Spring Resttemplate but I prefer to keep my app small and would like to avoid adding an extra networking library to my app:

http://docs.spring.io/autorepo/docs/spring-android/2.0.0.BUILD-SNAPSHOT/reference/html/rest-template.html

An additional ClientHttpRequestFactory based on OkHttp is available as an alternative to the two native clients. RestTemplate can be configured to use OkHttpRequestFactory through the RestTemplate constructor or by setting the requestFactory property. It is supported on Android 2.3 (Gingerbread) and newer, however in order to use it, you must include the OkHttp dependency in your project.

It appears my Spring RestTemplate uses HttpURLConnection to make its calls and there appears to be instructions on how to make stetho work with HttpURLConnection but the instructions are quite brief:

If you are using HttpURLConnection, you can use StethoURLConnectionManager to assist with integration though you should be aware that there are some caveats with this approach. In particular, you must explicitly add Accept-Encoding: gzip to the request headers and manually handle compressed responses in order for Stetho to report compressed payload sizes.

However, I'm concerned the instructions above will not work in my case as I use a clienthttprequestinterceptorto send my request and add on an authorisation header before it is sent. This causes the GZIP compression to occur twice according to this thread:

RestTemplate with ClientHttpRequestInterceptor causes GZIP compression twice

Has anyone successfully used stetho with Spring RestTemplate for Android? For now, a workaround is to use Charles Proxy (paid alternative) to detect all the network calls instead of stetho.

0

There are 0 best solutions below