in src/main/java/com/aliyun/mns/common/http/ServiceClient.java [86:148]
private <T> Future<HttpResponse> sendRequestImpl(RequestMessage request,
ExecutionContext context,
HttpCallback<T> callback)
throws ClientException, ServiceException {
RetryStrategy retryStrategy = context.getRetryStrategy() != null ? context
.getRetryStrategy() : this.getDefaultRetryStrategy();
// Sign the request if a signer is provided.
if (context.getSigner() != null) {
context.getSigner().sign(request);
}
int retries = 0;
ResponseMessage response = null;
InputStream content = request.getContent();
if (content != null && content.markSupported()) {
content.mark(DEFAULT_MARK_LIMIT);
}
while (true) {
try {
if (retries > 0) {
pause(retries, retryStrategy, callback.getUserRequestId());
if (content != null && content.markSupported()) {
content.reset();
}
}
Request httpRequest = buildRequest(request, context);
// post process request
handleRequest(httpRequest, context.getResquestHandlers());
return sendRequestCore(httpRequest, context, callback);
} catch (ServiceException ex) {
// Notice that the response should not be closed in the
// finally block because if the request is successful,
// the response should be returned to the callers.
closeResponseSilently(response);
if (!shouldRetry(ex, request, response, retries, retryStrategy)) {
throw ex;
}
} catch (ClientException ex) {
// Notice that the response should not be closed in the
// finally block because if the request is successful,
// the response should be returned to the callers.
closeResponseSilently(response);
if (!shouldRetry(ex, request, response, retries, retryStrategy)) {
throw ex;
}
} catch (Exception ex) {
// Notice that the response should not be closed in the
// finally block because if the request is successful,
// the response should be returned to the callers.
closeResponseSilently(response);
throw new ClientException(rm.getFormattedString(
"ConnectionError", ex.getMessage()), callback.getUserRequestId(), ex);
} finally {
retries++;
}
}
}