public class OkHttp3Requestor extends HttpRequestor
HttpRequestor
implementation that uses OkHttp
v3. You can only use this if your project includes the OkHttp v3 library.
To use this, pass INSTANCE
to the DbxRequestConfig
constructor.
Modifier and Type | Class and Description |
---|---|
static class |
OkHttp3Requestor.AsyncCallback |
HttpRequestor.Header, HttpRequestor.Response, HttpRequestor.Uploader
Modifier and Type | Field and Description |
---|---|
static OkHttp3Requestor |
INSTANCE
A thread-safe instance of
OkHttp3Requestor that connects directly
(as opposed to using a proxy). |
DEFAULT_CONNECT_TIMEOUT_MILLIS, DEFAULT_READ_TIMEOUT_MILLIS
Constructor and Description |
---|
OkHttp3Requestor(okhttp3.OkHttpClient client)
Creates a new instance of this requestor that uses
client for its requests. |
Modifier and Type | Method and Description |
---|---|
protected void |
configureRequest(okhttp3.Request.Builder request)
Called beforing building the request and executing it.
|
HttpRequestor.Response |
doGet(String url,
Iterable<HttpRequestor.Header> headers) |
okhttp3.OkHttpClient |
getClient()
Returns the underlying
OkHttpClient used to make requests. |
protected okhttp3.Response |
interceptResponse(okhttp3.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 OkHttp3Requestor INSTANCE
OkHttp3Requestor
that connects directly
(as opposed to using a proxy).public OkHttp3Requestor(okhttp3.OkHttpClient client)
client
for its requests.
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() .readTimeout(2, TimeUnit.MINUTES) // ... other modifications .build(); HttpRequestor requestor = new OkHttpRequestor(client);
client
- OkHttpClient
to use for requests, never null
IllegalArgumentException
- if client uses a same-thread executor for its dispatcherpublic okhttp3.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(okhttp3.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 okhttp3.Response interceptResponse(okhttp3.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