Exemple #1
0
        private void RequestHandler(HttpRequest httpreq)
        {
            XmlRpc.XmlRpcRequest req;
            if (httpreq.Method != "POST")
            {
                httpreq.ErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed");
                return;
            }
            try
            {
                req = XmlRpc.DeserializeRequest(httpreq.Body);
            }
            catch
            {
                FaultResponse(httpreq, -32700, "Invalid XML RPC Request");
                return;
            }
            req.CallerIP = httpreq.CallerIP;
            req.IsSsl    = httpreq.IsSsl;

            Func <XmlRpc.XmlRpcRequest, XmlRpc.XmlRpcResponse> del;
            Func <HttpRequest, XmlRpc.XmlRpcRequest, XmlRpc.XmlRpcResponse> del2;

            XmlRpc.XmlRpcResponse res;
            if (XmlRpcMethods_DiscThread.TryGetValue(req.MethodName, out del2))
            {
                try
                {
                    res = del2(httpreq, req);
                }
                catch (XmlRpc.XmlRpcFaultException e)
                {
                    FaultResponse(httpreq, e.FaultCode, e.Message);
                    return;
                }
                catch (Exception e)
                {
                    m_Log.WarnFormat("Unexpected exception at XMRPC method {0}: {1}\n{2}", req.MethodName, e.GetType().Name, e.StackTrace);
                    FaultResponse(httpreq, -32700, "Internal service error");
                    return;
                }

                if (res != null)
                {
                    using (HttpResponse response = httpreq.BeginResponse())
                    {
                        response.ContentType = "text/xml";
                        using (Stream o = response.GetOutputStream())
                        {
                            res.Serialize(o);
                        }
                    }
                }
                else
                {
                    throw new HttpResponse.DisconnectFromThreadException();
                }
            }
            else if (XmlRpcMethods.TryGetValue(req.MethodName, out del))
            {
                try
                {
                    res = del(req);
                }
                catch (XmlRpc.XmlRpcFaultException e)
                {
                    FaultResponse(httpreq, e.FaultCode, e.Message);
                    return;
                }
                catch (Exception e)
                {
                    m_Log.WarnFormat("Unexpected exception at XMRPC method {0}: {1}\n{2}", req.MethodName, e.GetType().Name, e.StackTrace);
                    FaultResponse(httpreq, -32700, "Internal service error");
                    return;
                }

                using (HttpResponse response = httpreq.BeginResponse())
                {
                    response.ContentType = "text/xml";
                    using (Stream o = response.GetOutputStream())
                    {
                        res.Serialize(o);
                    }
                }
            }
            else
            {
                FaultResponse(httpreq, -32601, "Unknown Method");
            }
        }
Exemple #2
0
 public bool Run()
 {
     XmlRpc.XmlRpcRequest req = XmlRpc.DeserializeRequest(new MemoryStream(UTF8NoBOM.GetBytes(ParserInput)));
     return(true);
 }