Package com.dropbox.core.http
Class OkHttpRequestor
- java.lang.Object
-
- com.dropbox.core.http.HttpRequestor
-
- com.dropbox.core.http.OkHttpRequestor
-
public class OkHttpRequestor extends HttpRequestor
HttpRequestorimplementation that uses OkHttp v2. You can only use this if your project includes the OkHttp v2 library.To use OkHttp v3, see
OkHttp3Requestor.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOkHttpRequestor.AsyncCallback-
Nested classes/interfaces inherited from class com.dropbox.core.http.HttpRequestor
HttpRequestor.Header, HttpRequestor.Response, HttpRequestor.Uploader
-
-
Field Summary
-
Fields inherited from class com.dropbox.core.http.HttpRequestor
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS
-
-
Constructor Summary
Constructors Constructor Description OkHttpRequestor(com.squareup.okhttp.OkHttpClient client)Creates a new instance of this requestor that usesclientfor its requests.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidconfigureRequest(com.squareup.okhttp.Request.Builder request)Called beforing building the request and executing it.static com.squareup.okhttp.OkHttpClientdefaultOkHttpClient()Returns anOkHttpClientinstance with the default settings for this SDK.HttpRequestor.ResponsedoGet(java.lang.String url, java.lang.Iterable<HttpRequestor.Header> headers)com.squareup.okhttp.OkHttpClientgetClient()Returns a clone of the underlyingOkHttpClientused to make requests.protected com.squareup.okhttp.ResponseinterceptResponse(com.squareup.okhttp.Response response)Called before returningHttpRequestor.Responsefrom a request.HttpRequestor.UploaderstartPost(java.lang.String url, java.lang.Iterable<HttpRequestor.Header> headers)HttpRequestor.UploaderstartPut(java.lang.String url, java.lang.Iterable<HttpRequestor.Header> headers)-
Methods inherited from class com.dropbox.core.http.HttpRequestor
startPostInStreamingMode
-
-
-
-
Constructor Detail
-
OkHttpRequestor
public OkHttpRequestor(com.squareup.okhttp.OkHttpClient client)
Creates a new instance of this requestor that usesclientfor its requests. The client will be cloned to prevent further modification.OkHttpClient client = OkHttpRequestor.defaultOkHttpClient(); // Make modifications, if necessary client.setReadTimeout(2, TimeUnit.MINUTES); ... HttpRequestor requestor = new OkHttpRequestor(client);
If you don't use
defaultOkHttpClient(), make sure to use Dropbox's hardened SSL settings fromSSLConfig:client.setSslSocketFactory(SSLConfig.getSSLSocketFactory())
-
-
Method Detail
-
defaultOkHttpClient
public static com.squareup.okhttp.OkHttpClient defaultOkHttpClient()
Returns anOkHttpClientinstance with the default settings for this SDK.
-
getClient
public com.squareup.okhttp.OkHttpClient getClient()
Returns a clone of the underlyingOkHttpClientused to make requests. If you want to modify the client for a particular request, create a new instance of this requestor with the modified client.- Returns:
- clone of the underlying
OkHttpClientused by this requestor.
-
configureRequest
protected void configureRequest(com.squareup.okhttp.Request.Builder request)
Called beforing building the request and executing it.This method should be used by subclasses to make any changes or additions to the request before it is issued.
- Parameters:
request- Builder of request to be executed
-
interceptResponse
protected com.squareup.okhttp.Response interceptResponse(com.squareup.okhttp.Response response)
Called before returningHttpRequestor.Responsefrom a request.This method should be used by subclasses to add any logging, analytics, or cleanup necessary.
If the response body is consumed, it should be replaced.
- Parameters:
response- OkHttp response- Returns:
- OkHttp response
-
doGet
public HttpRequestor.Response doGet(java.lang.String url, java.lang.Iterable<HttpRequestor.Header> headers) throws java.io.IOException
- Specified by:
doGetin classHttpRequestor- Throws:
java.io.IOException
-
startPost
public HttpRequestor.Uploader startPost(java.lang.String url, java.lang.Iterable<HttpRequestor.Header> headers) throws java.io.IOException
- Specified by:
startPostin classHttpRequestor- Throws:
java.io.IOException
-
startPut
public HttpRequestor.Uploader startPut(java.lang.String url, java.lang.Iterable<HttpRequestor.Header> headers) throws java.io.IOException
- Specified by:
startPutin classHttpRequestor- Throws:
java.io.IOException
-
-