29 using System.Collections.Generic;
32 using System.Reflection;
34 using System.Text.RegularExpressions;
39 namespace OpenSim.Framework.Servers.HttpServer
45 private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
57 XmlRpcRequest xmlRpcRequest = null;
63 if (req.Whiteboard.ContainsKey(
"xmlrequest"))
65 xmlRpcRequest = req.Whiteboard[
"xmlrequest"] as XmlRpcRequest;
69 StreamReader body =
new StreamReader(req.
InputStream);
70 string requestBody = body.ReadToEnd();
71 xmlRpcRequest = (XmlRpcRequest)(
new XmlRpcRequestDeserializer()).Deserialize(requestBody);
72 req.Whiteboard[
"xmlrequest"] = xmlRpcRequest;
77 _log.ErrorFormat(
"[OSHttpXmlRpcHandler] failed to deserialize XmlRpcRequest from {0}", req.ToString());
82 if ((null != xmlRpcRequest)
83 && !String.IsNullOrEmpty(xmlRpcRequest.MethodName)
84 && xmlRpcRequest.MethodName == _methodName)
86 _log.DebugFormat(
"[OSHttpXmlRpcHandler] located handler {0} for {1}", _methodName, req.ToString());
97 private string _methodName;
117 Dictionary<string, Regex> headers, Regex whitelist)
118 : base(new Regex(
@"^POST$", RegexOptions.IgnoreCase | RegexOptions.Compiled), path, null, headers,
119 new Regex(
@"^(text|application)/xml", RegexOptions.IgnoreCase | RegexOptions.Compiled),
123 _methodName = methodName;
134 : this(handler, methodName, null, null, null)
144 XmlRpcResponse xmlRpcResponse;
145 string responseString;
148 if (!XmlRpcMethodMatch(request))
return OSHttpHandlerResult.Pass;
155 XmlRpcRequest xmlRpcRequest = request.Whiteboard[
"xmlrequest"] as XmlRpcRequest;
156 xmlRpcResponse = _handler(xmlRpcRequest);
157 responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse);
159 resp.ContentType =
"text/xml";
160 byte[] buffer = Encoding.UTF8.GetBytes(responseString);
162 resp.SendChunked =
false;
163 resp.ContentLength = buffer.Length;
164 resp.ContentEncoding = Encoding.UTF8;
166 resp.Body.Write(buffer, 0, buffer.Length);
174 _log.WarnFormat(
"[OSHttpXmlRpcHandler]: Error: {0}", ex.Message);
175 return OSHttpHandlerResult.Pass;
177 return OSHttpHandlerResult.Done;
override OSHttpHandlerResult Process(OSHttpRequest request)
Invoked by OSHttpRequestPump.
OSHttpXmlRpcHandler(XmlRpcMethod handler, string methodName, Regex path, Dictionary< string, Regex > headers, Regex whitelist)
Instantiate an XmlRpc handler.
OSHttpResponse is the OpenSim representation of an HTTP response.
bool XmlRpcMethodMatch(OSHttpRequest req)
XmlRpcMethodMatch tries to reify (deserialize) an incoming XmlRpc request (and posts it to the "white...
delegate XmlRpcResponse OSHttpXmlRpcProcessor(XmlRpcRequest request)
delegate XmlRpcResponse XmlRpcMethod(XmlRpcRequest request, IPEndPoint client)
OSHttpXmlRpcHandler(XmlRpcMethod handler, string methodName)
Instantiate an XmlRpc handler.