示例#1
0
        /// <summary>
        /// After MakeSingleCall determines whether the HTTP request was succesful. Populates the error, logs messages and update4s the latency tracker.
        /// </summary>
        /// <param name="opCode">Operation Code</param>
        /// <param name="path">Path of the file or directory</param>
        /// <param name="resp">Contains the response message </param>
        /// <param name="responseLength">Length of the response returned by the server</param>
        /// <param name="requestLength">Length of the request data</param>
        /// <param name="requestId">Request ID</param>
        /// <param name="clientId">Client Id of the application</param>
        /// <param name="querParams">Serialized query parameter of the Http request</param>
        /// <param name="numRetries">Number of retries</param>
        private static void HandleMakeSingleCallResponse(string opCode, string path, OperationResponse resp, int responseLength, int requestLength, string requestId, long clientId, string querParams, ref int numRetries)
        {
            DetermineIsSuccessful(resp);//After recieving the response from server determine whether the response is successful
            string error = "";

            if (!resp.IsSuccessful)
            {
                if (resp.Ex != null)
                {
                    error = resp.Ex.Message;
                }
                else if (!string.IsNullOrEmpty(resp.RemoteExceptionName))
                {
                    error = resp.HttpStatus + ": " + resp.RemoteExceptionName;
                }
                else if (!string.IsNullOrEmpty(resp.Error))
                {
                    error = resp.Error;
                }
                //This is either unexplained exception or the remote exception returned from server
                resp.ExceptionHistory = resp.ExceptionHistory == null ? error : resp.ExceptionHistory + "," + error;
                numRetries++;
            }
            if (WebTransportLog.IsDebugEnabled)
            {
                string logLine = $"HTTPRequest,{(resp.IsSuccessful ? "Succeeded" : "failed")},cReqId:{requestId},lat:{resp.LastCallLatency},err{error},Reqlen:{requestLength},Resplen:{responseLength}" +
                                 $",token_ns:{resp.TokenAcquisitionLatency},sReqId:{resp.RequestId},path:{path},qp:{querParams}";
                WebTransportLog.Debug(logLine);
            }
            LatencyTracker.AddLatency(requestId, numRetries, resp.LastCallLatency, error, opCode,
                                      requestLength + responseLength, clientId);
        }
示例#2
0
        /// <summary>
        /// Sets the WebRequest headers
        /// </summary>
        /// <param name="webReq">HttpWebRequest</param>
        /// <param name="client">AdlsClient</param>
        /// <param name="req">RequestOptions</param>
        /// <param name="token">Auth token</param>
        /// <param name="opMethod">Operation method (e.g. POST/GET)</param>
        /// <param name="customHeaders">Custom headers</param>
        private static void AssignCommonHttpHeaders(HttpWebRequest webReq, AdlsClient client, RequestOptions req, string token, string opMethod, IDictionary <string, string> customHeaders, int postRequestLength)
        {
            webReq.Headers["Authorization"] = token;
            string latencyHeader = LatencyTracker.GetLatency();

            if (!string.IsNullOrEmpty(latencyHeader))
            {
                webReq.Headers["x-ms-adl-client-latency"] = latencyHeader;
            }

            if (client.ContentEncoding != null && postRequestLength > MinDataSizeForCompression)
            {
                webReq.Headers["Content-Encoding"] = client.ContentEncoding;
            }

            if (client.DipIp != null && !req.IgnoreDip)
            {
#if NET452
                webReq.Host = client.AccountFQDN;
#else
                webReq.Headers["Host"] = client.AccountFQDN;
#endif
            }

            if (!req.KeepAlive)
            {
                /*
                 * Connection cant be set directly as a header in net452.
                 * KeepAlive needs to be set as a property in HttpWebRequest when we want to close connection.
                 */
#if NET452
                webReq.KeepAlive = false;
#else
                webReq.Headers["Connection"] = "Close";
#endif
            }

            if (customHeaders != null)
            {
                string contentType;
                if (customHeaders.TryGetValue("Content-Type", out contentType))
                {
                    webReq.ContentType = contentType;
                    customHeaders.Remove("Content-Type");
                }
                foreach (var key in customHeaders.Keys)
                {
                    webReq.Headers[key] = customHeaders[key];
                }
            }
#if NET452
            webReq.UserAgent = client.GetUserAgent();
            webReq.ServicePoint.UseNagleAlgorithm = false;
            webReq.ServicePoint.Expect100Continue = false;
#else
            webReq.Headers["User-Agent"] = client.GetUserAgent();
#endif
            webReq.Headers["x-ms-client-request-id"] = req.RequestId;
            webReq.Method = opMethod;
        }
        /// <summary>
        /// After MakeSingleCall determines whether the HTTP request was succesful. Populates the error, logs messages and update4s the latency tracker.
        /// </summary>
        /// <param name="opCode">Operation Code</param>
        /// <param name="path">Path of the file or directory</param>
        /// <param name="resp">Contains the response message </param>
        /// <param name="responseLength">Length of the response returned by the server</param>
        /// <param name="requestLength">Length of the request data</param>
        /// <param name="req">Request Options</param>
        /// <param name="client">AdlsClient</param>
        /// <param name="querParams">Serialized query parameter of the Http request</param>
        /// <param name="numRetries">Number of retries</param>
        private static void HandleMakeSingleCallResponse(string opCode, string path, OperationResponse resp, int responseLength, int requestLength, RequestOptions req, AdlsClient client, string querParams, ref int numRetries)
        {
            DetermineIsSuccessful(resp);//After recieving the response from server determine whether the response is successful
            string error = "";

            if (!resp.IsSuccessful)
            {
                if (resp.Ex != null)
                {
                    error = resp.Ex.Message;
                }
                else if (!string.IsNullOrEmpty(resp.RemoteExceptionName))
                {
                    error = $"{resp.HttpStatus} ( {resp.RemoteExceptionName}  {resp.RemoteExceptionMessage} JavaClassName: {resp.RemoteExceptionJavaClassName} ";
                }
                else if (!string.IsNullOrEmpty(resp.Error))
                {
                    error = resp.Error;
                }
                //This is either unexplained exception or the remote exception returned from server
                resp.ExceptionHistory = resp.ExceptionHistory == null ? error : resp.ExceptionHistory + "," + error;
                numRetries++;
            }
            if (WebTransportLog.IsDebugEnabled)
            {
                string logLine =
                    $"HTTPRequest,{(resp.IsSuccessful ? "Succeeded" : "failed")},cReqId:{req.RequestId},lat:{resp.LastCallLatency},err:{error},Reqlen:{requestLength},Resplen:{responseLength}" +
                    $"{(resp.HttpStatus == HttpStatusCode.Unauthorized ? $",Tokenlen:{resp.AuthorizationHeaderLength}" : "")},token_ns:{resp.TokenAcquisitionLatency},sReqId:{resp.RequestId}" +
                    $",path:{path},qp:{querParams}{(!req.KeepAlive ? ",keepAlive:false" : "")}{(!req.IgnoreDip && client.DipIp != null ? $",dipIp:{client.DipIp}" : "")}";
                WebTransportLog.Debug(logLine);
            }
            LatencyTracker.AddLatency(req.RequestId, numRetries, resp.LastCallLatency, error, opCode,
                                      requestLength + responseLength, client.ClientId);
        }
        /// <summary>
        /// Sets the WebRequest headers
        /// </summary>
        /// <param name="webReq">HttpWebRequest</param>
        /// <param name="client">AdlsClient</param>
        /// <param name="req">RequestOptions</param>
        /// <param name="token">Auth token</param>
        /// <param name="opMethod">Operation method (e.g. POST/GET)</param>
        /// <param name="customHeaders">Custom headers</param>
        private static void AssignCommonHttpHeaders(HttpWebRequest webReq, AdlsClient client, RequestOptions req, string token, string opMethod, IDictionary <string, string> customHeaders)
        {
            webReq.Headers["Authorization"] = token;
            string latencyHeader = LatencyTracker.GetLatency();

            if (!string.IsNullOrEmpty(latencyHeader))
            {
                webReq.Headers["x-ms-adl-client-latency"] = latencyHeader;
            }

            if (client.DipIp != null && !req.IgnoreDip)
            {
#if NET452
                webReq.Host = client.AccountFQDN;
#else
                webReq.Headers["Host"] = client.AccountFQDN;
#endif
            }

            if (!req.KeepAlive)
            {
                /*
                 * Connection cant be set directly as a header in net452.
                 * KeepAlive needs to be set as a property in HttpWebRequest when we want to close connection.
                 */
#if NET452
                webReq.KeepAlive = false;
#else
                webReq.Headers["Connection"] = "Close";
#endif
            }
            if (customHeaders != null)
            {
                foreach (var key in customHeaders.Keys)
                {
                    webReq.Headers[key] = customHeaders[key];
                }
            }
#if NETSTANDARD2_0 || NET452
            webReq.UserAgent = client.GetUserAgent();
#else
            webReq.Headers["User-Agent"] = client.GetUserAgent();
#endif
#if NET452
            //Setting timeout is only available in NET452
            webReq.ReadWriteTimeout = (int)req.TimeOut.TotalMilliseconds;
            webReq.Timeout          = (int)req.TimeOut.TotalMilliseconds;
            webReq.ServicePoint.UseNagleAlgorithm = false;
            webReq.ServicePoint.Expect100Continue = false;
#endif
            webReq.Headers["x-ms-client-request-id"] = req.RequestId;
            webReq.Method = opMethod;
        }
示例#5
0
        /// <summary>
        /// Sets the WebRequest headers
        /// </summary>
        /// <param name="webReq">HttpWebRequest</param>
        /// <param name="client">AdlsClient</param>
        /// <param name="req">RequestOptions</param>
        /// <param name="token">Auth token</param>
        /// <param name="opMethod">Operation method (e.g. POST/GET)</param>
        private static void AssignCommonHttpHeaders(HttpWebRequest webReq, AdlsClient client, RequestOptions req, string token, string opMethod)
        {
            webReq.Headers["Authorization"] = token;
            string latencyHeader = LatencyTracker.GetLatency();

            if (!string.IsNullOrEmpty(latencyHeader))
            {
                webReq.Headers["x-ms-adl-client-latency"] = latencyHeader;
            }
#if NET452
            webReq.UserAgent = client.GetUserAgent();
            //Setting timeout is only available in NET452
            webReq.ReadWriteTimeout = (int)req.TimeOut.TotalMilliseconds;
            webReq.Timeout          = (int)req.TimeOut.TotalMilliseconds;
            webReq.ServicePoint.UseNagleAlgorithm = false;
            webReq.ServicePoint.Expect100Continue = false;
#else
            webReq.Headers["User-Agent"] = client.GetUserAgent();
#endif
            webReq.Headers["x-ms-client-request-id"] = req.RequestId;
            webReq.Method = opMethod;
        }