From 161c827a4474c2356deef3b0f927638b5b9085ea Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Thu, 27 Mar 2014 17:46:37 +0200 Subject: Fixed a case where logging an HTTP response failed because the stream was non-seekable --- OpenSim/Framework/WebUtil.cs | 51 ++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 89181a9..40c1634 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); + } + } + } } } -- cgit v1.1