diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 89181a96af..40c1634fc6 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs @@ -41,6 +41,7 @@ using System.Xml; using System.Xml.Serialization; using log4net; using OpenMetaverse.StructuredData; +using XMLResponseHelper = OpenSim.Framework.SynchronousRestObjectRequester.XMLResponseHelper; namespace OpenSim.Framework { @@ -793,7 +794,6 @@ namespace OpenSim.Framework ht.ServicePoint.ConnectionLimit = maxConnections; TResponse deserial = default(TResponse); - XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); request.Method = verb; @@ -840,9 +840,7 @@ namespace OpenSim.Framework { using (Stream respStream = response.GetResponseStream()) { - if (WebUtil.DebugLevel >= 5) - WebUtil.LogResponseDetail(respStream); - deserial = (TResponse)deserializer.Deserialize(respStream); + deserial = XMLResponseHelper.LogAndDeserialize(respStream, response.ContentLength); } } catch (System.InvalidOperationException) @@ -869,9 +867,7 @@ namespace OpenSim.Framework { using (Stream respStream = response.GetResponseStream()) { - if (WebUtil.DebugLevel >= 5) - WebUtil.LogResponseDetail(respStream); - deserial = (TResponse)deserializer.Deserialize(respStream); + deserial = XMLResponseHelper.LogAndDeserialize(respStream, response.ContentLength); } } catch (System.InvalidOperationException) @@ -1189,22 +1185,7 @@ namespace OpenSim.Framework { using (Stream respStream = resp.GetResponseStream()) { - XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); - - if (WebUtil.DebugLevel >= 5) - { - byte[] data = new byte[resp.ContentLength]; - Util.ReadStream(respStream, data); - - WebUtil.LogResponseDetail(System.Text.Encoding.UTF8.GetString(data)); - - using (MemoryStream temp = new MemoryStream(data)) - deserial = (TResponse)deserializer.Deserialize(temp); - } - else - { - deserial = (TResponse)deserializer.Deserialize(respStream); - } + deserial = XMLResponseHelper.LogAndDeserialize(respStream, resp.ContentLength); } } else @@ -1278,5 +1259,29 @@ namespace OpenSim.Framework return deserial; } + + + public static class XMLResponseHelper + { + public static TResponse LogAndDeserialize(Stream respStream, long contentLength) + { + XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); + + if (WebUtil.DebugLevel >= 5) + { + byte[] data = new byte[contentLength]; + Util.ReadStream(respStream, data); + + WebUtil.LogResponseDetail(System.Text.Encoding.UTF8.GetString(data)); + + using (MemoryStream temp = new MemoryStream(data)) + return (TResponse)deserializer.Deserialize(temp); + } + else + { + return (TResponse)deserializer.Deserialize(respStream); + } + } + } } }