mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-24 05:42:10 +08:00
Refactoring XRpcFault serialization
--HG-- branch : 1.x
This commit is contained in:
@@ -41,6 +41,25 @@ namespace Orchard.Tests.Modules.XmlRpc.Services {
|
||||
")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FaultShouldBeCorrectlyFormatted() {
|
||||
var mapper = new XmlRpcWriter();
|
||||
var response = new XRpcMethodResponse {
|
||||
Fault = new XRpcFault(10, "foo")
|
||||
};
|
||||
|
||||
var element = mapper.MapMethodResponse(response);
|
||||
|
||||
Assert.That(NoSpace(element.ToString()), Is.EqualTo(NoSpace(@"
|
||||
<methodResponse><fault>
|
||||
<value><struct>
|
||||
<member><name>faultCode</name><value><int>10</int></value></member>
|
||||
<member><name>faultString</name><value><string>foo</string></value></member>
|
||||
</struct></value>
|
||||
</fault></methodResponse>
|
||||
")));
|
||||
}
|
||||
|
||||
private static string NoSpace(string text) {
|
||||
return text.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("\t", "");
|
||||
}
|
||||
|
||||
@@ -43,11 +43,7 @@ namespace Orchard.Core.XmlRpc.Controllers {
|
||||
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 {
|
||||
Code = 0,
|
||||
Message = e.LocalizedMessage.ToString()
|
||||
};
|
||||
context.Response.Fault = new XRpcFault(0, e.LocalizedMessage.ToString());
|
||||
}
|
||||
|
||||
return context.Response;
|
||||
|
||||
@@ -41,6 +41,11 @@ namespace Orchard.Core.XmlRpc.Models {
|
||||
}
|
||||
|
||||
public class XRpcFault {
|
||||
public XRpcFault(int code, string message) {
|
||||
Code = code;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public string Message { get; set; }
|
||||
public int Code { get; set; }
|
||||
}
|
||||
|
||||
@@ -43,18 +43,16 @@ namespace Orchard.Core.XmlRpc.Services {
|
||||
|
||||
// return a valid fault as per http://xmlrpc.scripting.com/spec.html
|
||||
if(rpcMethodResponse.Fault != null) {
|
||||
var members = new XRpcStruct();
|
||||
members.Set("faultCode", rpcMethodResponse.Fault.Code);
|
||||
members.Set("faultString", rpcMethodResponse.Fault.Message);
|
||||
|
||||
return new XElement("methodResponse",
|
||||
new XElement("fault",
|
||||
new XElement("value",
|
||||
new XElement("struct",
|
||||
new XElement("member",
|
||||
new XElement("name", "faultCode"),
|
||||
new XElement("value",
|
||||
new XElement("int", rpcMethodResponse.Fault.Code))),
|
||||
new XElement("member",
|
||||
new XElement("name", "faultString"),
|
||||
new XElement("value",
|
||||
new XElement("string", rpcMethodResponse.Fault.Message)))))));
|
||||
new XElement("value", MapStruct(members))
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return new XElement("methodResponse",
|
||||
|
||||
Reference in New Issue
Block a user