/* * Copyright (C) Alibaba Cloud Computing * All rights reserved. * * 版权所有 (C)阿里云计算有限公司 */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Aliyun.Api.LOG.Utilities; namespace Aliyun.Api.LOG.Response { /// /// Super class of SLS response /// public class LogResponse { // Http header of the response private Dictionary _headers = new Dictionary(); /// /// LogResponse constructor with HTTP response headers /// /// HTTP response header from SLS server public LogResponse(IDictionary httpHeaders) { _headers = new Dictionary(httpHeaders); } /// /// Get the value from the head of response using key /// /// Value of specified http header public String GetHeader(String key) { String res = null; _headers.TryGetValue(key, out res); return res; } /// /// Get request Id for current response generated on server-side. it is useful to track any potential issues /// for this request. /// /// request Id generated on server-side public String GetRequestId() { String requestId = String.Empty; _headers.TryGetValue(LogConsts.NAME_HEADER_REQUESTID, out requestId); return requestId; } /// /// Get all the http response headers /// /// Key-pair map for http headers public Dictionary GetAllHeaders() { return new Dictionary(_headers); } //internal helper function to consolidate logic to throw exception when parsing json string in http response. internal void ParseResponseBody(JObject jsonBody) { try { DeserializeFromJsonInternal(jsonBody); } catch (Exception ex) { throw new LogException("LOGBadResponse", "The response is not valid json string : " + jsonBody, ex, GetRequestId()); } } internal void ParseResponseBody(JArray jsonBody) { try { DeserializeFromJsonInternal(jsonBody); } catch (Exception ex) { throw new LogException("LOGBadResponse", "The response is not valid json string : " + jsonBody, ex, GetRequestId()); } } internal virtual void DeserializeFromJsonInternal(JObject json) { } internal virtual void DeserializeFromJsonInternal(JArray json) { } } }