diff options
author | UbitUmarov | 2015-09-02 19:54:53 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-02 19:54:53 +0100 |
commit | a11edceb00b5b86f825bd957bdac9edb91f893dd (patch) | |
tree | c192eae26f3aadf365a66f32fc6d9ade2f0a0c61 /OpenSim/Framework/WebUtil.cs | |
parent | bad merge? (diff) | |
download | opensim-SC_OLD-a11edceb00b5b86f825bd957bdac9edb91f893dd.zip opensim-SC_OLD-a11edceb00b5b86f825bd957bdac9edb91f893dd.tar.gz opensim-SC_OLD-a11edceb00b5b86f825bd957bdac9edb91f893dd.tar.bz2 opensim-SC_OLD-a11edceb00b5b86f825bd957bdac9edb91f893dd.tar.xz |
seems to compile ( tests comented out)
Diffstat (limited to 'OpenSim/Framework/WebUtil.cs')
-rw-r--r-- | OpenSim/Framework/WebUtil.cs | 146 |
1 files changed, 23 insertions, 123 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 94b5230..44d9318 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs | |||
@@ -205,16 +205,8 @@ namespace OpenSim.Framework | |||
205 | { | 205 | { |
206 | if (DebugLevel == 5) | 206 | if (DebugLevel == 5) |
207 | { | 207 | { |
208 | <<<<<<< HEAD | ||
209 | if (output.Length > MaxRequestDiagLength) | 208 | if (output.Length > MaxRequestDiagLength) |
210 | output = output.Substring(0, MaxRequestDiagLength) + "..."; | 209 | 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 | ||
218 | } | 210 | } |
219 | 211 | ||
220 | m_log.DebugFormat("[LOGHTTP]: {0}{1}", context, Util.BinaryToASCII(output)); | 212 | m_log.DebugFormat("[LOGHTTP]: {0}{1}", context, Util.BinaryToASCII(output)); |
@@ -295,12 +287,9 @@ namespace OpenSim.Framework | |||
295 | } | 287 | } |
296 | else | 288 | else |
297 | { | 289 | { |
298 | <<<<<<< HEAD | ||
299 | ======= | ||
300 | tickcompressdata = tickJsondata; | 290 | tickcompressdata = tickJsondata; |
301 | compsize = buffer.Length; | 291 | compsize = buffer.Length; |
302 | request.ContentType = "application/json"; | 292 | |
303 | >>>>>>> avn/ubitvar | ||
304 | request.ContentLength = buffer.Length; //Count bytes to send | 293 | request.ContentLength = buffer.Length; //Count bytes to send |
305 | using (Stream requestStream = request.GetRequestStream()) | 294 | using (Stream requestStream = request.GetRequestStream()) |
306 | requestStream.Write(buffer, 0, buffer.Length); //Send it | 295 | requestStream.Write(buffer, 0, buffer.Length); //Send it |
@@ -315,7 +304,6 @@ namespace OpenSim.Framework | |||
315 | { | 304 | { |
316 | using (Stream responseStream = response.GetResponseStream()) | 305 | using (Stream responseStream = response.GetResponseStream()) |
317 | { | 306 | { |
318 | <<<<<<< HEAD | ||
319 | using (StreamReader reader = new StreamReader(responseStream)) | 307 | using (StreamReader reader = new StreamReader(responseStream)) |
320 | { | 308 | { |
321 | string responseStr = reader.ReadToEnd(); | 309 | string responseStr = reader.ReadToEnd(); |
@@ -323,12 +311,6 @@ namespace OpenSim.Framework | |||
323 | WebUtil.LogResponseDetail(reqnum, responseStr); | 311 | WebUtil.LogResponseDetail(reqnum, responseStr); |
324 | return CanonicalizeResults(responseStr); | 312 | return CanonicalizeResults(responseStr); |
325 | } | 313 | } |
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 | ||
332 | } | 314 | } |
333 | } | 315 | } |
334 | } | 316 | } |
@@ -352,10 +334,6 @@ namespace OpenSim.Framework | |||
352 | if (tickdiff > LongCallTime) | 334 | if (tickdiff > LongCallTime) |
353 | { | 335 | { |
354 | m_log.InfoFormat( | 336 | m_log.InfoFormat( |
355 | <<<<<<< HEAD | ||
356 | "[LOGHTTP]: Slow JSON-RPC request {0} {1} to {2} took {3}ms, {4}ms writing, {5}", | ||
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}", | 337 | "[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, | 338 | reqnum, |
361 | method, | 339 | method, |
@@ -366,7 +344,7 @@ namespace OpenSim.Framework | |||
366 | tickcompressdata, | 344 | tickcompressdata, |
367 | compsize, | 345 | compsize, |
368 | strBuffer != null ? strBuffer.Length : 0, | 346 | strBuffer != null ? strBuffer.Length : 0, |
369 | >>>>>>> avn/ubitvar | 347 | |
370 | strBuffer != null | 348 | strBuffer != null |
371 | ? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer) | 349 | ? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer) |
372 | : ""); | 350 | : ""); |
@@ -823,6 +801,20 @@ namespace OpenSim.Framework | |||
823 | MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, action, maxConnections, null); | 801 | MakeRequest<TRequest, TResponse>(verb, requestUrl, obj, action, maxConnections, null); |
824 | } | 802 | } |
825 | 803 | ||
804 | /// <summary> | ||
805 | /// Perform a synchronous REST request. | ||
806 | /// </summary> | ||
807 | /// <param name="verb"></param> | ||
808 | /// <param name="requestUrl"></param> | ||
809 | /// <param name="obj"></param> | ||
810 | /// <param name="pTimeout"> | ||
811 | /// Request timeout in milliseconds. Timeout.Infinite indicates no timeout. If 0 is passed then the default HttpWebRequest timeout is used (100 seconds) | ||
812 | /// </param> | ||
813 | /// <param name="maxConnections"></param> | ||
814 | /// <returns> | ||
815 | /// The response. If there was an internal exception or the request timed out, | ||
816 | /// then the default(TResponse) is returned. | ||
817 | /// </returns> | ||
826 | public static void MakeRequest<TRequest, TResponse>(string verb, | 818 | public static void MakeRequest<TRequest, TResponse>(string verb, |
827 | string requestUrl, TRequest obj, Action<TResponse> action, | 819 | string requestUrl, TRequest obj, Action<TResponse> action, |
828 | int maxConnections, IServiceAuth auth) | 820 | int maxConnections, IServiceAuth auth) |
@@ -834,7 +826,7 @@ namespace OpenSim.Framework | |||
834 | reqnum, verb, requestUrl); | 826 | reqnum, verb, requestUrl); |
835 | 827 | ||
836 | int tickstart = Util.EnvironmentTickCount(); | 828 | int tickstart = Util.EnvironmentTickCount(); |
837 | // int tickdata = 0; | 829 | int tickdata = 0; |
838 | int tickdiff = 0; | 830 | int tickdiff = 0; |
839 | 831 | ||
840 | Type type = typeof(TRequest); | 832 | Type type = typeof(TRequest); |
@@ -876,27 +868,19 @@ namespace OpenSim.Framework | |||
876 | request.ContentLength = length; | 868 | request.ContentLength = length; |
877 | byte[] data = buffer.ToArray(); | 869 | byte[] data = buffer.ToArray(); |
878 | 870 | ||
879 | <<<<<<< HEAD | ||
880 | if (WebUtil.DebugLevel >= 5) | 871 | if (WebUtil.DebugLevel >= 5) |
881 | WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); | 872 | WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); |
882 | 873 | ||
883 | request.BeginGetRequestStream(delegate(IAsyncResult res) | 874 | 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 | ||
890 | { | 875 | { |
891 | using (Stream requestStream = request.EndGetRequestStream(res)) | 876 | using (Stream requestStream = request.EndGetRequestStream(res)) |
892 | requestStream.Write(data, 0, length); | 877 | requestStream.Write(data, 0, length); |
893 | 878 | ||
894 | // capture how much time was spent writing | 879 | // capture how much time was spent writing |
895 | tickdata = Util.EnvironmentTickCountSubtract(tickstart); | 880 | // tickdata = Util.EnvironmentTickCountSubtract(tickstart); |
896 | 881 | ||
897 | request.BeginGetResponse(delegate(IAsyncResult ar) | 882 | request.BeginGetResponse(delegate(IAsyncResult ar) |
898 | { | 883 | { |
899 | <<<<<<< HEAD | ||
900 | using (WebResponse response = request.EndGetResponse(ar)) | 884 | using (WebResponse response = request.EndGetResponse(ar)) |
901 | { | 885 | { |
902 | try | 886 | try |
@@ -911,14 +895,6 @@ namespace OpenSim.Framework | |||
911 | { | 895 | { |
912 | } | 896 | } |
913 | } | 897 | } |
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 | ||
922 | 898 | ||
923 | action(deserial); | 899 | action(deserial); |
924 | 900 | ||
@@ -980,7 +956,6 @@ namespace OpenSim.Framework | |||
980 | "[ASYNC REQUEST]: Request {0} {1} failed with exception {2}{3}", | 956 | "[ASYNC REQUEST]: Request {0} {1} failed with exception {2}{3}", |
981 | verb, requestUrl, e.Message, e.StackTrace); | 957 | verb, requestUrl, e.Message, e.StackTrace); |
982 | } | 958 | } |
983 | <<<<<<< HEAD | ||
984 | 959 | ||
985 | // m_log.DebugFormat("[ASYNC REQUEST]: Received {0}", deserial.ToString()); | 960 | // m_log.DebugFormat("[ASYNC REQUEST]: Received {0}", deserial.ToString()); |
986 | 961 | ||
@@ -998,83 +973,34 @@ namespace OpenSim.Framework | |||
998 | }, null); | 973 | }, null); |
999 | } | 974 | } |
1000 | 975 | ||
1001 | int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); | 976 | tickdiff = Util.EnvironmentTickCountSubtract(tickstart); |
1002 | if (tickdiff > WebUtil.LongCallTime) | 977 | if (tickdiff > WebUtil.LongCallTime) |
1003 | { | 978 | { |
1004 | string originalRequest = null; | 979 | string originalRequest = null; |
1005 | 980 | ||
1006 | if (buffer != null) | 981 | 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 | ||
1023 | { | 982 | { |
1024 | originalRequest = Encoding.UTF8.GetString(buffer.ToArray()); | 983 | originalRequest = Encoding.UTF8.GetString(buffer.ToArray()); |
1025 | 984 | ||
1026 | <<<<<<< HEAD | ||
1027 | if (originalRequest.Length > WebUtil.MaxRequestDiagLength) | 985 | if (originalRequest.Length > WebUtil.MaxRequestDiagLength) |
1028 | originalRequest = originalRequest.Remove(WebUtil.MaxRequestDiagLength); | 986 | originalRequest = originalRequest.Remove(WebUtil.MaxRequestDiagLength); |
1029 | } | 987 | } |
1030 | ======= | 988 | m_log.InfoFormat( |
1031 | tickdiff = Util.EnvironmentTickCountSubtract(tickstart); | ||
1032 | if (tickdiff > WebUtil.LongCallTime) | ||
1033 | { | ||
1034 | /* | ||
1035 | string originalRequest = null; | ||
1036 | >>>>>>> avn/ubitvar | ||
1037 | |||
1038 | m_log.InfoFormat( | ||
1039 | "[LOGHTTP]: Slow AsynchronousRequestObject request {0} {1} to {2} took {3}ms, {4}ms writing, {5}", | 989 | "[LOGHTTP]: Slow AsynchronousRequestObject request {0} {1} to {2} took {3}ms, {4}ms writing, {5}", |
1040 | reqnum, verb, requestUrl, tickdiff, tickdata, | 990 | reqnum, verb, requestUrl, tickdiff, tickdata, |
1041 | originalRequest); | 991 | originalRequest); |
1042 | } | 992 | } |
1043 | else if (WebUtil.DebugLevel >= 4) | 993 | else if (WebUtil.DebugLevel >= 4) |
1044 | { | 994 | { |
1045 | m_log.DebugFormat("[LOGHTTP]: HTTP OUT {0} took {1}ms, {2}ms writing", | 995 | m_log.DebugFormat( |
1046 | reqnum, tickdiff, tickdata); | 996 | "[WEB UTIL]: HTTP OUT {0} took {1}ms", |
997 | reqnum, tickdiff); | ||
1047 | } | 998 | } |
1048 | <<<<<<< HEAD | ||
1049 | } | 999 | } |
1050 | finally | 1000 | finally |
1051 | { | 1001 | { |
1052 | if (buffer != null) | 1002 | if (buffer != null) |
1053 | buffer.Dispose(); | 1003 | 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 | ||
1078 | } | 1004 | } |
1079 | } | 1005 | } |
1080 | } | 1006 | } |
@@ -1136,11 +1062,8 @@ namespace OpenSim.Framework | |||
1136 | request.ContentLength = length; | 1062 | request.ContentLength = length; |
1137 | byte[] data = buffer.ToArray(); | 1063 | byte[] data = buffer.ToArray(); |
1138 | 1064 | ||
1139 | <<<<<<< HEAD | ||
1140 | if (WebUtil.DebugLevel >= 5) | 1065 | if (WebUtil.DebugLevel >= 5) |
1141 | WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); | 1066 | WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); |
1142 | ======= | ||
1143 | >>>>>>> avn/ubitvar | ||
1144 | 1067 | ||
1145 | Stream requestStream = null; | 1068 | Stream requestStream = null; |
1146 | try | 1069 | try |
@@ -1188,10 +1111,6 @@ namespace OpenSim.Framework | |||
1188 | if (tickdiff > WebUtil.LongCallTime) | 1111 | if (tickdiff > WebUtil.LongCallTime) |
1189 | { | 1112 | { |
1190 | m_log.InfoFormat( | 1113 | m_log.InfoFormat( |
1191 | <<<<<<< HEAD | ||
1192 | "[LOGHTTP]: Slow SynchronousRestForms request {0} {1} to {2} took {3}ms, {4}ms writing, {5}", | ||
1193 | reqnum, verb, requestUrl, tickdiff, tickdata, | ||
1194 | ======= | ||
1195 | "[FORMS]: Slow request {0} {1} {2} took {3}ms, {4}ms writing, {5}", | 1114 | "[FORMS]: Slow request {0} {1} {2} took {3}ms, {4}ms writing, {5}", |
1196 | reqnum, | 1115 | reqnum, |
1197 | verb, | 1116 | verb, |
@@ -1199,7 +1118,6 @@ namespace OpenSim.Framework | |||
1199 | tickdiff, | 1118 | tickdiff, |
1200 | tickset, | 1119 | tickset, |
1201 | tickdata, | 1120 | tickdata, |
1202 | >>>>>>> avn/ubitvar | ||
1203 | obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj); | 1121 | obj.Length > WebUtil.MaxRequestDiagLength ? obj.Remove(WebUtil.MaxRequestDiagLength) : obj); |
1204 | } | 1122 | } |
1205 | else if (WebUtil.DebugLevel >= 4) | 1123 | else if (WebUtil.DebugLevel >= 4) |
@@ -1336,8 +1254,6 @@ namespace OpenSim.Framework | |||
1336 | ht.ServicePoint.ConnectionLimit = maxConnections; | 1254 | ht.ServicePoint.ConnectionLimit = maxConnections; |
1337 | 1255 | ||
1338 | request.Method = verb; | 1256 | request.Method = verb; |
1339 | if (pTimeout != 0) | ||
1340 | request.Timeout = pTimeout * 1000; | ||
1341 | MemoryStream buffer = null; | 1257 | MemoryStream buffer = null; |
1342 | 1258 | ||
1343 | try | 1259 | try |
@@ -1351,29 +1267,17 @@ namespace OpenSim.Framework | |||
1351 | XmlWriterSettings settings = new XmlWriterSettings(); | 1267 | XmlWriterSettings settings = new XmlWriterSettings(); |
1352 | settings.Encoding = Encoding.UTF8; | 1268 | settings.Encoding = Encoding.UTF8; |
1353 | 1269 | ||
1354 | <<<<<<< HEAD | ||
1355 | using (XmlWriter writer = XmlWriter.Create(buffer, settings)) | 1270 | using (XmlWriter writer = XmlWriter.Create(buffer, settings)) |
1356 | { | 1271 | { |
1357 | XmlSerializer serializer = new XmlSerializer(type); | 1272 | XmlSerializer serializer = new XmlSerializer(type); |
1358 | serializer.Serialize(writer, obj); | 1273 | serializer.Serialize(writer, obj); |
1359 | writer.Flush(); | 1274 | writer.Flush(); |
1360 | } | 1275 | } |
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 | ||
1371 | 1276 | ||
1372 | int length = (int)buffer.Length; | 1277 | int length = (int)buffer.Length; |
1373 | request.ContentLength = length; | 1278 | request.ContentLength = length; |
1374 | byte[] data = buffer.ToArray(); | 1279 | byte[] data = buffer.ToArray(); |
1375 | 1280 | ||
1376 | <<<<<<< HEAD | ||
1377 | if (WebUtil.DebugLevel >= 5) | 1281 | if (WebUtil.DebugLevel >= 5) |
1378 | WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); | 1282 | WebUtil.LogOutgoingDetail("SEND", reqnum, System.Text.Encoding.UTF8.GetString(data)); |
1379 | 1283 | ||
@@ -1397,9 +1301,6 @@ namespace OpenSim.Framework | |||
1397 | } | 1301 | } |
1398 | } | 1302 | } |
1399 | 1303 | ||
1400 | ======= | ||
1401 | Stream requestStream = null; | ||
1402 | >>>>>>> avn/ubitvar | ||
1403 | try | 1304 | try |
1404 | { | 1305 | { |
1405 | using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse()) | 1306 | using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse()) |
@@ -1488,7 +1389,6 @@ namespace OpenSim.Framework | |||
1488 | 1389 | ||
1489 | return deserial; | 1390 | return deserial; |
1490 | } | 1391 | } |
1491 | |||
1492 | 1392 | ||
1493 | public static class XMLResponseHelper | 1393 | public static class XMLResponseHelper |
1494 | { | 1394 | { |