aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/WebUtil.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/WebUtil.cs')
-rw-r--r--OpenSim/Framework/WebUtil.cs151
1 files changed, 148 insertions, 3 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index b180c8a..94b5230 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -86,7 +86,7 @@ namespace OpenSim.Framework
86 /// Number of milliseconds a call can take before it is considered 86 /// Number of milliseconds a call can take before it is considered
87 /// a "long" call for warning & debugging purposes 87 /// a "long" call for warning & debugging purposes
88 /// </summary> 88 /// </summary>
89 public const int LongCallTime = 3000; 89 public const int LongCallTime = 500;
90 90
91 /// <summary> 91 /// <summary>
92 /// The maximum length of any data logged because of a long request time. 92 /// The maximum length of any data logged because of a long request time.
@@ -205,8 +205,16 @@ namespace OpenSim.Framework
205 { 205 {
206 if (DebugLevel == 5) 206 if (DebugLevel == 5)
207 { 207 {
208<<<<<<< HEAD
208 if (output.Length > MaxRequestDiagLength) 209 if (output.Length > MaxRequestDiagLength)
209 output = output.Substring(0, MaxRequestDiagLength) + "..."; 210 output = output.Substring(0, MaxRequestDiagLength) + "...";
211=======
212 int len = output.Length;
213 if(len > 80)
214 len = 80;
215 output = output.Substring(0, len);
216 output = output + "...";
217>>>>>>> avn/ubitvar
210 } 218 }
211 219
212 m_log.DebugFormat("[LOGHTTP]: {0}{1}", context, Util.BinaryToASCII(output)); 220 m_log.DebugFormat("[LOGHTTP]: {0}{1}", context, Util.BinaryToASCII(output));
@@ -233,6 +241,9 @@ namespace OpenSim.Framework
233 string errorMessage = "unknown error"; 241 string errorMessage = "unknown error";
234 int tickstart = Util.EnvironmentTickCount(); 242 int tickstart = Util.EnvironmentTickCount();
235 int tickdata = 0; 243 int tickdata = 0;
244 int tickcompressdata = 0;
245 int tickJsondata = 0;
246 int compsize = 0;
236 string strBuffer = null; 247 string strBuffer = null;
237 248
238 try 249 try
@@ -250,6 +261,8 @@ namespace OpenSim.Framework
250 { 261 {
251 strBuffer = OSDParser.SerializeJsonString(data); 262 strBuffer = OSDParser.SerializeJsonString(data);
252 263
264 tickJsondata = Util.EnvironmentTickCountSubtract(tickstart);
265
253 if (DebugLevel >= 5) 266 if (DebugLevel >= 5)
254 LogOutgoingDetail("SEND", reqnum, strBuffer); 267 LogOutgoingDetail("SEND", reqnum, strBuffer);
255 268
@@ -271,13 +284,23 @@ namespace OpenSim.Framework
271 // gets written on the stream upon Dispose() 284 // gets written on the stream upon Dispose()
272 } 285 }
273 byte[] buf = ms.ToArray(); 286 byte[] buf = ms.ToArray();
287
288 tickcompressdata = Util.EnvironmentTickCountSubtract(tickstart);
289
274 request.ContentLength = buf.Length; //Count bytes to send 290 request.ContentLength = buf.Length; //Count bytes to send
291 compsize = buf.Length;
275 using (Stream requestStream = request.GetRequestStream()) 292 using (Stream requestStream = request.GetRequestStream())
276 requestStream.Write(buf, 0, (int)buf.Length); 293 requestStream.Write(buf, 0, (int)buf.Length);
277 } 294 }
278 } 295 }
279 else 296 else
280 { 297 {
298<<<<<<< HEAD
299=======
300 tickcompressdata = tickJsondata;
301 compsize = buffer.Length;
302 request.ContentType = "application/json";
303>>>>>>> avn/ubitvar
281 request.ContentLength = buffer.Length; //Count bytes to send 304 request.ContentLength = buffer.Length; //Count bytes to send
282 using (Stream requestStream = request.GetRequestStream()) 305 using (Stream requestStream = request.GetRequestStream())
283 requestStream.Write(buffer, 0, buffer.Length); //Send it 306 requestStream.Write(buffer, 0, buffer.Length); //Send it
@@ -292,6 +315,7 @@ namespace OpenSim.Framework
292 { 315 {
293 using (Stream responseStream = response.GetResponseStream()) 316 using (Stream responseStream = response.GetResponseStream())
294 { 317 {
318<<<<<<< HEAD
295 using (StreamReader reader = new StreamReader(responseStream)) 319 using (StreamReader reader = new StreamReader(responseStream))
296 { 320 {
297 string responseStr = reader.ReadToEnd(); 321 string responseStr = reader.ReadToEnd();
@@ -299,6 +323,12 @@ namespace OpenSim.Framework
299 WebUtil.LogResponseDetail(reqnum, responseStr); 323 WebUtil.LogResponseDetail(reqnum, responseStr);
300 return CanonicalizeResults(responseStr); 324 return CanonicalizeResults(responseStr);
301 } 325 }
326=======
327 string responseStr = null;
328 responseStr = responseStream.GetStreamString();
329 //m_log.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr);
330 return CanonicalizeResults(responseStr);
331>>>>>>> avn/ubitvar
302 } 332 }
303 } 333 }
304 } 334 }
@@ -314,6 +344,7 @@ namespace OpenSim.Framework
314 catch (Exception ex) 344 catch (Exception ex)
315 { 345 {
316 errorMessage = ex.Message; 346 errorMessage = ex.Message;
347 m_log.Debug("[WEB UTIL]: Exception making request: " + ex.ToString());
317 } 348 }
318 finally 349 finally
319 { 350 {
@@ -321,8 +352,21 @@ namespace OpenSim.Framework
321 if (tickdiff > LongCallTime) 352 if (tickdiff > LongCallTime)
322 { 353 {
323 m_log.InfoFormat( 354 m_log.InfoFormat(
355<<<<<<< HEAD
324 "[LOGHTTP]: Slow JSON-RPC request {0} {1} to {2} took {3}ms, {4}ms writing, {5}", 356 "[LOGHTTP]: Slow JSON-RPC request {0} {1} to {2} took {3}ms, {4}ms writing, {5}",
325 reqnum, method, url, tickdiff, tickdata, 357 reqnum, method, url, tickdiff, tickdata,
358=======
359 "[WEB UTIL]: Slow ServiceOSD request {0} {1} {2} took {3}ms, {4}ms writing({5} at Json; {6} at comp), {7} bytes ({8} uncomp): {9}",
360 reqnum,
361 method,
362 url,
363 tickdiff,
364 tickdata,
365 tickJsondata,
366 tickcompressdata,
367 compsize,
368 strBuffer != null ? strBuffer.Length : 0,
369>>>>>>> avn/ubitvar
326 strBuffer != null 370 strBuffer != null
327 ? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer) 371 ? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer)
328 : ""); 372 : "");
@@ -396,7 +440,7 @@ namespace OpenSim.Framework
396 /// </summary> 440 /// </summary>
397 public static OSDMap PostToService(string url, NameValueCollection data) 441 public static OSDMap PostToService(string url, NameValueCollection data)
398 { 442 {
399 return ServiceFormRequest(url,data,10000); 443 return ServiceFormRequest(url,data, 20000);
400 } 444 }
401 445
402 public static OSDMap ServiceFormRequest(string url, NameValueCollection data, int timeout) 446 public static OSDMap ServiceFormRequest(string url, NameValueCollection data, int timeout)
@@ -790,7 +834,8 @@ namespace OpenSim.Framework
790 reqnum, verb, requestUrl); 834 reqnum, verb, requestUrl);
791 835
792 int tickstart = Util.EnvironmentTickCount(); 836 int tickstart = Util.EnvironmentTickCount();
793 int tickdata = 0; 837// int tickdata = 0;
838 int tickdiff = 0;
794 839
795 Type type = typeof(TRequest); 840 Type type = typeof(TRequest);
796 841
@@ -831,10 +876,17 @@ namespace OpenSim.Framework
831 request.ContentLength = length; 876 request.ContentLength = length;
832 byte[] data = buffer.ToArray(); 877 byte[] data = buffer.ToArray();
833 878
879<<<<<<< HEAD
834 if (WebUtil.DebugLevel >= 5) 880 if (WebUtil.DebugLevel >= 5)
835 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); 881 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
836 882
837 request.BeginGetRequestStream(delegate(IAsyncResult res) 883 request.BeginGetRequestStream(delegate(IAsyncResult res)
884=======
885 // capture how much time was spent writing
886 // useless in this async
887// tickdata = Util.EnvironmentTickCountSubtract(tickstart);
888 request.BeginGetResponse(delegate(IAsyncResult ar)
889>>>>>>> avn/ubitvar
838 { 890 {
839 using (Stream requestStream = request.EndGetRequestStream(res)) 891 using (Stream requestStream = request.EndGetRequestStream(res))
840 requestStream.Write(data, 0, length); 892 requestStream.Write(data, 0, length);
@@ -844,6 +896,7 @@ namespace OpenSim.Framework
844 896
845 request.BeginGetResponse(delegate(IAsyncResult ar) 897 request.BeginGetResponse(delegate(IAsyncResult ar)
846 { 898 {
899<<<<<<< HEAD
847 using (WebResponse response = request.EndGetResponse(ar)) 900 using (WebResponse response = request.EndGetResponse(ar))
848 { 901 {
849 try 902 try
@@ -858,6 +911,14 @@ namespace OpenSim.Framework
858 { 911 {
859 } 912 }
860 } 913 }
914=======
915 // Let's not close this
916 // yes do close it
917 buffer.Close();
918 respStream.Close();
919 response.Close();
920 }
921>>>>>>> avn/ubitvar
861 922
862 action(deserial); 923 action(deserial);
863 924
@@ -919,6 +980,7 @@ namespace OpenSim.Framework
919 "[ASYNC REQUEST]: Request {0} {1} failed with exception {2}{3}", 980 "[ASYNC REQUEST]: Request {0} {1} failed with exception {2}{3}",
920 verb, requestUrl, e.Message, e.StackTrace); 981 verb, requestUrl, e.Message, e.StackTrace);
921 } 982 }
983<<<<<<< HEAD
922 984
923 // m_log.DebugFormat("[ASYNC REQUEST]: Received {0}", deserial.ToString()); 985 // m_log.DebugFormat("[ASYNC REQUEST]: Received {0}", deserial.ToString());
924 986
@@ -942,12 +1004,36 @@ namespace OpenSim.Framework
942 string originalRequest = null; 1004 string originalRequest = null;
943 1005
944 if (buffer != null) 1006 if (buffer != null)
1007=======
1008 }
1009 catch (Exception e)
1010 {
1011 m_log.ErrorFormat(
1012 "[ASYNC REQUEST]: Request {0} {1} failed with exception {2}{3}",
1013 verb, requestUrl, e.Message, e.StackTrace);
1014 }
1015
1016 // m_log.DebugFormat("[ASYNC REQUEST]: Received {0}", deserial.ToString());
1017 try
1018 {
1019 action(deserial);
1020 }
1021 catch (Exception e)
1022>>>>>>> avn/ubitvar
945 { 1023 {
946 originalRequest = Encoding.UTF8.GetString(buffer.ToArray()); 1024 originalRequest = Encoding.UTF8.GetString(buffer.ToArray());
947 1025
1026<<<<<<< HEAD
948 if (originalRequest.Length > WebUtil.MaxRequestDiagLength) 1027 if (originalRequest.Length > WebUtil.MaxRequestDiagLength)
949 originalRequest = originalRequest.Remove(WebUtil.MaxRequestDiagLength); 1028 originalRequest = originalRequest.Remove(WebUtil.MaxRequestDiagLength);
950 } 1029 }
1030=======
1031 tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
1032 if (tickdiff > WebUtil.LongCallTime)
1033 {
1034/*
1035 string originalRequest = null;
1036>>>>>>> avn/ubitvar
951 1037
952 m_log.InfoFormat( 1038 m_log.InfoFormat(
953 "[LOGHTTP]: Slow AsynchronousRequestObject request {0} {1} to {2} took {3}ms, {4}ms writing, {5}", 1039 "[LOGHTTP]: Slow AsynchronousRequestObject request {0} {1} to {2} took {3}ms, {4}ms writing, {5}",
@@ -959,11 +1045,36 @@ namespace OpenSim.Framework
959 m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms, {2}ms writing", 1045 m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms, {2}ms writing",
960 reqnum, tickdiff, tickdata); 1046 reqnum, tickdiff, tickdata);
961 } 1047 }
1048<<<<<<< HEAD
962 } 1049 }
963 finally 1050 finally
964 { 1051 {
965 if (buffer != null) 1052 if (buffer != null)
966 buffer.Dispose(); 1053 buffer.Dispose();
1054=======
1055
1056 m_log.InfoFormat(
1057 "[ASYNC REQUEST]: Slow request {0} {1} {2} took {3}ms, {4}ms writing, {5}",
1058 reqnum,
1059 verb,
1060 requestUrl,
1061 tickdiff,
1062 tickdata,
1063 originalRequest);
1064*/
1065 m_log.InfoFormat(
1066 "[ASYNC REQUEST]: Slow WebRequest SETUP <{0}> {1} {2} took {3}ms",
1067 reqnum,
1068 verb,
1069 requestUrl,
1070 tickdiff);
1071 }
1072 else if (WebUtil.DebugLevel >= 4)
1073 {
1074 m_log.DebugFormat(
1075 "[WEB UTIL]: HTTP OUT {0} took {1}ms",
1076 reqnum, tickdiff);
1077>>>>>>> avn/ubitvar
967 } 1078 }
968 } 1079 }
969 } 1080 }
@@ -1004,6 +1115,8 @@ namespace OpenSim.Framework
1004 1115
1005 string respstring = String.Empty; 1116 string respstring = String.Empty;
1006 1117
1118 int tickset = Util.EnvironmentTickCountSubtract(tickstart);
1119
1007 using (MemoryStream buffer = new MemoryStream()) 1120 using (MemoryStream buffer = new MemoryStream())
1008 { 1121 {
1009 if ((verb == "POST") || (verb == "PUT")) 1122 if ((verb == "POST") || (verb == "PUT"))
@@ -1015,14 +1128,19 @@ namespace OpenSim.Framework
1015 { 1128 {
1016 writer.Write(obj); 1129 writer.Write(obj);
1017 writer.Flush(); 1130 writer.Flush();
1131 if (WebUtil.DebugLevel >= 5)
1132 WebUtil.LogOutgoingDetail(buffer);
1018 } 1133 }
1019 1134
1020 length = (int)obj.Length; 1135 length = (int)obj.Length;
1021 request.ContentLength = length; 1136 request.ContentLength = length;
1022 byte[] data = buffer.ToArray(); 1137 byte[] data = buffer.ToArray();
1023 1138
1139<<<<<<< HEAD
1024 if (WebUtil.DebugLevel >= 5) 1140 if (WebUtil.DebugLevel >= 5)
1025 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); 1141 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
1142=======
1143>>>>>>> avn/ubitvar
1026 1144
1027 Stream requestStream = null; 1145 Stream requestStream = null;
1028 try 1146 try
@@ -1070,8 +1188,18 @@ namespace OpenSim.Framework
1070 if (tickdiff > WebUtil.LongCallTime) 1188 if (tickdiff > WebUtil.LongCallTime)
1071 { 1189 {
1072 m_log.InfoFormat( 1190 m_log.InfoFormat(
1191<<<<<<< HEAD
1073 "[LOGHTTP]: Slow SynchronousRestForms request {0} {1} to {2} took {3}ms, {4}ms writing, {5}", 1192 "[LOGHTTP]: Slow SynchronousRestForms request {0} {1} to {2} took {3}ms, {4}ms writing, {5}",
1074 reqnum, verb, requestUrl, tickdiff, tickdata, 1193 reqnum, verb, requestUrl, tickdiff, tickdata,
1194=======
1195 "[FORMS]: Slow request {0} {1} {2} took {3}ms, {4}ms writing, {5}",
1196 reqnum,
1197 verb,
1198 requestUrl,
1199 tickdiff,
1200 tickset,
1201 tickdata,
1202>>>>>>> avn/ubitvar
1075 obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj); 1203 obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj);
1076 } 1204 }
1077 else if (WebUtil.DebugLevel >= 4) 1205 else if (WebUtil.DebugLevel >= 4)
@@ -1208,6 +1336,8 @@ namespace OpenSim.Framework
1208 ht.ServicePoint.ConnectionLimit = maxConnections; 1336 ht.ServicePoint.ConnectionLimit = maxConnections;
1209 1337
1210 request.Method = verb; 1338 request.Method = verb;
1339 if (pTimeout != 0)
1340 request.Timeout = pTimeout * 1000;
1211 MemoryStream buffer = null; 1341 MemoryStream buffer = null;
1212 1342
1213 try 1343 try
@@ -1221,17 +1351,29 @@ namespace OpenSim.Framework
1221 XmlWriterSettings settings = new XmlWriterSettings(); 1351 XmlWriterSettings settings = new XmlWriterSettings();
1222 settings.Encoding = Encoding.UTF8; 1352 settings.Encoding = Encoding.UTF8;
1223 1353
1354<<<<<<< HEAD
1224 using (XmlWriter writer = XmlWriter.Create(buffer, settings)) 1355 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
1225 { 1356 {
1226 XmlSerializer serializer = new XmlSerializer(type); 1357 XmlSerializer serializer = new XmlSerializer(type);
1227 serializer.Serialize(writer, obj); 1358 serializer.Serialize(writer, obj);
1228 writer.Flush(); 1359 writer.Flush();
1229 } 1360 }
1361=======
1362 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
1363 {
1364 XmlSerializer serializer = new XmlSerializer(type);
1365 serializer.Serialize(writer, obj);
1366 writer.Flush();
1367 if (WebUtil.DebugLevel >= 5)
1368 WebUtil.LogOutgoingDetail(buffer);
1369 }
1370>>>>>>> avn/ubitvar
1230 1371
1231 int length = (int)buffer.Length; 1372 int length = (int)buffer.Length;
1232 request.ContentLength = length; 1373 request.ContentLength = length;
1233 byte[] data = buffer.ToArray(); 1374 byte[] data = buffer.ToArray();
1234 1375
1376<<<<<<< HEAD
1235 if (WebUtil.DebugLevel >= 5) 1377 if (WebUtil.DebugLevel >= 5)
1236 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); 1378 WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data));
1237 1379
@@ -1255,6 +1397,9 @@ namespace OpenSim.Framework
1255 } 1397 }
1256 } 1398 }
1257 1399
1400=======
1401 Stream requestStream = null;
1402>>>>>>> avn/ubitvar
1258 try 1403 try
1259 { 1404 {
1260 using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse()) 1405 using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())