public class OkHttp3ClientHttpRequestFactory extends java.lang.Object implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory, DisposableBean
ClientHttpRequestFactory
implementation that uses
OkHttp 3.x to create requests.Modifier and Type | Field and Description |
---|---|
private OkHttpClient |
client |
private boolean |
defaultClient |
Constructor and Description |
---|
OkHttp3ClientHttpRequestFactory()
Create a factory with a default
OkHttpClient instance. |
OkHttp3ClientHttpRequestFactory(OkHttpClient client)
Create a factory with the given
OkHttpClient instance. |
Modifier and Type | Method and Description |
---|---|
(package private) static Request |
buildRequest(HttpHeaders headers,
byte[] content,
java.net.URI uri,
HttpMethod method) |
AsyncClientHttpRequest |
createAsyncRequest(java.net.URI uri,
HttpMethod httpMethod)
Create a new asynchronous
AsyncClientHttpRequest for the specified URI
and HTTP method. |
ClientHttpRequest |
createRequest(java.net.URI uri,
HttpMethod httpMethod)
Create a new
ClientHttpRequest for the specified URI and HTTP method. |
void |
destroy()
Invoked by a BeanFactory on destruction of a singleton.
|
private static okhttp3.MediaType |
getContentType(HttpHeaders headers) |
void |
setConnectTimeout(int connectTimeout)
Sets the underlying connect timeout in milliseconds.
|
void |
setReadTimeout(int readTimeout)
Sets the underlying read timeout in milliseconds.
|
void |
setWriteTimeout(int writeTimeout)
Sets the underlying write timeout in milliseconds.
|
public OkHttp3ClientHttpRequestFactory()
OkHttpClient
instance.public OkHttp3ClientHttpRequestFactory(OkHttpClient client)
OkHttpClient
instance.client
- the client to usepublic void setReadTimeout(int readTimeout)
OkHttpClient.Builder#readTimeout(long, TimeUnit)
public void setWriteTimeout(int writeTimeout)
OkHttpClient.Builder#writeTimeout(long, TimeUnit)
public void setConnectTimeout(int connectTimeout)
OkHttpClient.Builder#connectTimeout(long, TimeUnit)
public ClientHttpRequest createRequest(java.net.URI uri, HttpMethod httpMethod)
ClientHttpRequestFactory
ClientHttpRequest
for the specified URI and HTTP method.
The returned request can be written to, and then executed by calling
ClientHttpRequest.execute()
.
createRequest
in interface ClientHttpRequestFactory
uri
- the URI to create a request forhttpMethod
- the HTTP method to executepublic AsyncClientHttpRequest createAsyncRequest(java.net.URI uri, HttpMethod httpMethod)
AsyncClientHttpRequestFactory
AsyncClientHttpRequest
for the specified URI
and HTTP method.
The returned request can be written to, and then executed by calling
AsyncClientHttpRequest.executeAsync()
.
createAsyncRequest
in interface AsyncClientHttpRequestFactory
uri
- the URI to create a request forhttpMethod
- the HTTP method to executepublic void destroy() throws java.io.IOException
DisposableBean
destroy
in interface DisposableBean
java.io.IOException
static Request buildRequest(HttpHeaders headers, byte[] content, java.net.URI uri, HttpMethod method) throws java.net.MalformedURLException
java.net.MalformedURLException
@Nullable private static okhttp3.MediaType getContentType(HttpHeaders headers)