private static string ParseResponseErrorJSON(AstoriaResponse response, bool inStream)
        {
            // error should be something like
            //{
            //  "error": {
            //    "code": "", "message":  "Error message"
            //  }
            //}
            ServiceError serviceError  = new ServiceError();
            string       payloadString = response.Payload;

            CommonPayload payload;

            if (inStream)
            {
                Match match = JsonInStreamErrorRegex.Match(payloadString);
                if (!match.Success)
                {
                    AstoriaTestLog.TraceLine(payloadString);
                    AstoriaTestLog.FailAndThrow("Payload did not contain expected in-stream error");
                }
                response.Payload = match.Groups[1].Value;
            }
            payload = response.CommonPayload;

            PayloadProperty        prop;
            PayloadComplexProperty complex = payload.Resources as PayloadComplexProperty;

            if (complex != null)
            {
                if (complex.PayloadProperties.TryGetValue("message", out prop))
                {
                    if (prop is PayloadComplexProperty)
                    {
                        if ((prop as PayloadComplexProperty).PayloadProperties.TryGetValue("value", out prop))
                        {
                            serviceError.message = (prop as PayloadSimpleProperty).Value;
                        }
                    }
                }
            }

            return(serviceError.message);
        }
        private static string ParseResponseErrorXML(AstoriaResponse response, bool inStream)
        {
            string payloadString = response.Payload;

            ServiceError serviceError = new ServiceError();

            XmlNode error = null;

            if (inStream)
            {
                Match match = XmlInStreamErrorRegex.Match(payloadString);
                if (!match.Success)
                {
                    AstoriaTestLog.TraceLine(payloadString);
                    AstoriaTestLog.FailAndThrow("Payload did not contain expected in-stream error");
                }
                payloadString = match.Groups[1].Value;

                // if there was a namespace prefix, we need to inject a wrapping element with the namespace defined
                //
                if (!string.IsNullOrEmpty(match.Groups[2].Value))
                {
                    payloadString = "<wrapper xmlns:" + match.Groups[2].Value + "=\"" + AtomUpdatePayloadBuilder.DataWebMetadataXmlNamespace + "\">" +
                                    payloadString +
                                    "</wrapper>";
                }
                else
                {
                    // just for consistency later when we pull out the <error> tag
                    //
                    payloadString = "<wrapper>" + payloadString + "</wrapper>";
                }
                XmlDocument xmlDoc = new XmlDocument();
                try
                {
                    xmlDoc.LoadXml(payloadString);
                }
                catch (XmlException ex)
                {
                    AstoriaTestLog.FailAndContinue(ex);
                    return(null);
                }

                // pull out the <error> tag, assuming that there is a <wrapper> tag around it
                //
                error = xmlDoc.FirstChild.FirstChild;
            }
            else
            {
                XmlDocument xmlDoc = new XmlDocument();
                try
                {
                    xmlDoc.LoadXml(payloadString);
                }
                catch (XmlException ex)
                {
                    AstoriaTestLog.FailAndContinue(ex);
                    return(null);
                }

                error = xmlDoc.FirstChild.NextSibling;
            }

            if (error != null)
            {
                XmlNode code       = error.FirstChild;
                XmlNode message    = code.NextSibling;
                XmlNode innerError = message.NextSibling;

                serviceError.code    = code.InnerXml;
                serviceError.message = message.InnerXml;
                if (message.Attributes["xml:lang"] != null)
                {
                    serviceError.language = message.Attributes["xml:lang"].Value;
                }
                else
                {
                    serviceError.language = null;
                }

                if (innerError != null)
                {
                    XmlNode innerMessage    = null;
                    XmlNode innerType       = null;
                    XmlNode innerStackTrace = null;

                    innerMessage = innerError.FirstChild;
                    if (innerMessage != null)
                    {
                        serviceError.InnerServiceError.message = innerMessage.InnerXml;
                        innerType = innerMessage.NextSibling;
                        if (innerType != null)
                        {
                            serviceError.InnerServiceError.type = innerType.InnerXml;
                            innerStackTrace = innerType.NextSibling;
                            if (innerStackTrace != null)
                            {
                                serviceError.InnerServiceError.stacktrace = innerStackTrace.InnerXml;
                            }
                        }
                    }
                }
            }

            return(serviceError.message);
        }
Beispiel #3
0
 //Methods
 public static void TraceInfo(String value)
 {
     AstoriaTestLog.TraceLine(AstoriaTraceLevel.Info, value);
 }