Package org.springframework.http.client
Class OkHttpClientHttpRequestFactory
- java.lang.Object
- org.springframework.http.client.OkHttpClientHttpRequestFactory
- All Implemented Interfaces:
DisposableBean,AsyncClientHttpRequestFactory,ClientHttpRequestFactory
public class OkHttpClientHttpRequestFactory extends Object implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory, DisposableBean
ClientHttpRequestFactoryimplementation that uses OkHttp 2.x to create requests.- Since:
- 4.2
- Author:
- Luciano Leggieri, Arjen Poutsma
- See Also:
OkHttp3ClientHttpRequestFactory
Constructor Summary
Constructors Constructor Description OkHttpClientHttpRequestFactory()Create a factory with a defaultOkHttpClientinstance.OkHttpClientHttpRequestFactory(com.squareup.okhttp.OkHttpClient client)Create a factory with the givenOkHttpClientinstance.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AsyncClientHttpRequestcreateAsyncRequest(URI uri, HttpMethod httpMethod)Create a new asynchronousAsyncClientHttpRequestfor the specified URI and HTTP method.ClientHttpRequestcreateRequest(URI uri, HttpMethod httpMethod)Create a newClientHttpRequestfor the specified URI and HTTP method.voiddestroy()Invoked by the containingBeanFactoryon destruction of a bean.voidsetConnectTimeout(int connectTimeout)Sets the underlying connect timeout in milliseconds.voidsetReadTimeout(int readTimeout)Sets the underlying read timeout in milliseconds.voidsetWriteTimeout(int writeTimeout)Sets the underlying write timeout in milliseconds.
Constructor Detail
OkHttpClientHttpRequestFactory
public OkHttpClientHttpRequestFactory()
Create a factory with a defaultOkHttpClientinstance.
OkHttpClientHttpRequestFactory
public OkHttpClientHttpRequestFactory(com.squareup.okhttp.OkHttpClient client)
Create a factory with the givenOkHttpClientinstance.- Parameters:
client- the client to use
Method Detail
setReadTimeout
public void setReadTimeout(int readTimeout)
Sets the underlying read timeout in milliseconds. A value of 0 specifies an infinite timeout.- See Also:
OkHttpClient.setReadTimeout(long, TimeUnit)
setWriteTimeout
public void setWriteTimeout(int writeTimeout)
Sets the underlying write timeout in milliseconds. A value of 0 specifies an infinite timeout.- See Also:
OkHttpClient.setWriteTimeout(long, TimeUnit)
setConnectTimeout
public void setConnectTimeout(int connectTimeout)
Sets the underlying connect timeout in milliseconds. A value of 0 specifies an infinite timeout.- See Also:
OkHttpClient.setConnectTimeout(long, TimeUnit)
createRequest
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod)
Description copied from interface:ClientHttpRequestFactoryCreate a newClientHttpRequestfor the specified URI and HTTP method.The returned request can be written to, and then executed by calling
ClientHttpRequest.execute().- Specified by:
createRequestin 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:AsyncClientHttpRequestFactoryCreate a new asynchronousAsyncClientHttpRequestfor the specified URI and HTTP method.The returned request can be written to, and then executed by calling
AsyncClientHttpRequest.executeAsync().- Specified by:
createAsyncRequestin 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:DisposableBeanInvoked by the containingBeanFactoryon destruction of a bean.- Specified by:
destroyin interfaceDisposableBean- Throws:
IOException