public RestClientWrapper(OBS.Runtime.Internal.IRequest request, DISConfig disConfig) : base(request, disConfig) { this.requestObs = request; this.disConfig = disConfig; this._idisRestClient_4_5 = BasicDisRestClient.GetInstance(disConfig); this._idisRestClient = Com.Bigdata.Dis.Sdk.DISCommon.Client.BasicDisRestClient.GetInstance(disConfig); }
private async Task <T> DoRequestAsync <T>(OBS.Runtime.Internal.IRequest requestEx, object requestContent) { ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; ServicePointManager.DefaultConnectionLimit = 9999; HttpMethodName method = (HttpMethodName)Enum.Parse(typeof(HttpMethodName), requestObs.HttpMethod); switch (method) { case HttpMethodName.POST: { return(await _ibasicIdisRestClient.PostAsync <T>(requestEx.Endpoint.AbsoluteUri, requestEx.ResourcePath, requestEx.Headers, requestContent)); } } return(default(T)); }
protected T DoRequest <T>(OBS.Runtime.Internal.IRequest requestEx, object requestContent) { ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; ServicePointManager.Expect100Continue = true; //如果是4.0以下的版本 if (int.Parse(Environment.Version.ToString().Split('.').FirstOrDefault()) < 4) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3 | (SecurityProtocolType)768 | (SecurityProtocolType)3072; } //如果是4.0以上的版本 else { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3 | (SecurityProtocolType)768 | (SecurityProtocolType)3072; } ServicePointManager.DefaultConnectionLimit = 9999; HttpMethodName method = (HttpMethodName)Enum.Parse(typeof(HttpMethodName), requestObs.HttpMethod); switch (method) { case HttpMethodName.POST: { //return _idisRestClient.Post<T>(disConfig.GetFinalBaseURL(), requestEx.ResourcePath, requestEx.Headers, requestContent); return(_idisRestClient.Post <T>(requestEx.Endpoint.AbsoluteUri, requestEx.ResourcePath, requestEx.Headers, requestContent)); } case HttpMethodName.GET: { var requestContext = new RequestContext(true) { OriginalRequest = new DISWebServiceRequest(), Request = requestEx, ClientConfig = new DISExConfig { Timeout = new TimeSpan(1, 0, 0, 0), ReadWriteTimeout = new TimeSpan(1, 0, 0, 0) } }; return(_idisRestClient.Get <T>(requestContext, disConfig.GetFinalBaseURL(), requestEx.ResourcePath, requestEx.Headers, requestContent)); } case HttpMethodName.PUT: return(_idisRestClient.Put <T>(requestEx.Endpoint.AbsoluteUri, requestEx.ResourcePath, requestEx.Headers, requestContent)); case HttpMethodName.DELETE: return(_idisRestClient.Delete <T>(disConfig.GetFinalBaseURL() + requestEx.ResourcePath, requestEx.Headers, requestContent)); } return(default(T)); }
public static OBS.Runtime.Internal.IRequest Sign(OBS.Runtime.Internal.IRequest request, String ak, String sk, String region) { // sign request AbstractDISSigner signer = SignerFactory.GetSigner(Constants.SERVICENAME, region); signer.Sign(request, new BasicCredentials(ak, sk)); return(request); }
public string Request(object requestContent, string ak, string sk, string region, string projectId) { BeforeRequest(requestContent, region, projectId); requestObs = SignUtil.Sign(requestObs, ak, sk, region); string result = DoRequest <string>(requestContent); return(result); }
protected T DoRequest <T>(object requestContent) { int retryCount = -1; ExponentialBackOff backOff = null; do { retryCount++; if (retryCount > 0) { // 等待一段时间再发起重试 if (backOff == null) { backOff = new ExponentialBackOff(250, 2.0, disConfig.GetBackOffMaxIntervalMs(), ExponentialBackOff.DEFAULT_MAX_ELAPSED_TIME); } backOff.backOff(backOff.getNextBackOff()); } try { requestObs.Headers.Remove(HttpHeaderKeys.Authorization); requestObs.Headers.Remove(HttpHeaderKeys.SdkData); requestObs.Headers.Remove(HttpHeaderKeys.SdkShaContent); requestObs.Headers.Remove(HttpHeaderKeys.HostHeader); // 每次重传需要重新签名 requestObs = SignUtil.Sign(requestObs, disConfig.GetAK(), disConfig.GetSK(), disConfig.GetRegion()); return(DoRequest <T>(requestObs, requestContent)); } catch (Exception t) { String errorMsg = t.Message; int statusCode = int.Parse(errorMsg.Split('\n')[0]); // 如果不是可以重试的异常 或者 已达到重试次数,则直接抛出异常 if (!Utils.Utils.IsRetriableSendException(statusCode) || retryCount >= disConfig.GetExceptionRetries()) { throw new Exception(errorMsg.Substring(statusCode.ToString().Length + 1), t); } logger.WarnFormat("Find Retriable Exception {0}, url [{1} {2}], currRetryCount is {3}", errorMsg.Replace("\r\n", ""), requestObs.HttpMethod, requestObs.Endpoint.Host.Trim('/') + requestObs.ResourcePath, retryCount); } } while (retryCount < disConfig.GetExceptionRetries()); return(default(T)); }
public RestClientWrapper(OBS.Runtime.Internal.IRequest request, DISConfig disConfig) { this.requestObs = request; this.disConfig = disConfig; this._idisRestClient = BasicDisRestClient.GetInstance(disConfig); }
public RestClientWrapper(OBS.Runtime.Internal.IRequest request, DISConfig disConfig) : base(request, disConfig) { }