HttpClientBuilder 。
@Contract(threading=SAFE_CONDITIONAL) @Deprecated public abstract class AbstractHttpClient extends CloseableHttpClient
HttpClient实现的基类。
该类作为一些特殊目的处理程序或策略实现的门面,负责处理HTTP协议的特定方面,例如重定向或身份验证处理或决定连接持久性并保持活动持续时间。
这使得用户能够选择性地将这些方面的默认实现替换为具有特定应用程序的那些方面。
这个类还提供了工厂方法来实例化这些对象:
HttpRequestExecutor用于通过HTTP连接传输消息的对象。 createRequestExecutor()必须由具体的超类来实现这个对象。 BasicHttpProcessor对象管理协议拦截器列表,并将交叉协议逻辑应用于所有传入和传出的HTTP消息。 createHttpProcessor()必须由具体的超类来实现这个对象。 HttpRequestRetryHandler用于确定失败的HTTP请求是否安全自动重试的对象。 createHttpRequestRetryHandler()必须由具体的超类来实现这个对象。 ClientConnectionManager用于管理持久HTTP连接的对象。 ConnectionReuseStrategy对象,用于决定HTTP连接是否可以保持活动并重新用于后续HTTP请求。 createConnectionReuseStrategy()必须由具体的超类实现来实例化此对象。 ConnectionKeepAliveStrategy对象用于确定持久HTTP连接可以保持多长时间。 createConnectionKeepAliveStrategy()必须由具体的超类来实现这个对象。 CookieSpecRegistry对象用于维护支持的cookie规范列表。 createCookieSpecRegistry()必须由具体的超类来实现这个对象。 CookieStore对象用于维护一个cookie的集合。 createCookieStore()必须由具体的超类来实现这个对象。 AuthSchemeRegistry对象用于维护支持的认证方案列表。 createAuthSchemeRegistry()必须由具体的超类来实现这个对象。 CredentialsProvider对象用于维护收集用户凭据。 createCredentialsProvider()必须由具体的超类来实现这个对象。 AuthenticationStrategy对象用于对目标主机进行身份验证。 createTargetAuthenticationStrategy()必须由具体的超类来实现这个对象。 AuthenticationStrategy用于对代理主机进行身份验证的对象。 createProxyAuthenticationStrategy()必须由具体的超类实现来实例化这个对象。 HttpRoutePlanner用于计算用于建立与目标主机的连接的路由的对象。 该路由可能涉及多个中间跳。 createHttpRoutePlanner()必须由具体的超类来实现这个对象。 RedirectStrategy对象用于确定是否应将HTTP请求重定向到新位置以响应从目标服务器接收到的HTTP响应。 UserTokenHandler用于确定执行上下文是否具有用户身份的对象。 createUserTokenHandler()必须由具体的超类实现来实例化这个对象。 该类还保留了用于处理传出请求和传入响应的协议拦截器列表,并提供了管理这些拦截器的方法。 如果需要,可以将新的协议拦截器引入协议处理器链,或者从协议处理器链中删除。 内部协议拦截器存储在一个简单的ArrayList中 。 它们以与添加到列表中相同的自然顺序执行。
AbstractHttpClient是线程安全的。 建议将此类的同一个实例重复用于多个请求执行。 当DefaultHttpClient的实例不再需要并且即将超出范围时,与之关联的连接管理器必须通过调用ClientConnectionManager.shutdown()关闭!
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractHttpClient(ClientConnectionManager conman, HttpParams params)
已过时。
创建一个新的HTTP客户端。
|
protected AbstractHttpClient(ClientConnectionManager conman, HttpParams params)
conman - 连接管理器
params - 参数
protected abstract HttpParams createHttpParams()
protected abstract BasicHttpProcessor createHttpProcessor()
protected HttpContext createHttpContext()
protected ClientConnectionManager createClientConnectionManager()
protected AuthSchemeRegistry createAuthSchemeRegistry()
protected CookieSpecRegistry createCookieSpecRegistry()
protected HttpRequestExecutor createRequestExecutor()
protected ConnectionReuseStrategy createConnectionReuseStrategy()
protected ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy()
protected HttpRequestRetryHandler createHttpRequestRetryHandler()
@Deprecated protected RedirectHandler createRedirectHandler()
protected AuthenticationStrategy createTargetAuthenticationStrategy()
@Deprecated protected AuthenticationHandler createTargetAuthenticationHandler()
protected AuthenticationStrategy createProxyAuthenticationStrategy()
@Deprecated protected AuthenticationHandler createProxyAuthenticationHandler()
protected CookieStore createCookieStore()
protected CredentialsProvider createCredentialsProvider()
protected HttpRoutePlanner createHttpRoutePlanner()
protected UserTokenHandler createUserTokenHandler()
public final HttpParams getParams()
HttpClient复制
public void setParams(HttpParams params)
params - 新的默认参数
public final ClientConnectionManager getConnectionManager()
HttpClient复制
public final HttpRequestExecutor getRequestExecutor()
public final AuthSchemeRegistry getAuthSchemes()
public void setAuthSchemes(AuthSchemeRegistry registry)
public final ConnectionBackoffStrategy getConnectionBackoffStrategy()
public void setConnectionBackoffStrategy(ConnectionBackoffStrategy strategy)
public final CookieSpecRegistry getCookieSpecs()
public final BackoffManager getBackoffManager()
public void setBackoffManager(BackoffManager manager)
public void setCookieSpecs(CookieSpecRegistry registry)
public final ConnectionReuseStrategy getConnectionReuseStrategy()
public void setReuseStrategy(ConnectionReuseStrategy strategy)
public final ConnectionKeepAliveStrategy getConnectionKeepAliveStrategy()
public void setKeepAliveStrategy(ConnectionKeepAliveStrategy strategy)
public final HttpRequestRetryHandler getHttpRequestRetryHandler()
public void setHttpRequestRetryHandler(HttpRequestRetryHandler handler)
@Deprecated public final RedirectHandler getRedirectHandler()
@Deprecated public void setRedirectHandler(RedirectHandler handler)
public final RedirectStrategy getRedirectStrategy()
public void setRedirectStrategy(RedirectStrategy strategy)
@Deprecated public final AuthenticationHandler getTargetAuthenticationHandler()
@Deprecated public void setTargetAuthenticationHandler(AuthenticationHandler handler)
public final AuthenticationStrategy getTargetAuthenticationStrategy()
public void setTargetAuthenticationStrategy(AuthenticationStrategy strategy)
@Deprecated public final AuthenticationHandler getProxyAuthenticationHandler()
@Deprecated public void setProxyAuthenticationHandler(AuthenticationHandler handler)
public final AuthenticationStrategy getProxyAuthenticationStrategy()
public void setProxyAuthenticationStrategy(AuthenticationStrategy strategy)
public final CookieStore getCookieStore()
public void setCookieStore(CookieStore cookieStore)
public final CredentialsProvider getCredentialsProvider()
public void setCredentialsProvider(CredentialsProvider credsProvider)
public final HttpRoutePlanner getRoutePlanner()
public void setRoutePlanner(HttpRoutePlanner routePlanner)
public final UserTokenHandler getUserTokenHandler()
public void setUserTokenHandler(UserTokenHandler handler)
protected final BasicHttpProcessor getHttpProcessor()
public int getResponseInterceptorCount()
public HttpResponseInterceptor getResponseInterceptor(int index)
public HttpRequestInterceptor getRequestInterceptor(int index)
public int getRequestInterceptorCount()
public void addResponseInterceptor(HttpResponseInterceptor itcp)
public void addResponseInterceptor(HttpResponseInterceptor itcp, int index)
public void clearResponseInterceptors()
public void removeResponseInterceptorByClass(Class<? extends HttpResponseInterceptor> clazz)
public void addRequestInterceptor(HttpRequestInterceptor itcp)
public void addRequestInterceptor(HttpRequestInterceptor itcp, int index)
public void clearRequestInterceptors()
public void removeRequestInterceptorByClass(Class<? extends HttpRequestInterceptor> clazz)
protected final CloseableHttpResponse doExecute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException
doExecute类
CloseableHttpClient
IOException
ClientProtocolException
@Deprecated protected RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectHandler redirectHandler, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler userTokenHandler, HttpParams params)
@Deprecated protected RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectStrategy redirectStrategy, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler userTokenHandler, HttpParams params)
protected RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectStrategy redirectStrategy, AuthenticationStrategy targetAuthStrategy, AuthenticationStrategy proxyAuthStrategy, UserTokenHandler userTokenHandler, HttpParams params)
protected HttpParams determineParams(HttpRequest req)
ClientParamsStack 。
此方法的默认实现称为CloseableHttpClient.execute(HttpHost,HttpRequest,HttpContext)以获得参数DefaultRequestDirector 。
req - 将执行的请求
public void close()
Copyright © 1999–2017 The Apache Software Foundation. All rights reserved.