类 HttpComponentsClientHttpRequestFactory
- 所有已实现的接口:
cn.taketoday.beans.factory.DisposableBean,ClientHttpRequestFactory
ClientHttpRequestFactory implementation that
uses Apache HttpComponents
HttpClient to create requests.
Allows to use a pre-configured HttpClient instance -
potentially with authentication, HTTP connection pooling, etc.
NOTE: Requires Apache HttpComponents 5.1 or higher.
- 从以下版本开始:
- 4.0
- 作者:
- Oleg Kalnichevski, Arjen Poutsma, Stephane Nicoll, Juergen Hoeller, Harry Yang
-
字段概要
字段修饰符和类型字段说明private longprivate longprivate HttpClientprivate BiFunction<HttpMethod,URI, org.apache.hc.core5.http.protocol.HttpContext> -
构造器概要
构造器构造器说明Create a new instance of theHttpComponentsClientHttpRequestFactorywith a defaultHttpClientbased on system properties.HttpComponentsClientHttpRequestFactory(HttpClient httpClient) Create a new instance of theHttpComponentsClientHttpRequestFactorywith the givenHttpClientinstance. -
方法概要
修饰符和类型方法说明protected org.apache.hc.core5.http.protocol.HttpContextcreateHttpContext(HttpMethod httpMethod, URI uri) Template methods that creates aHttpContextfor the given HTTP method and URI.protected org.apache.hc.core5.http.ClassicHttpRequestcreateHttpUriRequest(HttpMethod httpMethod, URI uri) Create a Commons HttpMethodBase object for the given HTTP method and URI specification.createRequest(URI uri, HttpMethod httpMethod) Create a newClientHttpRequestfor the specified URI and HTTP method.protected RequestConfigcreateRequestConfig(Object client) Create a defaultRequestConfigto use with the given client.voiddestroy()Shutdown hook that closes the underlyingClientConnectionManager's connection pool, if any.Return theHttpClientused for synchronous execution.protected RequestConfigmergeRequestConfig(RequestConfig clientConfig) Merge the givenHttpClient-levelRequestConfigwith the factory-level configuration, if necessary.protected voidpostProcessHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest request) Template method that allows for manipulating theClassicHttpRequestbefore it is returned as part of aHttpComponentsClientHttpRequest.voidsetConnectionRequestTimeout(int connectionRequestTimeout) Set the timeout in milliseconds used when requesting a connection from the connection manager using the underlyingRequestConfig.voidsetConnectionRequestTimeout(Duration connectionRequestTimeout) Set the timeout in milliseconds used when requesting a connection from the connection manager using the underlyingRequestConfig.voidsetConnectTimeout(int connectTimeout) Set the connection timeout for the underlyingRequestConfig.voidsetConnectTimeout(Duration connectTimeout) Set the connection timeout for the underlyingRequestConfig.voidsetHttpClient(HttpClient httpClient) Set theHttpClientused for synchronous execution.voidsetHttpContextFactory(BiFunction<HttpMethod, URI, org.apache.hc.core5.http.protocol.HttpContext> httpContextFactory) Configure a factory to pre-create theHttpContextfor each request.
-
字段详细资料
-
httpClient
-
connectTimeout
private long connectTimeout -
connectionRequestTimeout
private long connectionRequestTimeout -
httpContextFactory
@Nullable private BiFunction<HttpMethod,URI, httpContextFactoryorg.apache.hc.core5.http.protocol.HttpContext>
-
-
构造器详细资料
-
HttpComponentsClientHttpRequestFactory
public HttpComponentsClientHttpRequestFactory()Create a new instance of theHttpComponentsClientHttpRequestFactorywith a defaultHttpClientbased on system properties. -
HttpComponentsClientHttpRequestFactory
Create a new instance of theHttpComponentsClientHttpRequestFactorywith the givenHttpClientinstance.- 参数:
httpClient- the HttpClient instance to use for this request factory
-
-
方法详细资料
-
setHttpClient
Set theHttpClientused for synchronous execution. -
getHttpClient
Return theHttpClientused for synchronous execution. -
setConnectTimeout
public void setConnectTimeout(int connectTimeout) Set the connection timeout for the underlyingRequestConfig. A timeout value of 0 specifies an infinite timeout.Additional properties can be configured by specifying a
RequestConfiginstance on a customHttpClient.This options does not affect connection timeouts for SSL handshakes or CONNECT requests; for that, it is required to use the
SocketConfigon theHttpClientitself.- 参数:
connectTimeout- the timeout value in milliseconds- 另请参阅:
-
ConnectionConfig.getConnectTimeout()SocketConfig.getSoTimeout()
-
setConnectTimeout
Set the connection timeout for the underlyingRequestConfig. A timeout value of 0 specifies an infinite timeout.Additional properties can be configured by specifying a
RequestConfiginstance on a customHttpClient.This options does not affect connection timeouts for SSL handshakes or CONNECT requests; for that, it is required to use the
SocketConfigon theHttpClientitself.- 参数:
connectTimeout- the timeout value in milliseconds- 另请参阅:
-
ConnectionConfig.getConnectTimeout()SocketConfig.getSoTimeout()
-
setConnectionRequestTimeout
public void setConnectionRequestTimeout(int connectionRequestTimeout) Set the timeout in milliseconds used when requesting a connection from the connection manager using the underlyingRequestConfig. A timeout value of 0 specifies an infinite timeout.Additional properties can be configured by specifying a
RequestConfiginstance on a customHttpClient.- 参数:
connectionRequestTimeout- the timeout value to request a connection in milliseconds- 另请参阅:
-
setConnectionRequestTimeout
Set the timeout in milliseconds used when requesting a connection from the connection manager using the underlyingRequestConfig. A timeout value of 0 specifies an infinite timeout.Additional properties can be configured by specifying a
RequestConfiginstance on a customHttpClient.- 参数:
connectionRequestTimeout- the timeout value to request a connection in milliseconds- 另请参阅:
-
setHttpContextFactory
public void setHttpContextFactory(BiFunction<HttpMethod, URI, org.apache.hc.core5.http.protocol.HttpContext> httpContextFactory) Configure a factory to pre-create theHttpContextfor each request.This may be useful for example in mutual TLS authentication where a different
RestTemplatefor each client certificate such that all calls made through a givenRestTemplateinstance as associated for the same client identity.HttpClientContext.setUserToken(Object)can be used to specify a fixed user token for all requests.- 参数:
httpContextFactory- the context factory to use
-
createRequest
从接口复制的说明:ClientHttpRequestFactoryCreate a newClientHttpRequestfor the specified URI and HTTP method.The returned request can be written to, and then executed by calling
ClientHttpRequest.execute().- 指定者:
createRequest在接口中ClientHttpRequestFactory- 参数:
uri- the URI to create a request forhttpMethod- the HTTP method to execute- 返回:
- the created request
- 抛出:
IOException- in case of I/O errors
-
createRequestConfig
Create a defaultRequestConfigto use with the given client. Can returnnullto indicate that no custom request config should be set and the defaults of theHttpClientshould be used.The default implementation tries to merge the defaults of the client with the local customizations of this factory instance, if any.
- 参数:
client- theHttpClient(orHttpAsyncClient) to check- 返回:
- the actual RequestConfig to use (may be
null) - 另请参阅:
-
mergeRequestConfig
Merge the givenHttpClient-levelRequestConfigwith the factory-level configuration, if necessary.- 参数:
clientConfig- the config held by the current- 返回:
- the merged request config
-
createHttpUriRequest
protected org.apache.hc.core5.http.ClassicHttpRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) Create a Commons HttpMethodBase object for the given HTTP method and URI specification.- 参数:
httpMethod- the HTTP methoduri- the URI- 返回:
- the Commons HttpMethodBase object
-
postProcessHttpRequest
protected void postProcessHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest request) Template method that allows for manipulating theClassicHttpRequestbefore it is returned as part of aHttpComponentsClientHttpRequest.The default implementation is empty.
- 参数:
request- the request to process
-
createHttpContext
@Nullable protected org.apache.hc.core5.http.protocol.HttpContext createHttpContext(HttpMethod httpMethod, URI uri) Template methods that creates aHttpContextfor the given HTTP method and URI.The default implementation returns
null.- 参数:
httpMethod- the HTTP methoduri- the URI- 返回:
- the http context
-
destroy
Shutdown hook that closes the underlyingClientConnectionManager's connection pool, if any.- 指定者:
destroy在接口中cn.taketoday.beans.factory.DisposableBean- 抛出:
Exception
-