mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 12:03:51 +08:00
56 lines
2.0 KiB
C#
56 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using Orchard.Core.XmlRpc.Models;
|
|
using Orchard.Core.XmlRpc.Services;
|
|
using Orchard.Logging;
|
|
|
|
namespace Orchard.Core.XmlRpc.Controllers {
|
|
public class HomeController : Controller {
|
|
private readonly IXmlRpcWriter _writer;
|
|
private readonly IEnumerable<IXmlRpcHandler> _xmlRpcHandlers;
|
|
|
|
public HomeController(
|
|
IXmlRpcWriter writer,
|
|
IEnumerable<IXmlRpcHandler> xmlRpcHandlers) {
|
|
_writer = writer;
|
|
_xmlRpcHandlers = xmlRpcHandlers;
|
|
|
|
Logger = NullLogger.Instance;
|
|
}
|
|
|
|
public ILogger Logger { get; set; }
|
|
|
|
[HttpPost, ActionName("Index")]
|
|
public ActionResult ServiceEndpoint(XRpcMethodCall methodCall) {
|
|
Logger.Debug("XmlRpc methodName {0}", methodCall.MethodName);
|
|
var methodResponse = Dispatch(methodCall);
|
|
|
|
if (methodResponse == null)
|
|
throw new HttpException(500, "TODO: xmlrpc fault");
|
|
|
|
var content = new StringBuilder();
|
|
_writer.MapMethodResponse(methodResponse).Save(new StringWriter(content));
|
|
|
|
return Content(content.ToString(), "text/xml");
|
|
}
|
|
|
|
private XRpcMethodResponse Dispatch(XRpcMethodCall request) {
|
|
var context = new XmlRpcContext { ControllerContext = ControllerContext, HttpContext = HttpContext, Request = request };
|
|
try {
|
|
foreach (var handler in _xmlRpcHandlers) {
|
|
handler.Process(context);
|
|
}
|
|
}
|
|
catch (OrchardCoreException e) {
|
|
// if a core exception is raised, report the error message, otherwise signal a 500
|
|
context.Response = context.Response ?? new XRpcMethodResponse();
|
|
context.Response.Fault = new XRpcFault(0, e.LocalizedMessage.ToString());
|
|
}
|
|
|
|
return context.Response;
|
|
}
|
|
}
|
|
} |