@ThreadSafe public class AmazonHttpClient extends Object
Modifier and Type | Class and Description |
---|---|
static class |
AmazonHttpClient.ExecOneRequestParams
Stateful parameters that are used for executing a single httpClientSettings request.
|
Modifier and Type | Field and Description |
---|---|
private com.amazonaws.ClientConfiguration |
config
Client configuration options, such as proxy httpClientSettings, max retries, etc.
|
static String |
HEADER_SDK_TRANSACTION_ID |
static String |
HEADER_USER_AGENT |
private ConnectionManagerAwareHttpClient |
httpClient
Internal client for sending HTTP requests
|
private static com.amazonaws.http.client.HttpClientFactory<SdkHttpClient> |
httpClientFactory |
private com.amazonaws.http.settings.HttpClientSettings |
httpClientSettings
Client configuration options, such as proxy httpClientSettings, max retries, etc.
|
private com.amazonaws.http.request.HttpRequestFactory<org.apache.http.client.methods.HttpRequestBase> |
httpRequestFactory |
(package private) static org.apache.commons.logging.Log |
log
Logger for more detailed debugging information, that might not be as useful for end users
(ex: HTTP client configuration, etc).
|
private static org.apache.commons.logging.Log |
requestLog
Logger providing detailed information on requests/responses.
|
private com.amazonaws.metrics.RequestMetricCollector |
requestMetricCollector
A request metric collector used specifically for this httpClientSettings client; or null if
there is none.
|
private com.amazonaws.util.ResponseMetadataCache |
responseMetadataCache
Cache of metadata for recently executed requests for diagnostic purposes
|
private int |
timeOffset
The time difference in seconds between this client and AWS.
|
Modifier | Constructor and Description |
---|---|
|
AmazonHttpClient(com.amazonaws.ClientConfiguration config)
Constructs a new AWS client using the specified client configuration options (ex: max retry
attempts, proxy httpClientSettings, etc).
|
|
AmazonHttpClient(com.amazonaws.ClientConfiguration config,
com.amazonaws.metrics.RequestMetricCollector requestMetricCollector)
Constructs a new AWS client using the specified client configuration options (ex: max retry
attempts, proxy httpClientSettings, etc), and request metric collector.
|
|
AmazonHttpClient(com.amazonaws.ClientConfiguration config,
com.amazonaws.metrics.RequestMetricCollector requestMetricCollector,
boolean useBrowserCompatibleHostNameVerifier)
Constructs a new AWS client using the specified client configuration options (ex: max retry
attempts, proxy httpClientSettings, etc), and request metric collector.
|
private |
AmazonHttpClient(com.amazonaws.ClientConfiguration clientConfig,
com.amazonaws.metrics.RequestMetricCollector requestMetricCollector,
com.amazonaws.http.settings.HttpClientSettings httpClientSettings) |
Modifier and Type | Method and Description |
---|---|
private void |
checkInterrupted()
Check if the thread has been interrupted.
|
private void |
checkInterrupted(com.amazonaws.Response<?> response)
Check if the thread has been interrupted.
|
private static String |
createUserAgentString(String existingUserAgentString,
String userAgent)
Appends the given user-agent string to the existing one and returns it.
|
private <T> Future<T> |
doExecute(com.amazonaws.Request<?> request,
com.amazonaws.http.HttpResponseHandler<com.amazonaws.AmazonWebServiceResponse<T>> responseHandler,
ExecutionContext executionContext,
ResultHandler<T> asyncHandler) |
<T> Future<T> |
execute(com.amazonaws.Request<?> request,
com.amazonaws.http.HttpResponseHandler<com.amazonaws.AmazonWebServiceResponse<T>> responseHandler,
ExecutionContext executionContext,
ResultHandler<T> asyncHandler)
Executes the request and returns the result.
|
private <T> Future<T> |
executeHelper(com.amazonaws.Request<?> request,
com.amazonaws.http.HttpResponseHandler<com.amazonaws.AmazonWebServiceResponse<T>> responseHandler,
ExecutionContext executionContext,
List<com.amazonaws.handlers.RequestHandler2> requestHandlers,
ResultHandler<T> asyncHandler)
Internal method to execute the HTTP method given.
|
private <T> Future<T> |
executeOneRequest(com.amazonaws.Request<?> request,
com.amazonaws.http.HttpResponseHandler<com.amazonaws.AmazonWebServiceResponse<T>> responseHandler,
ExecutionContext execContext,
AmazonHttpClient.ExecOneRequestParams execOneParams,
List<com.amazonaws.handlers.RequestHandler2> requestHandlers,
ResultHandler<T> asyncHandler)
Returns the response from executing one httpClientSettings request; or null for retry.
|
protected void |
finalize() |
private com.amazonaws.auth.AWSCredentials |
getCredentialsFromContext(ExecutionContext executionContext)
Returns the credentials from the execution if exists.
|
private <T> com.amazonaws.http.HttpResponseHandler<T> |
getNonNullResponseHandler(com.amazonaws.http.HttpResponseHandler<T> responseHandler)
Ensures the response handler is not null.
|
com.amazonaws.metrics.RequestMetricCollector |
getRequestMetricCollector()
Returns the httpClientSettings client specific request metric collector; or null if there is
none.
|
com.amazonaws.ResponseMetadata |
getResponseMetadataForRequest(com.amazonaws.AmazonWebServiceRequest request)
Returns additional response metadata for an executed request.
|
private RuntimeException |
handleInterruptedException(ExecutionContext executionContext,
InterruptedException e)
Determine if an interrupted exception is caused by the client execution timer interrupting
the current thread or some other task interrupting the thread for another purpose.
|
private void |
mergeQueryParameters(com.amazonaws.Request<?> request,
Map<String,List<String>> params)
Merge query parameters into the given request.
|
private List<com.amazonaws.handlers.RequestHandler2> |
requestHandler2s(com.amazonaws.Request<?> request,
ExecutionContext executionContext) |
private void |
setSdkTransactionId(com.amazonaws.Request<?> request)
Create a client side identifier that will be sent with the initial request and each retry.
|
private void |
setUserAgent(com.amazonaws.Request<?> request)
Sets a User-Agent for the specified request, taking into account any custom data.
|
void |
shutdown()
Shuts down this HTTP client object, releasing any resources that might be held open.
|
public static final String HEADER_USER_AGENT
public static final String HEADER_SDK_TRANSACTION_ID
static final org.apache.commons.logging.Log log
private static final org.apache.commons.logging.Log requestLog
private static final com.amazonaws.http.client.HttpClientFactory<SdkHttpClient> httpClientFactory
private final com.amazonaws.http.request.HttpRequestFactory<org.apache.http.client.methods.HttpRequestBase> httpRequestFactory
private ConnectionManagerAwareHttpClient httpClient
private final com.amazonaws.ClientConfiguration config
private final com.amazonaws.http.settings.HttpClientSettings httpClientSettings
private final com.amazonaws.util.ResponseMetadataCache responseMetadataCache
private final com.amazonaws.metrics.RequestMetricCollector requestMetricCollector
AwsSdkMetrics
private volatile int timeOffset
public AmazonHttpClient(com.amazonaws.ClientConfiguration config)
config
- Configuration options specifying how this client will communicate with AWS (ex:
proxy httpClientSettings, retry count, etc.).public AmazonHttpClient(com.amazonaws.ClientConfiguration config, com.amazonaws.metrics.RequestMetricCollector requestMetricCollector)
config
- Configuration options specifying how this client will communicate with AWS (ex:
proxy httpClientSettings, retry count, etc.).requestMetricCollector
- client specific request metric collector, which takes precedence over the one at
the AWS SDK level; or null if there is none.public AmazonHttpClient(com.amazonaws.ClientConfiguration config, com.amazonaws.metrics.RequestMetricCollector requestMetricCollector, boolean useBrowserCompatibleHostNameVerifier)
config
- Configuration options specifying how this client will communicate with AWS (ex:
proxy httpClientSettings, retry count, etc.).requestMetricCollector
- client specific request metric collector, which takes precedence over the one at
the AWS SDK level; or null if there is none.private AmazonHttpClient(com.amazonaws.ClientConfiguration clientConfig, com.amazonaws.metrics.RequestMetricCollector requestMetricCollector, com.amazonaws.http.settings.HttpClientSettings httpClientSettings)
private static String createUserAgentString(String existingUserAgentString, String userAgent)
public com.amazonaws.ResponseMetadata getResponseMetadataForRequest(com.amazonaws.AmazonWebServiceRequest request)
request
- A previously executed AmazonWebServiceRequest object, whose response metadata is
desired.public <T> Future<T> execute(com.amazonaws.Request<?> request, com.amazonaws.http.HttpResponseHandler<com.amazonaws.AmazonWebServiceResponse<T>> responseHandler, ExecutionContext executionContext, ResultHandler<T> asyncHandler)
request
- The AmazonWebServices request to send to the remote serverresponseHandler
- A response handler to accept a successful response from the remote serverexecutionContext
- Additional information about the context of this web service callasyncHandler
- Handlerprivate <T> com.amazonaws.http.HttpResponseHandler<T> getNonNullResponseHandler(com.amazonaws.http.HttpResponseHandler<T> responseHandler)
responseHandler
- Response handler passed to
execute(com.amazonaws.Request, com.amazonaws.http.HttpResponseHandler, com.amazonaws.services.dynamodbv2.nio.http.ExecutionContext, com.amazonaws.services.dynamodbv2.nio.handlers.ResultHandler)
private <T> Future<T> doExecute(com.amazonaws.Request<?> request, com.amazonaws.http.HttpResponseHandler<com.amazonaws.AmazonWebServiceResponse<T>> responseHandler, ExecutionContext executionContext, ResultHandler<T> asyncHandler) throws InterruptedException
InterruptedException
private RuntimeException handleInterruptedException(ExecutionContext executionContext, InterruptedException e)
executionContext
- e
- ClientExecutionTimeoutException
if the
InterruptedException
was caused by the
ClientExecutionTimer
. Otherwise
re-interrupts the current thread and returns an
AmazonClientException
wrapping an InterruptedException
private void checkInterrupted() throws InterruptedException
InterruptedException
. Long
running tasks should be periodically checked if the current thread has been interrupted and
handle it appropriatelyInterruptedException
- If thread has been interruptedprivate void checkInterrupted(com.amazonaws.Response<?> response) throws InterruptedException
InterruptedException
. Long
running tasks should be periodically checked if the current thread has been interrupted and
handle it appropriatelyresponse
- Response to be closed before returning control to the caller to avoid leaking the
connection.InterruptedException
- If thread has been interruptedprivate void mergeQueryParameters(com.amazonaws.Request<?> request, Map<String,List<String>> params)
private List<com.amazonaws.handlers.RequestHandler2> requestHandler2s(com.amazonaws.Request<?> request, ExecutionContext executionContext)
private <T> Future<T> executeHelper(com.amazonaws.Request<?> request, com.amazonaws.http.HttpResponseHandler<com.amazonaws.AmazonWebServiceResponse<T>> responseHandler, ExecutionContext executionContext, List<com.amazonaws.handlers.RequestHandler2> requestHandlers, ResultHandler<T> asyncHandler) throws InterruptedException
InterruptedException
private com.amazonaws.auth.AWSCredentials getCredentialsFromContext(ExecutionContext executionContext)
private <T> Future<T> executeOneRequest(com.amazonaws.Request<?> request, com.amazonaws.http.HttpResponseHandler<com.amazonaws.AmazonWebServiceResponse<T>> responseHandler, ExecutionContext execContext, AmazonHttpClient.ExecOneRequestParams execOneParams, List<com.amazonaws.handlers.RequestHandler2> requestHandlers, ResultHandler<T> asyncHandler) throws IOException, InterruptedException
IOException
InterruptedException
private void setSdkTransactionId(com.amazonaws.Request<?> request)
private void setUserAgent(com.amazonaws.Request<?> request)
public void shutdown()
protected void finalize() throws Throwable
public com.amazonaws.metrics.RequestMetricCollector getRequestMetricCollector()