Package org.springframework.http.client
Class OkHttp3ClientHttpRequestFactory
- java.lang.Object
- org.springframework.http.client.OkHttp3ClientHttpRequestFactory
- All Implemented Interfaces:
DisposableBean
,AsyncClientHttpRequestFactory
,ClientHttpRequestFactory
public class OkHttp3ClientHttpRequestFactory extends Object implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory, DisposableBean
ClientHttpRequestFactory
implementation that uses OkHttp 3.x to create requests.- Since:
- 4.3
- Author:
- Luciano Leggieri, Arjen Poutsma, Roy Clarkson
Constructor Summary
Constructors Constructor Description OkHttp3ClientHttpRequestFactory()
Create a factory with a defaultOkHttpClient
instance.OkHttp3ClientHttpRequestFactory(okhttp3.OkHttpClient client)
Create a factory with the givenOkHttpClient
instance.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AsyncClientHttpRequest
createAsyncRequest(URI uri, HttpMethod httpMethod)
Create a new asynchronousAsyncClientHttpRequest
for the specified URI and HTTP method.ClientHttpRequest
createRequest(URI uri, HttpMethod httpMethod)
Create a newClientHttpRequest
for the specified URI and HTTP method.void
destroy()
Invoked by the containingBeanFactory
on destruction of a bean.void
setConnectTimeout(int connectTimeout)
Set the underlying connect timeout in milliseconds.void
setReadTimeout(int readTimeout)
Set the underlying read timeout in milliseconds.void
setWriteTimeout(int writeTimeout)
Set the underlying write timeout in milliseconds.
Constructor Detail
OkHttp3ClientHttpRequestFactory
public OkHttp3ClientHttpRequestFactory()
Create a factory with a defaultOkHttpClient
instance.
OkHttp3ClientHttpRequestFactory
public OkHttp3ClientHttpRequestFactory(okhttp3.OkHttpClient client)
Create a factory with the givenOkHttpClient
instance.- Parameters:
client
- the client to use
Method Detail
setReadTimeout
public void setReadTimeout(int readTimeout)
Set the underlying read timeout in milliseconds. A value of 0 specifies an infinite timeout.
setWriteTimeout
public void setWriteTimeout(int writeTimeout)
Set the underlying write timeout in milliseconds. A value of 0 specifies an infinite timeout.
setConnectTimeout
public void setConnectTimeout(int connectTimeout)
Set the underlying connect timeout in milliseconds. A value of 0 specifies an infinite timeout.
createRequest
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod)
Description copied from interface:ClientHttpRequestFactory
Create a newClientHttpRequest
for the specified URI and HTTP method.The returned request can be written to, and then executed by calling
ClientHttpRequest.execute()
.- Specified by:
createRequest
in interfaceClientHttpRequestFactory
- Parameters:
uri
- the URI to create a request forhttpMethod
- the HTTP method to execute- Returns:
- the created request
createAsyncRequest
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod)
Description copied from interface:AsyncClientHttpRequestFactory
Create a new asynchronousAsyncClientHttpRequest
for the specified URI and HTTP method.The returned request can be written to, and then executed by calling
AsyncClientHttpRequest.executeAsync()
.- Specified by:
createAsyncRequest
in interfaceAsyncClientHttpRequestFactory
- Parameters:
uri
- the URI to create a request forhttpMethod
- the HTTP method to execute- Returns:
- the created request
destroy
public void destroy() throws IOException
Description copied from interface:DisposableBean
Invoked by the containingBeanFactory
on destruction of a bean.- Specified by:
destroy
in interfaceDisposableBean
- Throws:
IOException