diff options
author | Melanie Thielker | 2014-06-21 00:39:55 +0200 |
---|---|---|
committer | Melanie Thielker | 2014-06-21 00:39:55 +0200 |
commit | 159fcbf150b7da0e229b29aa7b94793484543d12 (patch) | |
tree | b8c0ff3b4c758a3fba8315b556c923ef4c02a185 /OpenSim/Framework/WebUtil.cs | |
parent | Merge commit '68c8633ba18f0a11cfc0ed04d1d0c7c59e6cec76' (diff) | |
parent | Merge branch 'master' into careminster (diff) | |
download | opensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.zip opensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.tar.gz opensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.tar.bz2 opensim-SC_OLD-159fcbf150b7da0e229b29aa7b94793484543d12.tar.xz |
Merge branch 'master' of ssh://3dhosting.de/var/git/careminster
Conflicts:
OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
Diffstat (limited to 'OpenSim/Framework/WebUtil.cs')
-rw-r--r-- | OpenSim/Framework/WebUtil.cs | 82 |
1 files changed, 76 insertions, 6 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index bf57fd4..33ef8e0 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> |
@@ -145,10 +150,50 @@ 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) |
154 | { | ||
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); | ||
163 | } | ||
164 | } | ||
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) | ||
149 | { | 191 | { |
150 | return ServiceOSDRequestWorker(url,data,method,timeout,compressed); | 192 | output = output.Substring(0, 80); |
193 | output = output + "..."; | ||
151 | } | 194 | } |
195 | |||
196 | m_log.DebugFormat("[WEB UTIL]: {0}", output.Replace("\n", @"\n")); | ||
152 | } | 197 | } |
153 | 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) |
@@ -178,7 +223,11 @@ namespace OpenSim.Framework | |||
178 | // If there is some input, write it into the request | 223 | // If there is some input, write it into the request |
179 | if (data != null) | 224 | if (data != null) |
180 | { | 225 | { |
181 | strBuffer = OSDParser.SerializeJsonString(data); | 226 | strBuffer = OSDParser.SerializeJsonString(data); |
227 | |||
228 | if (DebugLevel >= 5) | ||
229 | LogOutgoingDetail(strBuffer); | ||
230 | |||
182 | byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer); | 231 | byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer); |
183 | 232 | ||
184 | if (compressed) | 233 | if (compressed) |
@@ -358,6 +407,10 @@ namespace OpenSim.Framework | |||
358 | if (data != null) | 407 | if (data != null) |
359 | { | 408 | { |
360 | queryString = BuildQueryString(data); | 409 | queryString = BuildQueryString(data); |
410 | |||
411 | if (DebugLevel >= 5) | ||
412 | LogOutgoingDetail(queryString); | ||
413 | |||
361 | byte[] buffer = System.Text.Encoding.UTF8.GetBytes(queryString); | 414 | byte[] buffer = System.Text.Encoding.UTF8.GetBytes(queryString); |
362 | 415 | ||
363 | request.ContentLength = buffer.Length; | 416 | request.ContentLength = buffer.Length; |
@@ -668,7 +721,7 @@ namespace OpenSim.Framework | |||
668 | /// <returns></returns> | 721 | /// <returns></returns> |
669 | public static string[] GetPreferredImageTypes(string accept) | 722 | public static string[] GetPreferredImageTypes(string accept) |
670 | { | 723 | { |
671 | if (accept == null || accept == string.Empty) | 724 | if (string.IsNullOrEmpty(accept)) |
672 | return new string[0]; | 725 | return new string[0]; |
673 | 726 | ||
674 | string[] types = accept.Split(new char[] { ',' }); | 727 | string[] types = accept.Split(new char[] { ',' }); |
@@ -769,6 +822,9 @@ namespace OpenSim.Framework | |||
769 | int length = (int)buffer.Length; | 822 | int length = (int)buffer.Length; |
770 | request.ContentLength = length; | 823 | request.ContentLength = length; |
771 | 824 | ||
825 | if (WebUtil.DebugLevel >= 5) | ||
826 | WebUtil.LogOutgoingDetail(buffer); | ||
827 | |||
772 | request.BeginGetRequestStream(delegate(IAsyncResult res) | 828 | request.BeginGetRequestStream(delegate(IAsyncResult res) |
773 | { | 829 | { |
774 | Stream requestStream = request.EndGetRequestStream(res); | 830 | Stream requestStream = request.EndGetRequestStream(res); |
@@ -928,11 +984,12 @@ namespace OpenSim.Framework | |||
928 | /// <param name="verb"></param> | 984 | /// <param name="verb"></param> |
929 | /// <param name="requestUrl"></param> | 985 | /// <param name="requestUrl"></param> |
930 | /// <param name="obj"> </param> | 986 | /// <param name="obj"> </param> |
987 | /// <param name="timeoutsecs"> </param> | ||
931 | /// <returns></returns> | 988 | /// <returns></returns> |
932 | /// | 989 | /// |
933 | /// <exception cref="System.Net.WebException">Thrown if we encounter a network issue while posting | 990 | /// <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> | 991 | /// 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) | 992 | public static string MakeRequest(string verb, string requestUrl, string obj, int timeoutsecs) |
936 | { | 993 | { |
937 | int reqnum = WebUtil.RequestNumber++; | 994 | int reqnum = WebUtil.RequestNumber++; |
938 | 995 | ||
@@ -946,6 +1003,8 @@ namespace OpenSim.Framework | |||
946 | 1003 | ||
947 | WebRequest request = WebRequest.Create(requestUrl); | 1004 | WebRequest request = WebRequest.Create(requestUrl); |
948 | request.Method = verb; | 1005 | request.Method = verb; |
1006 | if (timeoutsecs > 0) | ||
1007 | request.Timeout = timeoutsecs * 1000; | ||
949 | string respstring = String.Empty; | 1008 | string respstring = String.Empty; |
950 | 1009 | ||
951 | int tickset = Util.EnvironmentTickCountSubtract(tickstart); | 1010 | int tickset = Util.EnvironmentTickCountSubtract(tickstart); |
@@ -966,6 +1025,9 @@ namespace OpenSim.Framework | |||
966 | length = (int)obj.Length; | 1025 | length = (int)obj.Length; |
967 | request.ContentLength = length; | 1026 | request.ContentLength = length; |
968 | 1027 | ||
1028 | if (WebUtil.DebugLevel >= 5) | ||
1029 | WebUtil.LogOutgoingDetail(buffer); | ||
1030 | |||
969 | Stream requestStream = null; | 1031 | Stream requestStream = null; |
970 | try | 1032 | try |
971 | { | 1033 | { |
@@ -1039,6 +1101,11 @@ namespace OpenSim.Framework | |||
1039 | 1101 | ||
1040 | return respstring; | 1102 | return respstring; |
1041 | } | 1103 | } |
1104 | |||
1105 | public static string MakeRequest(string verb, string requestUrl, string obj) | ||
1106 | { | ||
1107 | return MakeRequest(verb, requestUrl, obj, -1); | ||
1108 | } | ||
1042 | } | 1109 | } |
1043 | 1110 | ||
1044 | public class SynchronousRestObjectRequester | 1111 | public class SynchronousRestObjectRequester |
@@ -1111,6 +1178,9 @@ namespace OpenSim.Framework | |||
1111 | int length = (int)buffer.Length; | 1178 | int length = (int)buffer.Length; |
1112 | request.ContentLength = length; | 1179 | request.ContentLength = length; |
1113 | 1180 | ||
1181 | if (WebUtil.DebugLevel >= 5) | ||
1182 | WebUtil.LogOutgoingDetail(buffer); | ||
1183 | |||
1114 | Stream requestStream = null; | 1184 | Stream requestStream = null; |
1115 | try | 1185 | try |
1116 | { | 1186 | { |
@@ -1213,4 +1283,4 @@ namespace OpenSim.Framework | |||
1213 | return deserial; | 1283 | return deserial; |
1214 | } | 1284 | } |
1215 | } | 1285 | } |
1216 | } | 1286 | } \ No newline at end of file |