public class OkHttpRequestor extends HttpRequestor
HttpRequestor
implementation that uses OkHttp
v2. You can only use this if your project includes the OkHttp v2 library.
To use OkHttp v3, see OkHttp3Requestor
.
To use this, pass INSTANCE
to the DbxRequestConfig
constructor.
OkHttp3Requestor
Modifier and Type | Class and Description |
---|---|
static class |
OkHttpRequestor.AsyncCallback |
HttpRequestor.Header, HttpRequestor.Response, HttpRequestor.Uploader
Modifier and Type | Field and Description |
---|---|
static OkHttpRequestor |
INSTANCE
A thread-safe instance of
OkHttpRequestor that connects directly
(as opposed to using a proxy). |
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS
Constructor and Description |
---|
OkHttpRequestor(com.squareup.okhttp.OkHttpClient client)
Creates a new instance of this requestor that uses
client for its requests. |
Modifier and Type | Method and Description |
---|---|
protected void |
configureRequest(com.squareup.okhttp.Request.Builder request)
Called beforing building the request and executing it.
|
HttpRequestor.Response |
doGet(String url,
Iterable<HttpRequestor.Header> headers) |
com.squareup.okhttp.OkHttpClient |
getClient()
Returns a clone of the underlying
OkHttpClient used to make requests. |
protected com.squareup.okhttp.Response |
interceptResponse(com.squareup.okhttp.Response response)
Called before returning
Response from a request. |
HttpRequestor.Uploader |
startPost(String url,
Iterable<HttpRequestor.Header> headers) |
HttpRequestor.Uploader |
startPut(String url,
Iterable<HttpRequestor.Header> headers) |
public static final OkHttpRequestor INSTANCE
OkHttpRequestor
that connects directly
(as opposed to using a proxy).public OkHttpRequestor(com.squareup.okhttp.OkHttpClient client)
client
for its requests.
The OkHttpClient
will be cloned to prevent further modification.
NOTE: This constructor will not enable certificate pinning on the client. If you want
certificate pinning, use the default instance, INSTANCE
, or clone the default client
and modify it accordingly:
NOTE: This SDK requires that OkHttp clients do not use same-thread executors for issuing calls. The SDK relies on the assumption that all asynchronous calls will actually be executed asynchronously. Using a same-thread executor for your OkHttp client may result in dead-locks.
OkHttpClient client = OkHttpRequestor.INSTANCE.getClient(); // returns a clone client.setReadTimeout(2, TimeUnit.MINUTES); // ... other modifications HttpRequestor requestor = new OkHttpRequestor(client);
client
- OkHttpClient
to use for requests (will be cloned), never null
IllegalArgumentException
- if client uses a same-thread executor for its dispatcherpublic com.squareup.okhttp.OkHttpClient getClient()
OkHttpClient
used 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.OkHttpClient
used by this requestor.protected void configureRequest(com.squareup.okhttp.Request.Builder request)
This method should be used by subclasses to make any changes or additions to the request before it is issued.
request
- Builder of request to be executedprotected com.squareup.okhttp.Response interceptResponse(com.squareup.okhttp.Response response)
Response
from 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.
response
- OkHttp responsepublic HttpRequestor.Response doGet(String url, Iterable<HttpRequestor.Header> headers) throws IOException
doGet
in class HttpRequestor
IOException
public HttpRequestor.Uploader startPost(String url, Iterable<HttpRequestor.Header> headers) throws IOException
startPost
in class HttpRequestor
IOException
public HttpRequestor.Uploader startPut(String url, Iterable<HttpRequestor.Header> headers) throws IOException
startPut
in class HttpRequestor
IOException