aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
diff options
context:
space:
mode:
authorDr Scofield2008-05-22 12:00:01 +0000
committerDr Scofield2008-05-22 12:00:01 +0000
commitbdc792d319601caa93790b21c33b3b623a4ac13c (patch)
tree040726c9a37edba4f1873a1f8d445b6c6fa1fd63 /OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
parentAdded "show regions" to the CL help screen. Mantis 1123 (diff)
downloadopensim-SC_OLD-bdc792d319601caa93790b21c33b3b623a4ac13c.zip
opensim-SC_OLD-bdc792d319601caa93790b21c33b3b623a4ac13c.tar.gz
opensim-SC_OLD-bdc792d319601caa93790b21c33b3b623a4ac13c.tar.bz2
opensim-SC_OLD-bdc792d319601caa93790b21c33b3b623a4ac13c.tar.xz
here are further enhancements to the IHttpAgentHandler and to BaseHttpServer (from awebb)
i've added the OSHttpStatusCodes enumeration of HTTP status codes, have adapted BaseHttpServer to use those. then RestPlugin now has proper Failure handling returning proper HTTP status codes. Regions/POSTHandler is work-in-progress.
Diffstat (limited to 'OpenSim/ApplicationPlugins/Rest/RestPlugin.cs')
-rw-r--r--OpenSim/ApplicationPlugins/Rest/RestPlugin.cs60
1 files changed, 51 insertions, 9 deletions
diff --git a/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
index 4b8cdc1..f1ca83d 100644
--- a/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
+++ b/OpenSim/ApplicationPlugins/Rest/RestPlugin.cs
@@ -66,7 +66,7 @@ namespace OpenSim.ApplicationPlugins.Rest
66 private string _prefix; // URL prefix below 66 private string _prefix; // URL prefix below
67 // which all REST URLs 67 // which all REST URLs
68 // are living 68 // are living
69 private StringWriter _sw = null; 69 private StringWriter _sw = null;
70 private XmlTextWriter _xw = null; 70 private XmlTextWriter _xw = null;
71 71
72 private string _godkey; 72 private string _godkey;
@@ -240,7 +240,8 @@ namespace OpenSim.ApplicationPlugins.Rest
240 } 240 }
241 } 241 }
242 242
243 private List<RestStreamHandler> _handlers = new List<RestStreamHandler>(); 243 private List<RestStreamHandler> _handlers = new List<RestStreamHandler>();
244 private Dictionary<string, IHttpAgentHandler> _agents = new Dictionary<string, IHttpAgentHandler>();
244 245
245 /// <summary> 246 /// <summary>
246 /// Add a REST stream handler to the underlying HTTP server. 247 /// Add a REST stream handler to the underlying HTTP server.
@@ -271,15 +272,39 @@ namespace OpenSim.ApplicationPlugins.Rest
271 /// </summary> 272 /// </summary>
272 /// <param name="agentName">name of agent handler</param> 273 /// <param name="agentName">name of agent handler</param>
273 /// <param name="handler">agent handler method</param> 274 /// <param name="handler">agent handler method</param>
274 /// <returns>true when the plugin is disabled or the agent 275 /// <returns>false when the plugin is disabled or the agent
275 /// handler could not be added..</returns> 276 /// handler could not be added. Any generated exceptions are
277 /// allowed to drop through to the caller, i.e. ArgumentException.
278 /// </returns>
276 public bool AddAgentHandler(string agentName, IHttpAgentHandler handler) 279 public bool AddAgentHandler(string agentName, IHttpAgentHandler handler)
277 { 280 {
278 if (!IsEnabled) return false; 281 if (!IsEnabled) return false;
282 _agents.Add(agentName, handler);
279 return _httpd.AddAgentHandler(agentName, handler); 283 return _httpd.AddAgentHandler(agentName, handler);
280 } 284 }
281 285
282 /// <summary> 286 /// <summary>
287 /// Remove a powerful Agent handler from the underlying HTTP
288 /// server.
289 /// </summary>
290 /// <param name="agentName">name of agent handler</param>
291 /// <param name="handler">agent handler method</param>
292 /// <returns>false when the plugin is disabled or the agent
293 /// handler could not be removed. Any generated exceptions are
294 /// allowed to drop through to the caller, i.e. KeyNotFound.
295 /// </returns>
296 public bool RemoveAgentHandler(string agentName, IHttpAgentHandler handler)
297 {
298 if (!IsEnabled) return false;
299 if(_agents[agentName] == handler)
300 {
301 _agents.Remove(agentName);
302 return _httpd.RemoveAgentHandler(agentName, handler);
303 }
304 return false;
305 }
306
307 /// <summary>
283 /// Check whether the HTTP request came from god; that is, is 308 /// Check whether the HTTP request came from god; that is, is
284 /// the god_key as configured in the config section supplied 309 /// the god_key as configured in the config section supplied
285 /// via X-OpenSim-Godkey? 310 /// via X-OpenSim-Godkey?
@@ -316,19 +341,30 @@ namespace OpenSim.ApplicationPlugins.Rest
316 _httpd.RemoveStreamHandler(h.HttpMethod, h.Path); 341 _httpd.RemoveStreamHandler(h.HttpMethod, h.Path);
317 } 342 }
318 _handlers = null; 343 _handlers = null;
344 foreach (KeyValuePair<string,IHttpAgentHandler> h in _agents)
345 {
346 _httpd.RemoveAgentHandler(h.Key,h.Value);
347 }
348 _agents = null;
319 } 349 }
320 350
321 /// <summary> 351 /// <summary>
322 /// Return a failure message. 352 /// Return a failure message.
323 /// </summary> 353 /// </summary>
324 /// <param name="method">origin of the failure message</param> 354 /// <param name="method">origin of the failure message</param>
325 /// <param name="message>failure message</param> 355 /// <param name="message">failure message</param>
326 /// <remarks>This should probably set a return code as 356 /// <remarks>This should probably set a return code as
327 /// well. (?)</remarks> 357 /// well. (?)</remarks>
328 protected string Failure(string method, string message) 358 protected string Failure(OSHttpResponse response, OSHttpStatusCode status,
359 string method, string format, params string[] msg)
329 { 360 {
330 m_log.ErrorFormat("{0} {1} failed: {2}", MsgID, method, message); 361 string m = String.Format(format, msg);
331 return String.Format("<error>{0}</error>", message); 362
363 response.StatusCode = (int)status;
364 response.StatusDescription = m;
365
366 m_log.ErrorFormat("{0} {1} failed: {2}", MsgID, method, m);
367 return String.Format("<error>{0}</error>", m);
332 } 368 }
333 369
334 /// <summary> 370 /// <summary>
@@ -338,8 +374,14 @@ namespace OpenSim.ApplicationPlugins.Rest
338 /// <param name="e">exception causing the failure message</param> 374 /// <param name="e">exception causing the failure message</param>
339 /// <remarks>This should probably set a return code as 375 /// <remarks>This should probably set a return code as
340 /// well. (?)</remarks> 376 /// well. (?)</remarks>
341 public string Failure(string method, Exception e) 377 public string Failure(OSHttpResponse response, OSHttpStatusCode status,
378 string method, Exception e)
342 { 379 {
380 string m = String.Format("exception occurred: {0}", e.Message);
381
382 response.StatusCode = (int)status;
383 response.StatusDescription = m;
384
343 m_log.DebugFormat("{0} {1} failed: {2}", MsgID, method, e.ToString()); 385 m_log.DebugFormat("{0} {1} failed: {2}", MsgID, method, e.ToString());
344 m_log.ErrorFormat("{0} {1} failed: {2}", MsgID, method, e.Message); 386 m_log.ErrorFormat("{0} {1} failed: {2}", MsgID, method, e.Message);
345 387