[jayrock] push by azizatif - Fixes issue #37 on 2011-07-04 16:33 GMT

1 view
Skip to first unread message

jay...@googlecode.com

unread,
Jul 4, 2011, 12:34:17 PM7/4/11
to jayrock...@googlegroups.com
Revision: 0df7b70e7394
Author: azizatif
Date: Mon Jul 4 09:33:32 2011
Log: Fixes issue #37
http://code.google.com/p/jayrock/source/detail?r=0df7b70e7394

Modified:
/src/Jayrock.Sandbox/JsonRpcClient.cs

=======================================
--- /src/Jayrock.Sandbox/JsonRpcClient.cs Fri Apr 15 16:09:54 2011
+++ /src/Jayrock.Sandbox/JsonRpcClient.cs Mon Jul 4 09:33:32 2011
@@ -109,11 +109,22 @@
return OnResponse(JsonText.CreateReader(reader),
returnType);
}

- private object OnResponse(JsonReader reader, Type returnType)
+ public object OnResponse(JsonReader reader, Type returnType)
{
Debug.Assert(reader != null);
Debug.Assert(returnType != null);

+ bool resultSpecified = false;
+ object result = null;
+
+ //
+ // JSON-RPC 2.0 specification/protocol, states that either
error
+ // or result must be present but not both. JSON-RPC 1.0 is less
+ // strict and states that one or the other must be null. There
+ // is an ambiguity however with 1.0 when both result and error
+ // are null. Here, it is treated like a successful null result.
+ //
+
NamedJsonBuffer[] members =
JsonBuffer.From(reader).GetMembersArray();
foreach (NamedJsonBuffer member in members)
{
@@ -125,13 +136,17 @@
}
else if (string.CompareOrdinal(member.Name, "result") == 0)
{
- return returnType != typeof(JsonBuffer)
- ? JsonConvert.Import(returnType,
member.Buffer.CreateReader())
- : member.Buffer;
+ resultSpecified = true;
+ result = returnType != typeof(JsonBuffer)
+ ? JsonConvert.Import(returnType,
member.Buffer.CreateReader())
+ : member.Buffer;
}
}

- throw new Exception("Invalid JSON-RPC response. It contains
neither a result nor an error.");
+ if (!resultSpecified) // never gets here on error
+ throw new Exception("Invalid JSON-RPC response. It
contains neither a result nor an error.");
+
+ return result;
}

protected virtual void OnError(object errorObject)

Reply all
Reply to author
Forward
0 new messages