}
private <X, Y extends AmazonWebServiceRequest> X invoke(Request<Y> request,
HttpResponseHandler<AmazonWebServiceResponse<X>> responseHandler,
String bucket, String key) {
AmazonWebServiceRequest originalRequest = request.getOriginalRequest();
ExecutionContext executionContext = createExecutionContext(originalRequest);
AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics();
// Binds the request metrics to the current request.
request.setAWSRequestMetrics(awsRequestMetrics);
// Having the ClientExecuteTime defined here is not ideal (for the
// timing measurement should start as close to the top of the call
// stack of the service client method as possible)
// but definitely a safe compromise for S3 at least for now.
// We can incrementally make it more elaborate should the need arise
// for individual method.
awsRequestMetrics.startEvent(Field.ClientExecuteTime);
Response<X> response = null;
try {
for (Entry<String, String> entry : request.getOriginalRequest()
.copyPrivateRequestParameters().entrySet()) {
request.addParameter(entry.getKey(), entry.getValue());
}
request.setTimeOffset(timeOffset);
/*
* The string we sign needs to include the exact headers that we
* send with the request, but the client runtime layer adds the
* Content-Type header before the request is sent if one isn't set,
* so we have to set something here otherwise the request will fail.
*/
if (!request.getHeaders().containsKey(Headers.CONTENT_TYPE)) {
request.addHeader(Headers.CONTENT_TYPE,
"application/x-www-form-urlencoded; charset=utf-8");
}
AWSCredentials credentials = awsCredentialsProvider.getCredentials();
if (originalRequest.getRequestCredentials() != null) {
credentials = originalRequest.getRequestCredentials();
}
executionContext.setSigner(createSigner(request, bucket, key));
executionContext.setCredentials(credentials);
response = client.execute(request, responseHandler,
errorResponseHandler, executionContext);