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.cs101
1 files changed, 93 insertions, 8 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index bf57fd4..86e5293 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -67,6 +67,11 @@ namespace OpenSim.Framework
67 public static int RequestNumber { get; internal set; } 67 public static int RequestNumber { get; internal set; }
68 68
69 /// <summary> 69 /// <summary>
70 /// Control where OSD requests should be serialized per endpoint.
71 /// </summary>
72 public static bool SerializeOSDRequestsPerEndpoint { get; set; }
73
74 /// <summary>
70 /// this is the header field used to communicate the local request id 75 /// this is the header field used to communicate the local request id
71 /// used for performance and debugging 76 /// used for performance and debugging
72 /// </summary> 77 /// </summary>
@@ -76,7 +81,7 @@ namespace OpenSim.Framework
76 /// Number of milliseconds a call can take before it is considered 81 /// Number of milliseconds a call can take before it is considered
77 /// a "long" call for warning & debugging purposes 82 /// a "long" call for warning & debugging purposes
78 /// </summary> 83 /// </summary>
79 public const int LongCallTime = 3000; 84 public const int LongCallTime = 500;
80 85
81 /// <summary> 86 /// <summary>
82 /// The maximum length of any data logged because of a long request time. 87 /// The maximum length of any data logged because of a long request time.
@@ -145,12 +150,52 @@ namespace OpenSim.Framework
145 150
146 public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout, bool compressed) 151 public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout, bool compressed)
147 { 152 {
148 lock (EndPointLock(url)) 153 if (SerializeOSDRequestsPerEndpoint)
149 { 154 {
150 return ServiceOSDRequestWorker(url,data,method,timeout,compressed); 155 lock (EndPointLock(url))
156 {
157 return ServiceOSDRequestWorker(url, data, method, timeout, compressed);
158 }
159 }
160 else
161 {
162 return ServiceOSDRequestWorker(url, data, method, timeout, compressed);
151 } 163 }
152 } 164 }
153 165
166 public static void LogOutgoingDetail(Stream outputStream)
167 {
168 using (StreamReader reader = new StreamReader(Util.Copy(outputStream), Encoding.UTF8))
169 {
170 string output;
171
172 if (DebugLevel == 5)
173 {
174 const int sampleLength = 80;
175 char[] sampleChars = new char[sampleLength];
176 reader.Read(sampleChars, 0, sampleLength);
177 output = new string(sampleChars);
178 }
179 else
180 {
181 output = reader.ReadToEnd();
182 }
183
184 LogOutgoingDetail(output);
185 }
186 }
187
188 public static void LogOutgoingDetail(string output)
189 {
190 if (DebugLevel == 5)
191 {
192 output = output.Substring(0, 80);
193 output = output + "...";
194 }
195
196 m_log.DebugFormat("[WEB UTIL]: {0}", output.Replace("\n", @"\n"));
197 }
198
154 private static OSDMap ServiceOSDRequestWorker(string url, OSDMap data, string method, int timeout, bool compressed) 199 private static OSDMap ServiceOSDRequestWorker(string url, OSDMap data, string method, int timeout, bool compressed)
155 { 200 {
156 int reqnum = RequestNumber++; 201 int reqnum = RequestNumber++;
@@ -163,6 +208,9 @@ namespace OpenSim.Framework
163 string errorMessage = "unknown error"; 208 string errorMessage = "unknown error";
164 int tickstart = Util.EnvironmentTickCount(); 209 int tickstart = Util.EnvironmentTickCount();
165 int tickdata = 0; 210 int tickdata = 0;
211 int tickcompressdata = 0;
212 int tickJsondata = 0;
213 int compsize = 0;
166 string strBuffer = null; 214 string strBuffer = null;
167 215
168 try 216 try
@@ -178,7 +226,13 @@ namespace OpenSim.Framework
178 // If there is some input, write it into the request 226 // If there is some input, write it into the request
179 if (data != null) 227 if (data != null)
180 { 228 {
181 strBuffer = OSDParser.SerializeJsonString(data); 229 strBuffer = OSDParser.SerializeJsonString(data);
230
231 tickJsondata = Util.EnvironmentTickCountSubtract(tickstart);
232
233 if (DebugLevel >= 5)
234 LogOutgoingDetail(strBuffer);
235
182 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer); 236 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer);
183 237
184 if (compressed) 238 if (compressed)
@@ -194,13 +248,19 @@ namespace OpenSim.Framework
194 // gets written on the strteam upon Dispose() 248 // gets written on the strteam upon Dispose()
195 } 249 }
196 byte[] buf = ms.ToArray(); 250 byte[] buf = ms.ToArray();
251
252 tickcompressdata = Util.EnvironmentTickCountSubtract(tickstart);
253
197 request.ContentLength = buf.Length; //Count bytes to send 254 request.ContentLength = buf.Length; //Count bytes to send
255 compsize = buf.Length;
198 using (Stream requestStream = request.GetRequestStream()) 256 using (Stream requestStream = request.GetRequestStream())
199 requestStream.Write(buf, 0, (int)buf.Length); 257 requestStream.Write(buf, 0, (int)buf.Length);
200 } 258 }
201 } 259 }
202 else 260 else
203 { 261 {
262 tickcompressdata = tickJsondata;
263 compsize = buffer.Length;
204 request.ContentType = "application/json"; 264 request.ContentType = "application/json";
205 request.ContentLength = buffer.Length; //Count bytes to send 265 request.ContentLength = buffer.Length; //Count bytes to send
206 using (Stream requestStream = request.GetRequestStream()) 266 using (Stream requestStream = request.GetRequestStream())
@@ -242,12 +302,16 @@ namespace OpenSim.Framework
242 int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); 302 int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
243 if (tickdiff > LongCallTime) 303 if (tickdiff > LongCallTime)
244 m_log.InfoFormat( 304 m_log.InfoFormat(
245 "[WEB UTIL]: Slow ServiceOSD request {0} {1} {2} took {3}ms, {4}ms writing, {5}", 305 "[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}",
246 reqnum, 306 reqnum,
247 method, 307 method,
248 url, 308 url,
249 tickdiff, 309 tickdiff,
250 tickdata, 310 tickdata,
311 tickJsondata,
312 tickcompressdata,
313 compsize,
314 strBuffer != null ? strBuffer.Length : 0,
251 strBuffer != null 315 strBuffer != null
252 ? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer) 316 ? (strBuffer.Length > MaxRequestDiagLength ? strBuffer.Remove(MaxRequestDiagLength) : strBuffer)
253 : ""); 317 : "");
@@ -358,6 +422,10 @@ namespace OpenSim.Framework
358 if (data != null) 422 if (data != null)
359 { 423 {
360 queryString = BuildQueryString(data); 424 queryString = BuildQueryString(data);
425
426 if (DebugLevel >= 5)
427 LogOutgoingDetail(queryString);
428
361 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(queryString); 429 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(queryString);
362 430
363 request.ContentLength = buffer.Length; 431 request.ContentLength = buffer.Length;
@@ -668,7 +736,7 @@ namespace OpenSim.Framework
668 /// <returns></returns> 736 /// <returns></returns>
669 public static string[] GetPreferredImageTypes(string accept) 737 public static string[] GetPreferredImageTypes(string accept)
670 { 738 {
671 if (accept == null || accept == string.Empty) 739 if (string.IsNullOrEmpty(accept))
672 return new string[0]; 740 return new string[0];
673 741
674 string[] types = accept.Split(new char[] { ',' }); 742 string[] types = accept.Split(new char[] { ',' });
@@ -769,6 +837,9 @@ namespace OpenSim.Framework
769 int length = (int)buffer.Length; 837 int length = (int)buffer.Length;
770 request.ContentLength = length; 838 request.ContentLength = length;
771 839
840 if (WebUtil.DebugLevel >= 5)
841 WebUtil.LogOutgoingDetail(buffer);
842
772 request.BeginGetRequestStream(delegate(IAsyncResult res) 843 request.BeginGetRequestStream(delegate(IAsyncResult res)
773 { 844 {
774 Stream requestStream = request.EndGetRequestStream(res); 845 Stream requestStream = request.EndGetRequestStream(res);
@@ -928,11 +999,12 @@ namespace OpenSim.Framework
928 /// <param name="verb"></param> 999 /// <param name="verb"></param>
929 /// <param name="requestUrl"></param> 1000 /// <param name="requestUrl"></param>
930 /// <param name="obj"> </param> 1001 /// <param name="obj"> </param>
1002 /// <param name="timeoutsecs"> </param>
931 /// <returns></returns> 1003 /// <returns></returns>
932 /// 1004 ///
933 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting 1005 /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting
934 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception> 1006 /// the request. You'll want to make sure you deal with this as they're not uncommon</exception>
935 public static string MakeRequest(string verb, string requestUrl, string obj) 1007 public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs)
936 { 1008 {
937 int reqnum = WebUtil.RequestNumber++; 1009 int reqnum = WebUtil.RequestNumber++;
938 1010
@@ -946,6 +1018,8 @@ namespace OpenSim.Framework
946 1018
947 WebRequest request = WebRequest.Create(requestUrl); 1019 WebRequest request = WebRequest.Create(requestUrl);
948 request.Method = verb; 1020 request.Method = verb;
1021 if (timeoutsecs > 0)
1022 request.Timeout = timeoutsecs * 1000;
949 string respstring = String.Empty; 1023 string respstring = String.Empty;
950 1024
951 int tickset = Util.EnvironmentTickCountSubtract(tickstart); 1025 int tickset = Util.EnvironmentTickCountSubtract(tickstart);
@@ -966,6 +1040,9 @@ namespace OpenSim.Framework
966 length = (int)obj.Length; 1040 length = (int)obj.Length;
967 request.ContentLength = length; 1041 request.ContentLength = length;
968 1042
1043 if (WebUtil.DebugLevel >= 5)
1044 WebUtil.LogOutgoingDetail(buffer);
1045
969 Stream requestStream = null; 1046 Stream requestStream = null;
970 try 1047 try
971 { 1048 {
@@ -1039,6 +1116,11 @@ namespace OpenSim.Framework
1039 1116
1040 return respstring; 1117 return respstring;
1041 } 1118 }
1119
1120 public static string MakeRequest(string verb, string requestUrl, string obj)
1121 {
1122 return MakeRequest(verb, requestUrl, obj, -1);
1123 }
1042 } 1124 }
1043 1125
1044 public class SynchronousRestObjectRequester 1126 public class SynchronousRestObjectRequester
@@ -1111,6 +1193,9 @@ namespace OpenSim.Framework
1111 int length = (int)buffer.Length; 1193 int length = (int)buffer.Length;
1112 request.ContentLength = length; 1194 request.ContentLength = length;
1113 1195
1196 if (WebUtil.DebugLevel >= 5)
1197 WebUtil.LogOutgoingDetail(buffer);
1198
1114 Stream requestStream = null; 1199 Stream requestStream = null;
1115 try 1200 try
1116 { 1201 {
@@ -1213,4 +1298,4 @@ namespace OpenSim.Framework
1213 return deserial; 1298 return deserial;
1214 } 1299 }
1215 } 1300 }
1216} 1301} \ No newline at end of file