aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorOren Hurvitz2014-03-27 17:46:37 +0200
committerOren Hurvitz2014-03-27 17:46:37 +0200
commit161c827a4474c2356deef3b0f927638b5b9085ea (patch)
tree69c064c8f3d9e52229f15994dcd9a490877007e7 /OpenSim
parentLog errors in MakeRequest() as INFO, not ERROR. Some communications problems ... (diff)
downloadopensim-SC_OLD-161c827a4474c2356deef3b0f927638b5b9085ea.zip
opensim-SC_OLD-161c827a4474c2356deef3b0f927638b5b9085ea.tar.gz
opensim-SC_OLD-161c827a4474c2356deef3b0f927638b5b9085ea.tar.bz2
opensim-SC_OLD-161c827a4474c2356deef3b0f927638b5b9085ea.tar.xz
Fixed a case where logging an HTTP response failed because the stream was non-seekable
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/WebUtil.cs51
1 files changed, 28 insertions, 23 deletions
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;
41using System.Xml.Serialization; 41using System.Xml.Serialization;
42using log4net; 42using log4net;
43using OpenMetaverse.StructuredData; 43using OpenMetaverse.StructuredData;
44using XMLResponseHelper = OpenSim.Framework.SynchronousRestObjectRequester.XMLResponseHelper;
44 45
45namespace OpenSim.Framework 46namespace OpenSim.Framework
46{ 47{
@@ -793,7 +794,6 @@ namespace OpenSim.Framework
793 ht.ServicePoint.ConnectionLimit = maxConnections; 794 ht.ServicePoint.ConnectionLimit = maxConnections;
794 795
795 TResponse deserial = default(TResponse); 796 TResponse deserial = default(TResponse);
796 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
797 797
798 request.Method = verb; 798 request.Method = verb;
799 799
@@ -840,9 +840,7 @@ namespace OpenSim.Framework
840 { 840 {
841 using (Stream respStream = response.GetResponseStream()) 841 using (Stream respStream = response.GetResponseStream())
842 { 842 {
843 if (WebUtil.DebugLevel >= 5) 843 deserial = XMLResponseHelper.LogAndDeserialize<TRequest, TResponse>(respStream, response.ContentLength);
844 WebUtil.LogResponseDetail(respStream);
845 deserial = (TResponse)deserializer.Deserialize(respStream);
846 } 844 }
847 } 845 }
848 catch (System.InvalidOperationException) 846 catch (System.InvalidOperationException)
@@ -869,9 +867,7 @@ namespace OpenSim.Framework
869 { 867 {
870 using (Stream respStream = response.GetResponseStream()) 868 using (Stream respStream = response.GetResponseStream())
871 { 869 {
872 if (WebUtil.DebugLevel >= 5) 870 deserial = XMLResponseHelper.LogAndDeserialize<TRequest, TResponse>(respStream, response.ContentLength);
873 WebUtil.LogResponseDetail(respStream);
874 deserial = (TResponse)deserializer.Deserialize(respStream);
875 } 871 }
876 } 872 }
877 catch (System.InvalidOperationException) 873 catch (System.InvalidOperationException)
@@ -1189,22 +1185,7 @@ namespace OpenSim.Framework
1189 { 1185 {
1190 using (Stream respStream = resp.GetResponseStream()) 1186 using (Stream respStream = resp.GetResponseStream())
1191 { 1187 {
1192 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); 1188 deserial = XMLResponseHelper.LogAndDeserialize<TRequest, TResponse>(respStream, resp.ContentLength);
1193
1194 if (WebUtil.DebugLevel >= 5)
1195 {
1196 byte[] data = new byte[resp.ContentLength];
1197 Util.ReadStream(respStream, data);
1198
1199 WebUtil.LogResponseDetail(System.Text.Encoding.UTF8.GetString(data));
1200
1201 using (MemoryStream temp = new MemoryStream(data))
1202 deserial = (TResponse)deserializer.Deserialize(temp);
1203 }
1204 else
1205 {
1206 deserial = (TResponse)deserializer.Deserialize(respStream);
1207 }
1208 } 1189 }
1209 } 1190 }
1210 else 1191 else
@@ -1278,5 +1259,29 @@ namespace OpenSim.Framework
1278 1259
1279 return deserial; 1260 return deserial;
1280 } 1261 }
1262
1263
1264 public static class XMLResponseHelper
1265 {
1266 public static TResponse LogAndDeserialize<TRequest, TResponse>(Stream respStream, long contentLength)
1267 {
1268 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
1269
1270 if (WebUtil.DebugLevel >= 5)
1271 {
1272 byte[] data = new byte[contentLength];
1273 Util.ReadStream(respStream, data);
1274
1275 WebUtil.LogResponseDetail(System.Text.Encoding.UTF8.GetString(data));
1276
1277 using (MemoryStream temp = new MemoryStream(data))
1278 return (TResponse)deserializer.Deserialize(temp);
1279 }
1280 else
1281 {
1282 return (TResponse)deserializer.Deserialize(respStream);
1283 }
1284 }
1285 }
1281 } 1286 }
1282} 1287}