コード例 #1
0
ファイル: MwsException.cs プロジェクト: vijayamazon/ezbob
 private void populateFromMWSException(MwsException e)
 {
     if (e.StatusCode != null)
     {
         this.statusCode = (int)e.StatusCode;
     }
     if (e.Message != null)
     {
         this.message = e.Message;
     }
     if (e.errorCode != null)
     {
         this.errorCode = e.ErrorCode;
     }
     if (e.errorType != null)
     {
         this.errorType = e.ErrorType;
     }
     if (e.detail != null)
     {
         this.detail = e.Detail;
     }
     if (e.xml != null)
     {
         this.xml = e.XML;
     }
     if (e.ResponseHeaderMetadata != null)
     {
         this.rhmd = e.ResponseHeaderMetadata;
     }
 }
コード例 #2
0
ファイル: MwsException.cs プロジェクト: vijayamazon/ezbob
        /// <summary>
        /// Initializes exception with information available from the service plus from an exception
        /// Needed for backwards compatibility
        /// </summary>
        /// <param name="statusCode">HTTP status code for error response (as an int)</param>
        /// <param name="message">Error message from HTTP header</param>
        /// <param name="errorCode">Error code from response XML</param>
        /// <param name="errorType">Error type from response XML</param>
        /// <param name="xml">Compete XML found in response</param>
        /// <param name="rhmd">Response header information</param>
        /// <param name="cause">Wrapped exception</param>
        public MwsException(int statusCode, string message, string errorCode, string errorType, string xml, MwsResponseHeaderMetadata rhmd, Exception cause)
            : base()
        {
            this.statusCode = statusCode;
            this.rhmd       = rhmd;
            this.xml        = xml;
            this.errorType  = errorType;
            this.errorCode  = errorCode;
            this.message    = message;

            if (xml != null)
            {
                populateFromXML(xml);
            }

            if (cause is MwsException)
            {
                populateFromMWSException((MwsException)cause);
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates a MwsCall and sends the request
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="type"></param>
        /// <param name="requestData"></param>
        /// <returns></returns>

        public T Call <T>(IMwsRequestType <T> type,
                          IMwsObject requestData) where T : IMwsObject
        {
            IMwsReader responseReader = null;

            try
            {
                string   servicePath   = type.ServicePath;
                string   operationName = type.OperationName;
                IMwsCall mc            = NewCall(servicePath, operationName);
                requestData.WriteFragmentTo(mc);
                responseReader = mc.invoke();
                MwsResponseHeaderMetadata rhmd = mc.GetResponseMetadataHeader();
                T response = MwsUtil.NewInstance <T>();
                type.SetResponseHeaderMetadata(response, rhmd);
                response.ReadFragmentFrom(responseReader);
                return(response);
            }
            catch (Exception e)
            {
                throw type.WrapException(e);
            }
        }
コード例 #4
0
 public MwsResponseHeaderMetadata(MwsResponseHeaderMetadata rhmd)
     : this(rhmd.RequestId, rhmd.ResponseContext, rhmd.Timestamp, rhmd.QuotaMax, rhmd.QuotaRemaining, rhmd.QuotaResetsAt)
 {
 }
コード例 #5
0
ファイル: MwsException.cs プロジェクト: vijayamazon/ezbob
 /// <summary>
 /// Initializes exception with information available from the service
 /// </summary>
 /// <param name="statusCode">HTTP status code for error response (as an int)</param>
 /// <param name="message">Error message from HTTP header</param>
 /// <param name="errorCode">Error code from response XML</param>
 /// <param name="errorType">Error type from response XML</param>
 /// <param name="xml">Compete XML found in response</param>
 /// <param name="rhmd">Response header information</param>
 public MwsException(int statusCode, string message, string errorCode, string errorType, string xml, MwsResponseHeaderMetadata rhmd)
     : this(statusCode, message, errorCode, errorType, xml, rhmd, null)
 {
 }
コード例 #6
0
ファイル: MwsAQCall.cs プロジェクト: vijayamazon/ezbob
        /// <summary>
        /// Creates a request and invokes it
        /// </summary>
        /// <returns></returns>
        /// <exception cref="MwsException">Exceptions from invoking the request</exception>
        public IMwsReader invoke()
        {
            string         responseBody;
            string         message;
            HttpStatusCode statusCode = default(HttpStatusCode);

            /* Add required request parameters */
            AddRequiredParameters();
            string queryString = GetParametersAsString(this.parameters);
            int    retries     = 0;

            do
            {
                /* Submit the request and read response body */
                try
                {
                    this.request = this.connection.GetHttpClient(this.serviceEndPoint.URI);
                    byte[] requestData = new UTF8Encoding().GetBytes(queryString);
                    this.request.ContentLength = requestData.Length;
                    using (Stream requestStream = this.request.GetRequestStream())
                    {
                        requestStream.Write(requestData, 0, requestData.Length);
                    }
                    using (HttpWebResponse httpResponse = this.request.GetResponse() as HttpWebResponse)
                    {
                        statusCode = httpResponse.StatusCode;
                        message    = httpResponse.StatusDescription;
                        this.ResponseHeaderMetadata = GetResponseHeaderMetadata(httpResponse);
                        StreamReader reader = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8);
                        responseBody = reader.ReadToEnd();
                    }
                    if (statusCode == HttpStatusCode.OK)
                    {
                        return(new MwsXmlReader(responseBody));
                    }
                    MwsException e = new MwsException((int)statusCode, message, null, null, responseBody, this.ResponseHeaderMetadata);

                    if (statusCode == HttpStatusCode.InternalServerError)
                    {
                        if (PauseIfRetryNeeded(retries++))
                        {
                            continue;
                        }
                    }
                    throw e;
                }
                /* Web exception is thrown on unsuccessful responses */
                catch (WebException we)
                {
                    using (HttpWebResponse httpErrorResponse = (HttpWebResponse)we.Response as HttpWebResponse)
                    {
                        if (httpErrorResponse == null)
                        {
                            throw new MwsException(we);
                        }
                        statusCode = httpErrorResponse.StatusCode;
                        using (StreamReader reader = new StreamReader(httpErrorResponse.GetResponseStream(), Encoding.UTF8))
                        {
                            responseBody = reader.ReadToEnd();
                        }
                    }
                    //retry logic
                    if (PauseIfRetryNeeded(retries++))
                    {
                        continue;
                    }
                    throw new MwsException((int)statusCode, null, null, null, responseBody, null);
                }

                /* Catch other exceptions, attempt to convert to formatted exception,
                 * else rethrow wrapped exception */
                catch (Exception e)
                {
                    throw new MwsException(e);
                }
            } while (true);
        }