コード例 #1
0
        public DescribeEndpointResponse DescribeEndpoint(String regionId, String locationProduct,
                                                         Credential credential, LocationConfig locationConfig, String locationEndpointType)
        {
            if (isEmpty(locationProduct))
            {
                return(null);
            }

            DescribeEndpointRequest request = new DescribeEndpointRequest();

            request.AcceptFormat    = FormatType.JSON;
            request.Id              = regionId;
            request.RegionId        = locationConfig.RegionId;
            request.LocationProduct = locationProduct;
            if (isEmpty(locationEndpointType))
            {
                request.EndpointType = DEFAULT_ENDPOINT_TYPE;
            }
            else
            {
                request.EndpointType = locationEndpointType;
            }


            ProductDomain domain = new ProductDomain(locationConfig.Product, locationConfig.Endpoint);

            try
            {
                HttpRequest  httpRequest  = request.SignRequest(signer, credential, FormatType.JSON, domain);
                HttpResponse httpResponse = HttpResponse.GetResponse(httpRequest);
                if (httpResponse.isSuccess())
                {
                    String data = System.Text.Encoding.UTF8.GetString(httpResponse.Content);
                    DescribeEndpointResponse response = getEndpointResponse(data, request.EndpointType);
                    if (null == response || isEmpty(response.Endpoint))
                    {
                        return(null);
                    }
                    return(response);
                }
                AcsError error = readError(httpResponse, FormatType.JSON);
                if (500 <= httpResponse.Status)
                {
                    Console.WriteLine("Invoke_Error, requestId: " + error.RequestId + "; code: " + error.ErrorCode
                                      + "; Msg: " + error.ErrorMessage);
                    return(null);
                }
                Console.WriteLine("Invoke_Error, requestId: " + error.RequestId + "; code: " + error.ErrorCode
                                  + "; Msg: " + error.ErrorMessage);
                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invoke Remote Error,Msg" + e.Message);
                return(null);
            }
        }
コード例 #2
0
        public static AcsError Unmarshall(UnmarshallerContext context)
        {
            AcsError error = new AcsError();
            error.HttpResponse = context.HttpResponse;
            Dictionary<String, String> map = context.ResponseDictionary;
            error.RequestId = context.StringValue("Error.RequestId");
            error.ErrorCode = context.StringValue("Error.Code");
            error.ErrorMessage = context.StringValue("Error.Message");

            return error;
        }
コード例 #3
0
ファイル: AcsErrorUnmarshaller.cs プロジェクト: yangbg/SS.SMS
        public static AcsError Unmarshall(UnmarshallerContext context)
        {
            AcsError error = new AcsError();

            error.HttpResponse = context.HttpResponse;
            Dictionary <String, String> map = context.ResponseDictionary;

            error.RequestId    = context.StringValue("Error.RequestId");
            error.ErrorCode    = context.StringValue("Error.Code");
            error.ErrorMessage = context.StringValue("Error.Message");

            return(error);
        }
コード例 #4
0
        public static AcsError Unmarshall(UnmarshallerContext context)
        {
            //Dictionary<string, string> map = context.ResponseDictionary;
            var error = new AcsError
            {
                HttpResponse = context.HttpResponse,
                RequestId    = context.StringValue("Error.RequestId"),
                ErrorCode    = context.StringValue("Error.Code"),
                ErrorMessage = context.StringValue("Error.Message")
            };

            return(error);
        }
コード例 #5
0
        private AcsError ReadError(HttpResponse httpResponse, FormatType format)
        {
            String              responseEndpoint = "Error";
            IReader             reader           = ReaderFactory.CreateInstance(format);
            UnmarshallerContext context          = new UnmarshallerContext();
            String              stringContent    = GetResponseContent(httpResponse);

            context.ResponseDictionary = reader.Read(stringContent, responseEndpoint);
            AcsError error = new AcsError();

            error.HttpResponse = httpResponse;

            return(error);
        }
コード例 #6
0
        public DescribeEndpointResponse DescribeEndpoint(string regionId, string serviceCode, string endpointType, Credential credential, LocationConfig locationConfig)
        {
            if (string.IsNullOrEmpty(serviceCode))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(endpointType))
            {
                endpointType = DEFAULT_ENDPOINT_TYPE;
            }

            DescribeEndpointRequest request = new DescribeEndpointRequest
            {
                AcceptFormat    = Http.FormatType.JSON,
                Id              = regionId,
                RegionId        = locationConfig.RegionId,
                LocationProduct = serviceCode,
                SecurityToken   = credential.SecurityToken,
                EndpointType    = endpointType
            };

            Signer        signer = Signer.GetSigner(new LegacyCredentials(credential));
            ProductDomain domain = new ProductDomain(locationConfig.Product, locationConfig.Endpoint);

            HttpRequest  httpRequest  = request.SignRequest(signer, credential, FormatType.JSON, domain);
            HttpResponse httpResponse = HttpResponse.GetResponse(httpRequest);

            if (httpResponse.isSuccess())
            {
                String data = Encoding.UTF8.GetString(httpResponse.Content);
                DescribeEndpointResponse response = GetEndpointResponse(data, endpointType);
                if (response == null || string.IsNullOrEmpty(response.Endpoint))
                {
                    return(null);
                }

                return(response);
            }
            AcsError error = ReadError(httpResponse, FormatType.JSON);

            if (500 <= httpResponse.Status)
            {
                return(null);
            }
            return(null);
        }
コード例 #7
0
        public void Unmarshall()
        {
            UnmarshallerContext unmarshallerContext = new UnmarshallerContext();

            if (unmarshallerContext.ResponseDictionary == null)
            {
                unmarshallerContext.ResponseDictionary = new Dictionary <string, string>
                {
                    { "Error.RequestId", "RequestId" },
                    { "Error.Code", "ErrorCode" },
                    { "Error.Message", "ErrorMessage" }
                };
            }
            AcsError error = AcsErrorUnmarshaller.Unmarshall(unmarshallerContext);

            Assert.Equal("ErrorCode", error.ErrorCode);
            Assert.Equal("ErrorMessage", error.ErrorMessage);
            Assert.Equal("RequestId", error.RequestId);
        }
        private AcsError ReadError <T>(AcsRequest <T> request, HttpResponse httpResponse, FormatType?format)
            where T : AcsResponse
        {
            var responseEndpoint = "Error";
            var reader           = ReaderFactory.CreateInstance(format);
            var context          = new UnmarshallerContext();
            var body             = Encoding.Default.GetString(httpResponse.Content);

            context.ResponseDictionary =
                null == reader ? new Dictionary <string, string>() : reader.Read(body, responseEndpoint);

            var error = new AcsError();

            error.HttpResponse = context.HttpResponse;
            var map = context.ResponseDictionary;

            error.RequestId = context.StringValue("Error.requestId") == null?context.StringValue("Error.RequestId") : context.StringValue("Error.requestId");

            error.ErrorCode = context.StringValue("Error.code") == null?context.StringValue("Error.Code") : context.StringValue("Error.code");

            error.ErrorMessage = context.StringValue("Error.message") == null?context.StringValue("Error.Message") : context.StringValue("Error.message");

            return(error);
        }