ProgressListener listener = awsreq.getGeneralProgressListener();
try {
/*
* Apply the byte counting stream wrapper if the legacy runtime profiling is enabled.
*/
CountingInputStream countingInputStream = null;
InputStream is = httpResponse.getContent();
if (is != null) {
if (System.getProperty(PROFILING_SYSTEM_PROPERTY) != null) {
is = countingInputStream = new CountingInputStream(is);
httpResponse.setContent(is);
}
httpResponse.setContent(
ProgressInputStream.inputStreamForResponse(is, awsreq));
}
Map<String,String> headers = httpResponse.getHeaders();
String s = headers.get("Content-Length");
if (s != null) {
try {
long contentLength = Long.parseLong(s);
publishResponseContentLength(listener, contentLength);
} catch (NumberFormatException e) {
log.warn("Cannot parse the Content-Length header of the response.");
}
}
AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics();
AmazonWebServiceResponse<? extends T> awsResponse;
awsRequestMetrics.startEvent(Field.ResponseProcessingTime);
publishProgress(listener, ProgressEventType.HTTP_RESPONSE_STARTED_EVENT);
try {
awsResponse = responseHandler.handle(httpResponse);
} finally {
awsRequestMetrics.endEvent(Field.ResponseProcessingTime);
}
publishProgress(listener, ProgressEventType.HTTP_RESPONSE_COMPLETED_EVENT);
if (countingInputStream != null) {
awsRequestMetrics.setCounter(Field.BytesProcessed, countingInputStream.getByteCount());
}
if (awsResponse == null)
throw new RuntimeException("Unable to unmarshall response metadata. Response Code: " +
httpResponse.getStatusCode() + ", Response Text: " + httpResponse.getStatusText());