类 HttpClient
java.lang.Object
com.baidu.mochow.http.HttpClient
-
字段概要
字段修饰符和类型字段说明protected ClientConfigurationClient configuration options, such as proxy settings, max retries, etc.protected org.apache.http.impl.nio.client.CloseableHttpAsyncClientInternal async client for sending HTTP requestsprotected org.apache.http.impl.client.CloseableHttpClientInternal client for sending HTTP requestsprotected Signer -
构造器概要
构造器构造器说明HttpClient(ClientConfiguration config, Signer signer) Constructs a new Mochow client using the specified client configuration options (ex: max retry attempts, proxy settings, etc), and request metric collector.HttpClient(ClientConfiguration config, Signer signer, boolean isHttpAsyncPutEnabled) Constructs a new Mochow Http Client with httpAsyncPutEnabled. -
方法概要
修饰符和类型方法说明protected org.apache.http.impl.nio.client.CloseableHttpAsyncClientcreateHttpAsyncClient(org.apache.http.nio.conn.NHttpClientConnectionManager connectionManager) Create asynchronous http client based on connection manager.protected org.apache.http.client.protocol.HttpClientContextcreateHttpContext(InternalRequest request) Creates HttpClient Context object based on the internal request.protected org.apache.http.client.methods.HttpRequestBasecreateHttpRequest(InternalRequest request) Creates HttpClient method object based on the specified request and populates any parameters, headers, etc. from the internal request.protected org.apache.http.nio.conn.NHttpClientConnectionManagerCreate connection manager for asynchronous http client.<T extends AbstractMochowResponse>
Texecute(InternalRequest request, Class<T> responseClass, HttpResponseHandler[] responseHandlers) Executes the request and returns the result.protected longgetDelayBeforeNextRetryInMillis(org.apache.http.client.methods.HttpRequestBase method, MochowClientException exception, int attempt, RetryPolicy retryPolicy) Get delay time before next retry.voidshutdown()Shuts down this HTTP client object, releasing any resources that might be held open.voidThe difference between shutdown() is that releasing all resources including nio and idle.
-
字段详细资料
-
httpClient
protected org.apache.http.impl.client.CloseableHttpClient httpClientInternal client for sending HTTP requests -
httpAsyncClient
protected org.apache.http.impl.nio.client.CloseableHttpAsyncClient httpAsyncClientInternal async client for sending HTTP requests -
config
Client configuration options, such as proxy settings, max retries, etc. -
signer
-
-
构造器详细资料
-
HttpClient
Constructs a new Mochow client using the specified client configuration options (ex: max retry attempts, proxy settings, etc), and request metric collector.- 参数:
config- Configuration options specifying how this client will communicate with Mochow (ex: proxy settings, retry count, etc.).signer- signer used to sign http requests- 抛出:
IllegalArgumentException- If config or signer is null.
-
HttpClient
Constructs a new Mochow Http Client with httpAsyncPutEnabled.- 参数:
config- Configuration options specifying how this client will communicate with Mochow (ex: proxy settings, retry count, etc.).signer- signer used to sign http requestsisHttpAsyncPutEnabled- whether use Async for PUT method.
-
-
方法详细资料
-
execute
public <T extends AbstractMochowResponse> T execute(InternalRequest request, Class<T> responseClass, HttpResponseHandler[] responseHandlers) Executes the request and returns the result.- 类型参数:
T- The type of response- 参数:
request- The Mochow request to send to the remote serverresponseClass- A response handler to accept a successful response from the remote serverresponseHandlers- A response handler to accept an unsuccessful response from the remote server- 返回:
- The response from the remote server
- 抛出:
MochowClientException- If any errors are encountered on the client while making the request or handling the response.MochowServiceException- If any errors occurred in Mochow while processing the request.
-
shutdown
public void shutdown()Shuts down this HTTP client object, releasing any resources that might be held open. This is an optional method, and callers are not expected to call it, but can if they want to explicitly release any open resources. Once a client has been shutdown, it cannot be used to make more requests. -
shutdownClean
public void shutdownClean()The difference between shutdown() is that releasing all resources including nio and idle. -
getDelayBeforeNextRetryInMillis
protected long getDelayBeforeNextRetryInMillis(org.apache.http.client.methods.HttpRequestBase method, MochowClientException exception, int attempt, RetryPolicy retryPolicy) Get delay time before next retry.- 参数:
method- The current HTTP method being executed.exception- The client/service exception from the failed request.attempt- The number of times the current request has been attempted.retryPolicy- The retryPolicy being used.- 返回:
- The deley time before next retry.
-
createNHttpClientConnectionManager
protected org.apache.http.nio.conn.NHttpClientConnectionManager createNHttpClientConnectionManager() throws org.apache.http.nio.reactor.IOReactorExceptionCreate connection manager for asynchronous http client.- 返回:
- Connection manager for asynchronous http client.
- 抛出:
org.apache.http.nio.reactor.IOReactorException- in case if a non-recoverable I/O error.
-
createHttpAsyncClient
protected org.apache.http.impl.nio.client.CloseableHttpAsyncClient createHttpAsyncClient(org.apache.http.nio.conn.NHttpClientConnectionManager connectionManager) Create asynchronous http client based on connection manager.- 参数:
connectionManager- Asynchronous http client connection manager.- 返回:
- Asynchronous http client based on connection manager.
-
createHttpRequest
Creates HttpClient method object based on the specified request and populates any parameters, headers, etc. from the internal request.- 参数:
request- The request to convert to an HttpClient method object.- 返回:
- The converted HttpClient method object with any parameters, headers, etc. from the original request set.
-
createHttpContext
protected org.apache.http.client.protocol.HttpClientContext createHttpContext(InternalRequest request) Creates HttpClient Context object based on the internal request.- 参数:
request- The internal request.- 返回:
- HttpClient Context object.
-