aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs16
-rw-r--r--OpenSim/Framework/WebUtil.cs240
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs2
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs3
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs3
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs64
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs4
-rw-r--r--OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs2
-rw-r--r--OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs557
9 files changed, 380 insertions, 511 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
index 3343f60..86ad7aa 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
@@ -346,9 +346,15 @@ namespace OpenSim.Framework.Servers.HttpServer
346 /// <param name="response"></param> 346 /// <param name="response"></param>
347 public virtual void HandleRequest(OSHttpRequest request, OSHttpResponse response) 347 public virtual void HandleRequest(OSHttpRequest request, OSHttpResponse response)
348 { 348 {
349 string reqnum = "unknown";
350 int tickstart = Environment.TickCount;
351
349 try 352 try
350 { 353 {
351 //m_log.Debug("[BASE HTTP SERVER]: Handling request to " + request.RawUrl); 354 // OpenSim.Framework.WebUtil.OSHeaderRequestID
355 if (request.Headers["opensim-request-id"] != null)
356 reqnum = String.Format("{0}:{1}",request.RemoteIPEndPoint,request.Headers["opensim-request-id"]);
357 // m_log.DebugFormat("[BASE HTTP SERVER]: <{0}> handle request for {1}",reqnum,request.RawUrl);
352 358
353 Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true); 359 Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true);
354 360
@@ -576,6 +582,14 @@ namespace OpenSim.Framework.Servers.HttpServer
576 m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw {0}", e); 582 m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw {0}", e);
577 SendHTML500(response); 583 SendHTML500(response);
578 } 584 }
585 finally
586 {
587 // Every month or so this will wrap and give bad numbers, not really a problem
588 // since its just for reporting, 200ms limit can be adjusted
589 int tickdiff = Environment.TickCount - tickstart;
590 if (tickdiff > 200)
591 m_log.InfoFormat("[BASE HTTP SERVER]: slow request <{0}> for {1} took {2} ms",reqnum,request.RawUrl,tickdiff);
592 }
579 } 593 }
580 594
581 private bool TryGetStreamHandler(string handlerKey, out IRequestHandler streamHandler) 595 private bool TryGetStreamHandler(string handlerKey, out IRequestHandler streamHandler)
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs
index 1c856af..d88d095 100644
--- a/OpenSim/Framework/WebUtil.cs
+++ b/OpenSim/Framework/WebUtil.cs
@@ -50,6 +50,16 @@ namespace OpenSim.Framework
50 LogManager.GetLogger( 50 LogManager.GetLogger(
51 MethodBase.GetCurrentMethod().DeclaringType); 51 MethodBase.GetCurrentMethod().DeclaringType);
52 52
53 private static int m_requestNumber = 0;
54
55 // this is the header field used to communicate the local request id
56 // used for performance and debugging
57 public const string OSHeaderRequestID = "opensim-request-id";
58
59 // number of milliseconds a call can take before it is considered
60 // a "long" call for warning & debugging purposes
61 public const int LongCallTime = 200;
62
53 /// <summary> 63 /// <summary>
54 /// Send LLSD to an HTTP client in application/llsd+json form 64 /// Send LLSD to an HTTP client in application/llsd+json form
55 /// </summary> 65 /// </summary>
@@ -123,26 +133,186 @@ namespace OpenSim.Framework
123 } 133 }
124 134
125 /// <summary> 135 /// <summary>
136 /// PUT JSON-encoded data to a web service that returns LLSD or
137 /// JSON data
138 /// </summary>
139 public static OSDMap PutToService(string url, OSDMap data)
140 {
141 return ServiceOSDRequest(url,data,"PUT",10000);
142 }
143
144 public static OSDMap PostToService(string url, OSDMap data)
145 {
146 return ServiceOSDRequest(url,data,"POST",10000);
147 }
148
149 public static OSDMap GetFromService(string url)
150 {
151 return ServiceOSDRequest(url,null,"GET",10000);
152 }
153
154 public static OSDMap ServiceOSDRequest(string url, OSDMap data, string method, int timeout)
155 {
156 int reqnum = m_requestNumber++;
157 // m_log.DebugFormat("[WEB UTIL]: <{0}> start osd request for {1}, method {2}",reqnum,url,method);
158
159 string errorMessage = "unknown error";
160 int tickstart = Util.EnvironmentTickCount();
161 int tickdata = 0;
162
163 try
164 {
165 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
166 request.Method = method;
167 request.Timeout = timeout;
168 request.KeepAlive = false;
169 request.MaximumAutomaticRedirections = 10;
170 request.ReadWriteTimeout = timeout / 4;
171 request.Headers[OSHeaderRequestID] = reqnum.ToString();
172
173 // If there is some input, write it into the request
174 if (data != null)
175 {
176 string strBuffer = OSDParser.SerializeJsonString(data);
177 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(strBuffer);
178
179 request.ContentType = "application/json";
180 request.ContentLength = buffer.Length; //Count bytes to send
181 using (Stream requestStream = request.GetRequestStream())
182 requestStream.Write(buffer, 0, buffer.Length); //Send it
183 }
184
185 // capture how much time was spent writing, this may seem silly
186 // but with the number concurrent requests, this often blocks
187 tickdata = Util.EnvironmentTickCountSubtract(tickstart);
188
189 using (WebResponse response = request.GetResponse())
190 {
191 using (Stream responseStream = response.GetResponseStream())
192 {
193 string responseStr = null;
194 responseStr = responseStream.GetStreamString();
195 // m_log.DebugFormat("[WEB UTIL]: <{0}> response is <{1}>",reqnum,responseStr);
196 return CanonicalizeResults(responseStr);
197 }
198 }
199 }
200 catch (WebException we)
201 {
202 errorMessage = we.Message;
203 if (we.Status == WebExceptionStatus.ProtocolError)
204 {
205 HttpWebResponse webResponse = (HttpWebResponse)we.Response;
206 errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription);
207 }
208 }
209 catch (Exception ex)
210 {
211 errorMessage = ex.Message;
212 }
213 finally
214 {
215 // This just dumps a warning for any operation that takes more than 100 ms
216 int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
217 if (tickdiff > LongCallTime)
218 m_log.InfoFormat("[WEB UTIL]: osd request <{0}> (URI:{1}, METHOD:{2}) took {3}ms overall, {4}ms writing",
219 reqnum,url,method,tickdiff,tickdata);
220 }
221
222 m_log.WarnFormat("[WEB UTIL] <{0}> osd request failed: {1}",reqnum,errorMessage);
223 return ErrorResponseMap(errorMessage);
224 }
225
226 /// <summary>
227 /// Since there are no consistencies in the way web requests are
228 /// formed, we need to do a little guessing about the result format.
229 /// Keys:
230 /// Success|success == the success fail of the request
231 /// _RawResult == the raw string that came back
232 /// _Result == the OSD unpacked string
233 /// </summary>
234 private static OSDMap CanonicalizeResults(string response)
235 {
236 OSDMap result = new OSDMap();
237
238 // Default values
239 result["Success"] = OSD.FromBoolean(true);
240 result["success"] = OSD.FromBoolean(true);
241 result["_RawResult"] = OSD.FromString(response);
242 result["_Result"] = new OSDMap();
243
244 if (response.Equals("true",System.StringComparison.OrdinalIgnoreCase))
245 return result;
246
247 if (response.Equals("false",System.StringComparison.OrdinalIgnoreCase))
248 {
249 result["Success"] = OSD.FromBoolean(false);
250 result["success"] = OSD.FromBoolean(false);
251 return result;
252 }
253
254 try
255 {
256 OSD responseOSD = OSDParser.Deserialize(response);
257 if (responseOSD.Type == OSDType.Map)
258 {
259 result["_Result"] = (OSDMap)responseOSD;
260 return result;
261 }
262 }
263 catch (Exception e)
264 {
265 // don't need to treat this as an error... we're just guessing anyway
266 m_log.DebugFormat("[WEB UTIL] couldn't decode <{0}>: {1}",response,e.Message);
267 }
268
269 return result;
270 }
271
272 /// <summary>
126 /// POST URL-encoded form data to a web service that returns LLSD or 273 /// POST URL-encoded form data to a web service that returns LLSD or
127 /// JSON data 274 /// JSON data
128 /// </summary> 275 /// </summary>
129 public static OSDMap PostToService(string url, NameValueCollection data) 276 public static OSDMap PostToService(string url, NameValueCollection data)
130 { 277 {
131 string errorMessage; 278 return ServiceFormRequest(url,data,10000);
279 }
280
281 public static OSDMap ServiceFormRequest(string url, NameValueCollection data, int timeout)
282 {
283 int reqnum = m_requestNumber++;
284 string method = (data != null && data["RequestMethod"] != null) ? data["RequestMethod"] : "unknown";
285 // m_log.DebugFormat("[WEB UTIL]: <{0}> start form request for {1}, method {2}",reqnum,url,method);
286
287 string errorMessage = "unknown error";
288 int tickstart = Util.EnvironmentTickCount();
289 int tickdata = 0;
132 290
133 try 291 try
134 { 292 {
135 string queryString = BuildQueryString(data); 293
136 byte[] requestData = System.Text.Encoding.UTF8.GetBytes(queryString);
137
138 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); 294 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
139 request.Method = "POST"; 295 request.Method = "POST";
140 request.ContentLength = requestData.Length; 296 request.Timeout = timeout;
141 request.ContentType = "application/x-www-form-urlencoded"; 297 request.KeepAlive = false;
298 request.MaximumAutomaticRedirections = 10;
299 request.ReadWriteTimeout = timeout / 4;
300 request.Headers[OSHeaderRequestID] = reqnum.ToString();
301
302 if (data != null)
303 {
304 string queryString = BuildQueryString(data);
305 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(queryString);
306
307 request.ContentLength = buffer.Length;
308 request.ContentType = "application/x-www-form-urlencoded";
309 using (Stream requestStream = request.GetRequestStream())
310 requestStream.Write(buffer, 0, buffer.Length);
311 }
142 312
143 Stream requestStream = request.GetRequestStream(); 313 // capture how much time was spent writing, this may seem silly
144 requestStream.Write(requestData, 0, requestData.Length); 314 // but with the number concurrent requests, this often blocks
145 requestStream.Close(); 315 tickdata = Util.EnvironmentTickCountSubtract(tickstart);
146 316
147 using (WebResponse response = request.GetResponse()) 317 using (WebResponse response = request.GetResponse())
148 { 318 {
@@ -150,34 +320,50 @@ namespace OpenSim.Framework
150 { 320 {
151 string responseStr = null; 321 string responseStr = null;
152 322
153 try 323 responseStr = responseStream.GetStreamString();
154 { 324 OSD responseOSD = OSDParser.Deserialize(responseStr);
155 responseStr = responseStream.GetStreamString(); 325 if (responseOSD.Type == OSDType.Map)
156 OSD responseOSD = OSDParser.Deserialize(responseStr); 326 return (OSDMap)responseOSD;
157 if (responseOSD.Type == OSDType.Map)
158 return (OSDMap)responseOSD;
159 else
160 errorMessage = "Response format was invalid.";
161 }
162 catch (Exception ex)
163 {
164 if (!String.IsNullOrEmpty(responseStr))
165 errorMessage = "Failed to parse the response:\n" + responseStr;
166 else
167 errorMessage = "Failed to retrieve the response: " + ex.Message;
168 }
169 } 327 }
170 } 328 }
171 } 329 }
330 catch (WebException we)
331 {
332 errorMessage = we.Message;
333 if (we.Status == WebExceptionStatus.ProtocolError)
334 {
335 HttpWebResponse webResponse = (HttpWebResponse)we.Response;
336 errorMessage = String.Format("[{0}] {1}",webResponse.StatusCode,webResponse.StatusDescription);
337 }
338 }
172 catch (Exception ex) 339 catch (Exception ex)
173 { 340 {
174 m_log.Warn("POST to URL " + url + " failed: " + ex);
175 errorMessage = ex.Message; 341 errorMessage = ex.Message;
176 } 342 }
343 finally
344 {
345 int tickdiff = Util.EnvironmentTickCountSubtract(tickstart);
346 if (tickdiff > LongCallTime)
347 m_log.InfoFormat("[WEB UTIL]: form request <{0}> (URI:{1}, METHOD:{2}) took {3}ms overall, {4}ms writing",
348 reqnum,url,method,tickdiff,tickdata);
349 }
177 350
178 return new OSDMap { { "Message", OSD.FromString("Service request failed. " + errorMessage) } }; 351 m_log.WarnFormat("[WEB UTIL]: <{0}> form request failed: {1}",reqnum,errorMessage);
352 return ErrorResponseMap(errorMessage);
179 } 353 }
180 354
355 /// <summary>
356 /// Create a response map for an error, trying to keep
357 /// the result formats consistent
358 /// </summary>
359 private static OSDMap ErrorResponseMap(string msg)
360 {
361 OSDMap result = new OSDMap();
362 result["Success"] = "False";
363 result["Message"] = OSD.FromString("Service request failed: " + msg);
364 return result;
365 }
366
181 #region Uri 367 #region Uri
182 368
183 /// <summary> 369 /// <summary>
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
index 7396c2d..6985449 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
@@ -648,7 +648,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
648 IClientAPI client; 648 IClientAPI client;
649 if (!m_scene.TryGetClient(address, out client) || !(client is LLClientView)) 649 if (!m_scene.TryGetClient(address, out client) || !(client is LLClientView))
650 { 650 {
651 m_log.Debug("[LLUDPSERVER]: Received a " + packet.Type + " packet from an unrecognized source: " + address + " in " + m_scene.RegionInfo.RegionName); 651 //m_log.Debug("[LLUDPSERVER]: Received a " + packet.Type + " packet from an unrecognized source: " + address + " in " + m_scene.RegionInfo.RegionName);
652 return; 652 return;
653 } 653 }
654 654
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 208c2a6..b8ad3ca 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -2858,7 +2858,8 @@ namespace OpenSim.Region.Framework.Scenes
2858// m_log.WarnFormat("[SP] Send avatar data from {0} to {1}",m_uuid,avatar.ControllingClient.AgentId); 2858// m_log.WarnFormat("[SP] Send avatar data from {0} to {1}",m_uuid,avatar.ControllingClient.AgentId);
2859 2859
2860 avatar.ControllingClient.SendAvatarDataImmediate(this); 2860 avatar.ControllingClient.SendAvatarDataImmediate(this);
2861 Animator.SendAnimPackToClient(avatar.ControllingClient); 2861 if (Animator != null)
2862 Animator.SendAnimPackToClient(avatar.ControllingClient);
2862 } 2863 }
2863 2864
2864 /// <summary> 2865 /// <summary>
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
index 4aab87f..a8dec63 100644
--- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs
@@ -123,8 +123,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
123 m_log.InfoFormat("[GROUPS]: Initializing {0}", this.Name); 123 m_log.InfoFormat("[GROUPS]: Initializing {0}", this.Name);
124 124
125 m_groupNoticesEnabled = groupsConfig.GetBoolean("NoticesEnabled", true); 125 m_groupNoticesEnabled = groupsConfig.GetBoolean("NoticesEnabled", true);
126 m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", true); 126 m_debugEnabled = groupsConfig.GetBoolean("DebugEnabled", false);
127
128 } 127 }
129 } 128 }
130 129
diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
index a1d9167..1aa3282 100644
--- a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs
@@ -283,46 +283,52 @@ namespace OpenSim.Services.Connectors.Hypergrid
283 283
284 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason) 284 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string myipaddress, out string reason)
285 { 285 {
286 HttpWebRequest AgentCreateRequest = null; 286 // m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: CreateAgent start");
287
287 myipaddress = String.Empty; 288 myipaddress = String.Empty;
288 reason = String.Empty; 289 reason = String.Empty;
289 290
290 if (SendRequest(destination, aCircuit, flags, out reason, out AgentCreateRequest)) 291 if (destination == null)
291 { 292 {
292 string response = GetResponse(AgentCreateRequest, out reason); 293 m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Given destination is null");
293 bool success = true; 294 return false;
294 UnpackResponse(response, out success, out reason, out myipaddress);
295 return success;
296 } 295 }
297 296
298 return false; 297 string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/";
299 }
300
301 protected void UnpackResponse(string response, out bool result, out string reason, out string ipaddress)
302 {
303 result = true;
304 reason = string.Empty;
305 ipaddress = string.Empty;
306 298
307 if (!String.IsNullOrEmpty(response)) 299 try
308 { 300 {
309 try 301 OSDMap args = aCircuit.PackAgentCircuitData();
310 { 302
311 // we assume we got an OSDMap back 303 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
312 OSDMap r = Util.GetOSDMap(response); 304 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
313 result = r["success"].AsBoolean(); 305 args["destination_name"] = OSD.FromString(destination.RegionName);
314 reason = r["reason"].AsString(); 306 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
315 ipaddress = r["your_ip"].AsString(); 307 args["teleport_flags"] = OSD.FromString(flags.ToString());
316 } 308
317 catch (NullReferenceException e) 309 OSDMap result = WebUtil.PostToService(uri,args);
310 if (result["Success"].AsBoolean())
318 { 311 {
319 m_log.InfoFormat("[GATEKEEPER SERVICE CONNECTOR]: exception on UnpackResponse of DoCreateChildAgentCall {0}", e.Message); 312 OSDMap unpacked = (OSDMap)result["_Result"];
320 reason = "Internal error"; 313
321 result = false; 314 if (unpacked != null)
315 {
316 reason = unpacked["reason"].AsString();
317 myipaddress = unpacked["your_ip"].AsString();
318 return unpacked["success"].AsBoolean();
319 }
322 } 320 }
321
322 reason = result["Message"] != null ? result["Message"].AsString() : "error";
323 return false;
324 }
325 catch (Exception e)
326 {
327 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e.ToString());
328 reason = e.Message;
323 } 329 }
324 }
325
326 330
331 return false;
332 }
327 } 333 }
328} 334}
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs
index 65a02df..810399c 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianAvatarServiceConnector.cs
@@ -159,9 +159,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
159 return false; 159 return false;
160 } 160 }
161 161
162// DEBUG ON 162 // m_log.DebugFormat("[SIMIAN AVATAR CONNECTOR] save appearance for {0}",userID);
163 m_log.WarnFormat("[SIMIAN AVATAR CONNECTOR] save appearance for {0}",userID);
164// DEBUG OFF
165 163
166 NameValueCollection requestArgs = new NameValueCollection 164 NameValueCollection requestArgs = new NameValueCollection
167 { 165 {
diff --git a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
index 5584c62..daf94fe 100644
--- a/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
+++ b/OpenSim/Services/Connectors/SimianGrid/SimianGridServiceConnector.cs
@@ -307,7 +307,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
307 { "Enabled", "1" } 307 { "Enabled", "1" }
308 }; 308 };
309 309
310 m_log.WarnFormat("[SIMIAN GRID CONNECTOR] request regions by range {0} to {1}",minPosition.ToString(),maxPosition.ToString()); 310 //m_log.DebugFormat("[SIMIAN GRID CONNECTOR] request regions by range {0} to {1}",minPosition.ToString(),maxPosition.ToString());
311 311
312 312
313 OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs); 313 OSDMap response = WebUtil.PostToService(m_ServerURI, requestArgs);
diff --git a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
index b877ca5..fbfc2dd 100644
--- a/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Simulation/SimulationServiceConnector.cs
@@ -75,473 +75,191 @@ namespace OpenSim.Services.Connectors.Simulation
75 return "agent/"; 75 return "agent/";
76 } 76 }
77 77
78 /// <summary>
79 ///
80 /// </summary>
78 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason) 81 public bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason)
79 { 82 {
80 HttpWebRequest AgentCreateRequest = null; 83 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateAgent start");
81 reason = String.Empty; 84
82
83 if (SendRequest(destination, aCircuit, flags, out reason, out AgentCreateRequest))
84 {
85 string response = GetResponse(AgentCreateRequest, out reason);
86 bool success = true;
87 UnpackResponse(response, out success, out reason);
88 return success;
89 }
90
91 return false;
92 }
93
94
95 protected bool SendRequest(GridRegion destination, AgentCircuitData aCircuit, uint flags, out string reason, out HttpWebRequest AgentCreateRequest)
96 {
97 reason = String.Empty; 85 reason = String.Empty;
98 AgentCreateRequest = null;
99
100 if (destination == null) 86 if (destination == null)
101 { 87 {
102 reason = "Destination is null";
103 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null"); 88 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Given destination is null");
104 return false; 89 return false;
105 } 90 }
106 91
107 string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/"; 92 string uri = destination.ServerURI + AgentPath() + aCircuit.AgentID + "/";
108 93
109 AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri);
110 AgentCreateRequest.Method = "POST";
111 AgentCreateRequest.ContentType = "application/json";
112 AgentCreateRequest.Timeout = 10000;
113 //AgentCreateRequest.KeepAlive = false;
114 //AgentCreateRequest.Headers.Add("Authorization", authKey);
115
116 // Fill it in
117 OSDMap args = PackCreateAgentArguments(aCircuit, destination, flags);
118 if (args == null)
119 return false;
120
121 string strBuffer = "";
122 byte[] buffer = new byte[1];
123 try 94 try
124 { 95 {
125 strBuffer = OSDParser.SerializeJsonString(args); 96 OSDMap args = aCircuit.PackAgentCircuitData();
126 Encoding str = Util.UTF8;
127 buffer = str.GetBytes(strBuffer);
128 97
129 } 98 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
130 catch (Exception e) 99 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
131 { 100 args["destination_name"] = OSD.FromString(destination.RegionName);
132 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message); 101 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
133 // ignore. buffer will be empty, caller should check. 102 args["teleport_flags"] = OSD.FromString(flags.ToString());
134 }
135 103
136 Stream os = null; 104 OSDMap result = WebUtil.PostToService(uri,args);
137 try 105 if (result["Success"].AsBoolean())
138 { // send the Post 106 return true;
139 AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send 107
140 os = AgentCreateRequest.GetRequestStream(); 108 reason = result["Message"] != null ? result["Message"].AsString() : "error";
141 os.Write(buffer, 0, strBuffer.Length); //Send it
142 m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}",
143 uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY);
144 }
145 //catch (WebException ex)
146 catch
147 {
148 //m_log.ErrorFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message);
149 reason = "cannot contact remote region";
150 return false; 109 return false;
151 } 110 }
152 finally
153 {
154 if (os != null)
155 os.Close();
156 }
157
158 return true;
159 }
160
161 protected string GetResponse(HttpWebRequest AgentCreateRequest, out string reason)
162 {
163 // Let's wait for the response
164 //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall");
165 reason = string.Empty;
166
167 WebResponse webResponse = null;
168 StreamReader sr = null;
169 string response = string.Empty;
170 try
171 {
172 webResponse = AgentCreateRequest.GetResponse();
173 if (webResponse == null)
174 {
175 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on DoCreateChildAgentCall post");
176 }
177 else
178 {
179
180 sr = new StreamReader(webResponse.GetResponseStream());
181 response = sr.ReadToEnd().Trim();
182 m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response);
183 }
184 }
185 catch (WebException ex)
186 {
187 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message);
188 reason = "Destination did not reply";
189 return string.Empty;
190 }
191 finally
192 {
193 if (sr != null)
194 sr.Close();
195 }
196
197 return response;
198 }
199
200 protected void UnpackResponse(string response, out bool result, out string reason)
201 {
202 result = true;
203 reason = string.Empty;
204 if (!String.IsNullOrEmpty(response))
205 {
206 try
207 {
208 // we assume we got an OSDMap back
209 OSDMap r = Util.GetOSDMap(response);
210 result = r["success"].AsBoolean();
211 reason = r["reason"].AsString();
212 }
213 catch (NullReferenceException e)
214 {
215 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message);
216
217 // check for old style response
218 if (response.ToLower().StartsWith("true"))
219 result = true;
220
221 result = false;
222 }
223 }
224 }
225
226 protected virtual OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion destination, uint flags)
227 {
228 OSDMap args = null;
229 try
230 {
231 args = aCircuit.PackAgentCircuitData();
232 }
233 catch (Exception e) 111 catch (Exception e)
234 { 112 {
235 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message); 113 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: CreateAgent failed with exception: " + e.ToString());
236 return null; 114 reason = e.Message;
237 } 115 }
238 116
239 // Add the input arguments 117 return false;
240 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
241 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
242 args["destination_name"] = OSD.FromString(destination.RegionName);
243 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
244 args["teleport_flags"] = OSD.FromString(flags.ToString());
245
246 return args;
247 } 118 }
248 119
120 /// <summary>
121 /// Send complete data about an agent in this region to a neighbor
122 /// </summary>
249 public bool UpdateAgent(GridRegion destination, AgentData data) 123 public bool UpdateAgent(GridRegion destination, AgentData data)
250 { 124 {
251 return UpdateAgent(destination, (IAgentData)data); 125 return UpdateAgent(destination, (IAgentData)data);
252 } 126 }
253 127
128 /// <summary>
129 /// Send updated position information about an agent in this region to a neighbor
130 /// This operation may be called very frequently if an avatar is moving about in
131 /// the region.
132 /// </summary>
254 public bool UpdateAgent(GridRegion destination, AgentPosition data) 133 public bool UpdateAgent(GridRegion destination, AgentPosition data)
255 { 134 {
135 // we need a better throttle for these
136 // return false;
137
256 return UpdateAgent(destination, (IAgentData)data); 138 return UpdateAgent(destination, (IAgentData)data);
257 } 139 }
258 140
141 /// <summary>
142 /// This is the worker function to send AgentData to a neighbor region
143 /// </summary>
259 private bool UpdateAgent(GridRegion destination, IAgentData cAgentData) 144 private bool UpdateAgent(GridRegion destination, IAgentData cAgentData)
260 { 145 {
261 // Eventually, we want to use a caps url instead of the agentID 146 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: UpdateAgent start");
262 147
148 // Eventually, we want to use a caps url instead of the agentID
263 string uri = destination.ServerURI + AgentPath() + cAgentData.AgentID + "/"; 149 string uri = destination.ServerURI + AgentPath() + cAgentData.AgentID + "/";
264 150
265 HttpWebRequest ChildUpdateRequest = (HttpWebRequest)WebRequest.Create(uri);
266 ChildUpdateRequest.Method = "PUT";
267 ChildUpdateRequest.ContentType = "application/json";
268 ChildUpdateRequest.Timeout = 30000;
269 //ChildUpdateRequest.KeepAlive = false;
270
271 // Fill it in
272 OSDMap args = null;
273 try
274 {
275 args = cAgentData.Pack();
276 }
277 catch (Exception e)
278 {
279 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: PackUpdateMessage failed with exception: " + e.Message);
280 }
281 // Add the input arguments
282 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
283 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
284 args["destination_name"] = OSD.FromString(destination.RegionName);
285 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
286
287 string strBuffer = "";
288 byte[] buffer = new byte[1];
289 try
290 {
291 strBuffer = OSDParser.SerializeJsonString(args);
292 Encoding str = Util.UTF8;
293 buffer = str.GetBytes(strBuffer);
294
295 }
296 catch (Exception e)
297 {
298 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of ChildUpdate: {0}", e.Message);
299 // ignore. buffer will be empty, caller should check.
300 }
301
302 Stream os = null;
303 try
304 { // send the Post
305 ChildUpdateRequest.ContentLength = buffer.Length; //Count bytes to send
306 os = ChildUpdateRequest.GetRequestStream();
307 os.Write(buffer, 0, strBuffer.Length); //Send it
308 //m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted AgentUpdate request to remote sim {0}", uri);
309 }
310 catch (WebException ex)
311 //catch
312 {
313 // m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on AgentUpdate {0}", ex.Message);
314
315 return false;
316 }
317 finally
318 {
319 if (os != null)
320 os.Close();
321 }
322
323 // Let's wait for the response
324 //m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after ChildAgentUpdate");
325
326 WebResponse webResponse = null;
327 StreamReader sr = null;
328 try 151 try
329 { 152 {
330 webResponse = ChildUpdateRequest.GetResponse(); 153 OSDMap args = cAgentData.Pack();
331 if (webResponse == null)
332 {
333 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on ChilAgentUpdate post");
334 }
335 154
336 sr = new StreamReader(webResponse.GetResponseStream()); 155 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
337 //reply = sr.ReadToEnd().Trim(); 156 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
338 sr.ReadToEnd().Trim(); 157 args["destination_name"] = OSD.FromString(destination.RegionName);
339 sr.Close(); 158 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
340 //m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply);
341 159
160 OSDMap result = WebUtil.PutToService(uri,args);
161 return result["Success"].AsBoolean();
342 } 162 }
343 catch (WebException ex) 163 catch (Exception e)
344 {
345 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ChilAgentUpdate from {0}: {1}", uri, ex.Message);
346 // ignore, really
347 }
348 finally
349 { 164 {
350 if (sr != null) 165 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString());
351 sr.Close();
352 } 166 }
353 167
354 return true; 168 return false;
355 } 169 }
356 170
171 /// <summary>
172 /// Not sure what sequence causes this function to be invoked. The only calling
173 /// path is through the GET method
174 /// </summary>
357 public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent) 175 public bool RetrieveAgent(GridRegion destination, UUID id, out IAgentData agent)
358 { 176 {
359 IPEndPoint ext = destination.ExternalEndPoint; 177 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: RetrieveAgent start");
178
360 agent = null; 179 agent = null;
361 if (ext == null) return false; 180
362 // Eventually, we want to use a caps url instead of the agentID 181 // Eventually, we want to use a caps url instead of the agentID
363 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; 182 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/";
364 183
365 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
366 request.Method = "GET";
367 request.Timeout = 10000;
368 //request.Headers.Add("authorization", ""); // coming soon
369
370 HttpWebResponse webResponse = null;
371 string reply = string.Empty;
372 StreamReader sr = null;
373 try 184 try
374 { 185 {
375 webResponse = (HttpWebResponse)request.GetResponse(); 186 OSDMap result = WebUtil.GetFromService(uri);
376 if (webResponse == null) 187 if (result["Success"].AsBoolean())
377 { 188 {
378 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent get "); 189 // OSDMap args = Util.GetOSDMap(result["_RawResult"].AsString());
190 OSDMap args = (OSDMap)result["_Result"];
191 if (args != null)
192 {
193 agent = new CompleteAgentData();
194 agent.Unpack(args);
195 return true;
196 }
379 } 197 }
380
381 sr = new StreamReader(webResponse.GetResponseStream());
382 reply = sr.ReadToEnd().Trim();
383
384
385 } 198 }
386 catch (WebException ex) 199 catch (Exception e)
387 {
388 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent get {0}", ex.Message);
389 // ignore, really
390 return false;
391 }
392 finally
393 {
394 if (sr != null)
395 sr.Close();
396 }
397
398 if (webResponse.StatusCode == HttpStatusCode.OK)
399 { 200 {
400 // we know it's jason 201 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: UpdateAgent failed with exception: " + e.ToString());
401 OSDMap args = Util.GetOSDMap(reply);
402 if (args == null)
403 {
404 return false;
405 }
406
407 agent = new CompleteAgentData();
408 agent.Unpack(args);
409 return true;
410 } 202 }
411 203
412 return false; 204 return false;
413 } 205 }
414 206
207 /// <summary>
208 /// </summary>
415 public bool QueryAccess(GridRegion destination, UUID id) 209 public bool QueryAccess(GridRegion destination, UUID id)
416 { 210 {
211 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: QueryAccess start");
212
417 IPEndPoint ext = destination.ExternalEndPoint; 213 IPEndPoint ext = destination.ExternalEndPoint;
418 if (ext == null) return false; 214 if (ext == null) return false;
215
419 // Eventually, we want to use a caps url instead of the agentID 216 // Eventually, we want to use a caps url instead of the agentID
420 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; 217 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/";
421 218
422 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
423 request.Method = "QUERYACCESS";
424 request.Timeout = 10000;
425 //request.Headers.Add("authorization", ""); // coming soon
426
427 HttpWebResponse webResponse = null;
428 string reply = string.Empty;
429 StreamReader sr = null;
430 try 219 try
431 { 220 {
432 webResponse = (HttpWebResponse)request.GetResponse(); 221 OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"QUERYACCESS",10000);
433 if (webResponse == null) 222 return result["Success"].AsBoolean();
434 {
435 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent query ");
436 }
437
438 sr = new StreamReader(webResponse.GetResponseStream());
439 reply = sr.ReadToEnd().Trim();
440
441
442 } 223 }
443 catch (WebException ex) 224 catch (Exception e)
444 {
445 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent query {0}", ex.Message);
446 // ignore, really
447 return false;
448 }
449 finally
450 { 225 {
451 if (sr != null) 226 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] QueryAcess failed with exception; {0}",e.ToString());
452 sr.Close();
453 } 227 }
454 228
455 if (webResponse.StatusCode == HttpStatusCode.OK)
456 {
457 try
458 {
459 bool result;
460
461 result = bool.Parse(reply);
462
463 return result;
464 }
465 catch
466 {
467 return false;
468 }
469 }
470
471 return false; 229 return false;
472 } 230 }
473 231
232 /// <summary>
233 /// </summary>
474 public bool ReleaseAgent(UUID origin, UUID id, string uri) 234 public bool ReleaseAgent(UUID origin, UUID id, string uri)
475 { 235 {
476 WebRequest request = WebRequest.Create(uri); 236 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: ReleaseAgent start");
477 request.Method = "DELETE";
478 request.Timeout = 10000;
479 237
480 StreamReader sr = null;
481 try 238 try
482 { 239 {
483 WebResponse webResponse = request.GetResponse(); 240 OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"DELETE",10000);
484 if (webResponse == null)
485 {
486 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on ReleaseAgent");
487 }
488
489 sr = new StreamReader(webResponse.GetResponseStream());
490 //reply = sr.ReadToEnd().Trim();
491 sr.ReadToEnd().Trim();
492 sr.Close();
493 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply);
494
495 }
496 catch (WebException ex)
497 {
498 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of ReleaseAgent {0}", ex.Message);
499 return false;
500 } 241 }
501 finally 242 catch (Exception e)
502 { 243 {
503 if (sr != null) 244 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] ReleaseAgent failed with exception; {0}",e.ToString());
504 sr.Close();
505 } 245 }
506 246
507 return true; 247 return true;
508 } 248 }
509 249
510 private bool CloseAgent(GridRegion destination, UUID id, bool ChildOnly) 250 private bool CloseAgent(GridRegion destination, UUID id, bool ChildOnly)
511 { 251 {
512 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/"; 252 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CloseAgent start");
513 253
514 WebRequest request = WebRequest.Create(uri); 254 string uri = destination.ServerURI + AgentPath() + id + "/" + destination.RegionID.ToString() + "/";
515 request.Method = "DELETE";
516 if (ChildOnly)
517 request.Method += "CHILD";
518 request.Timeout = 10000;
519 255
520 StreamReader sr = null;
521 try 256 try
522 { 257 {
523 WebResponse webResponse = request.GetResponse(); 258 OSDMap result = WebUtil.ServiceOSDRequest(uri,null,"DELETE",10000);
524 if (webResponse == null)
525 {
526 m_log.Debug("[REMOTE SIMULATION CONNECTOR]: Null reply on agent delete ");
527 }
528
529 sr = new StreamReader(webResponse.GetResponseStream());
530 //reply = sr.ReadToEnd().Trim();
531 sr.ReadToEnd().Trim();
532 sr.Close();
533 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: ChilAgentUpdate reply was {0} ", reply);
534
535 }
536 catch (WebException ex)
537 {
538 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of agent delete from {0}: {1}", destination.RegionName, ex.Message);
539 return false;
540 } 259 }
541 finally 260 catch (Exception e)
542 { 261 {
543 if (sr != null) 262 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] CloseAgent failed with exception; {0}",e.ToString());
544 sr.Close();
545 } 263 }
546 264
547 return true; 265 return true;
@@ -566,99 +284,46 @@ namespace OpenSim.Services.Connectors.Simulation
566 return "object/"; 284 return "object/";
567 } 285 }
568 286
287 /// <summary>
288 ///
289 /// </summary>
569 public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall) 290 public bool CreateObject(GridRegion destination, ISceneObject sog, bool isLocalCall)
570 { 291 {
571 IPEndPoint ext = destination.ExternalEndPoint; 292 // m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: CreateObject start");
572 if (ext == null) return false;
573 string uri
574 = destination.ServerURI + ObjectPath() + sog.UUID + "/";
575 //m_log.Debug(" >>> DoCreateObjectCall <<< " + uri);
576
577 WebRequest ObjectCreateRequest = WebRequest.Create(uri);
578 ObjectCreateRequest.Method = "POST";
579 ObjectCreateRequest.ContentType = "application/json";
580 ObjectCreateRequest.Timeout = 10000;
581
582 OSDMap args = new OSDMap(2);
583 args["sog"] = OSD.FromString(sog.ToXml2());
584 args["extra"] = OSD.FromString(sog.ExtraToXmlString());
585 args["modified"] = OSD.FromBoolean(sog.HasGroupChanged);
586 string state = sog.GetStateSnapshot();
587 if (state.Length > 0)
588 args["state"] = OSD.FromString(state);
589 // Add the input general arguments
590 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
591 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
592 args["destination_name"] = OSD.FromString(destination.RegionName);
593 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
594
595 string strBuffer = "";
596 byte[] buffer = new byte[1];
597 try
598 {
599 strBuffer = OSDParser.SerializeJsonString(args);
600 Encoding str = Util.UTF8;
601 buffer = str.GetBytes(strBuffer);
602 293
603 } 294 string uri = destination.ServerURI + ObjectPath() + sog.UUID + "/";
604 catch (Exception e)
605 {
606 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Exception thrown on serialization of CreateObject: {0}", e.Message);
607 // ignore. buffer will be empty, caller should check.
608 }
609 295
610 Stream os = null;
611 try 296 try
612 { // send the Post
613 ObjectCreateRequest.ContentLength = buffer.Length; //Count bytes to send
614 os = ObjectCreateRequest.GetRequestStream();
615 os.Write(buffer, 0, strBuffer.Length); //Send it
616 m_log.DebugFormat("[REMOTE SIMULATION CONNECTOR]: Posted CreateObject request to remote sim {0}", uri);
617 }
618 catch (WebException ex)
619 {
620 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: Bad send on CreateObject {0}", ex.Message);
621 return false;
622 }
623 finally
624 { 297 {
625 if (os != null) 298 OSDMap args = new OSDMap(2);
626 os.Close();
627 }
628 299
629 // Let's wait for the response 300 args["sog"] = OSD.FromString(sog.ToXml2());
630 //m_log.Info("[REMOTE SIMULATION CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); 301 args["extra"] = OSD.FromString(sog.ExtraToXmlString());
302 args["modified"] = OSD.FromBoolean(sog.HasGroupChanged);
631 303
632 StreamReader sr = null; 304 string state = sog.GetStateSnapshot();
633 try 305 if (state.Length > 0)
634 { 306 args["state"] = OSD.FromString(state);
635 WebResponse webResponse = ObjectCreateRequest.GetResponse();
636 if (webResponse == null)
637 {
638 m_log.Warn("[REMOTE SIMULATION CONNECTOR]: Null reply on CreateObject post");
639 return false;
640 }
641 307
642 sr = new StreamReader(webResponse.GetResponseStream()); 308 // Add the input general arguments
643 //reply = sr.ReadToEnd().Trim(); 309 args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString());
644 sr.ReadToEnd().Trim(); 310 args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString());
645 //m_log.InfoFormat("[REMOTE SIMULATION CONNECTOR]: DoCreateChildAgentCall reply was {0} ", reply); 311 args["destination_name"] = OSD.FromString(destination.RegionName);
312 args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString());
646 313
314 OSDMap result = WebUtil.PostToService(uri,args);
647 } 315 }
648 catch (WebException ex) 316 catch (Exception e)
649 {
650 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR]: exception on reply of CreateObject {0}", ex.Message);
651 return false;
652 }
653 finally
654 { 317 {
655 if (sr != null) 318 m_log.WarnFormat("[REMOTE SIMULATION CONNECTOR] CreateObject failed with exception; {0}",e.ToString());
656 sr.Close();
657 } 319 }
658 320
659 return true; 321 return true;
660 } 322 }
661 323
324 /// <summary>
325 ///
326 /// </summary>
662 public bool CreateObject(GridRegion destination, UUID userID, UUID itemID) 327 public bool CreateObject(GridRegion destination, UUID userID, UUID itemID)
663 { 328 {
664 // TODO, not that urgent 329 // TODO, not that urgent