Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
Use OkHttp if it is available on the classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
royclarkson committed Jun 24, 2015
1 parent 10f47de commit 1c630fa
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.OkHttpClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
Expand All @@ -49,6 +50,9 @@ public abstract class HttpAccessor {
private static final boolean httpClient43Present =
ClassUtils.isPresent("org.apache.http.impl.client.CloseableHttpClient", HttpAccessor.class.getClassLoader());

private static final boolean okHttpPresent =
ClassUtils.isPresent("com.squareup.okhttp.OkHttpClient", HttpAccessor.class.getClassLoader());

private ClientHttpRequestFactory requestFactory;


Expand All @@ -57,6 +61,9 @@ protected HttpAccessor() {
if (httpClient43Present) {
this.requestFactory = new HttpComponentsClientHttpRequestFactory();
}
else if (okHttpPresent) {
this.requestFactory = new OkHttpClientHttpRequestFactory();
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
this.requestFactory = new SimpleClientHttpRequestFactory();
}
Expand Down

0 comments on commit 1c630fa

Please sign in to comment.