public static LogRestWarn ( log4net.ILog logger, IRestResponse restResponse, string warnHeading ) : void | ||
logger | log4net.ILog | |
restResponse | IRestResponse | |
warnHeading | string | |
Résultat | void |
public async Task <IRestResponse> RequestAsync(Uri uri, Method method, object body, string contentType, int timeout) { var connectionClosedRetryCounter = 0; IRestResponse response = null; retry: while (connectionClosedRetryCounter < DEFAULT_REQUEST_RETRY_ATTEMPTS) { var request = CreateRequest(uri, method, body, contentType, timeout); var client = CreateClient(); var oldAuth = client.DefaultParameters.FirstOrDefault(x => x.Name == XAuthToken)?.Value as string; response = await client.ExecuteAsync(request); if (response.ResponseStatus == ResponseStatus.Error && response.ErrorException is WebException && ((WebException)response.ErrorException).Status == WebExceptionStatus.KeepAliveFailure) { //retry connectionClosedRetryCounter++; Logger.LogWarning("Request failed due underlying connection closed URL={0}", uri); goto retry; } if (response.StatusCode == HttpStatusCode.Unauthorized) { RestErrorHelper.LogRestWarn(Logger, response, string.Format("Unauthenticated when using authToken={0}", SessionToken)); var authenticated = false; try { await SessionLock.WaitAsync(); if (SessionToken == null || oldAuth == SessionToken) { authenticated = await AuthenticateAsync(response); } else { authenticated = true; } } finally { SessionLock.Release(); } if (authenticated) { connectionClosedRetryCounter++; goto retry; } else { throw new NotAuthenticatedException(string.Format("Not Authenticated for url={0}", uri)); } } connectionClosedRetryCounter = DEFAULT_REQUEST_RETRY_ATTEMPTS; } return(response); }
public IRestResponse Request(Uri uri, Method method, object body, string contentType, int timeout) { var connectionClosedRetryCounter = 0; IRestResponse response = null; while (connectionClosedRetryCounter < DEFAULT_REQUEST_RETRY_ATTEMPTS) { var request = CreateRequest(uri, method, body, contentType, timeout); var client = CreateClient(); var oldAuth = client.DefaultParameters.FirstOrDefault(x => x.Name == XAuthToken); response = client.Execute(request); if (response.ResponseStatus == ResponseStatus.Error && response.ErrorException is WebException && ((WebException)response.ErrorException).Status == WebExceptionStatus.KeepAliveFailure) { //retry connectionClosedRetryCounter++; Logger.WarnFormat("Request failed due underlying connection closed URL={0}", uri); continue; } if (response.StatusCode == HttpStatusCode.Unauthorized) { RestErrorHelper.LogRestWarn(Logger, response, string.Format("Unauthenticated when using authToken={0}", _xAuthTokenParameter != null ? _xAuthTokenParameter.Value : String.Empty)); var authenticated = false; lock (sysLock) { if (_xAuthTokenParameter == null || oldAuth == _xAuthTokenParameter) { authenticated = Authenticate(response); } else { authenticated = true; } } if (authenticated) { request = CreateRequest(uri, method, body, contentType, timeout); response = CreateClient().Execute(request); if (response.ResponseStatus == ResponseStatus.Error && response.ErrorException is WebException && ((WebException)response.ErrorException).Status == WebExceptionStatus.KeepAliveFailure) { //retry connectionClosedRetryCounter++; Logger.WarnFormat("Request failed due underlying connection closed URL={0}", uri); continue; } } else { throw new NotAuthenticatedException(string.Format("Not Authenticated for url={0}", uri)); } } connectionClosedRetryCounter = DEFAULT_REQUEST_RETRY_ATTEMPTS; } return(response); }