diff options
| author | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
|---|---|---|
| committer | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
| commit | b62676ca5d3d6f6ba3f019ea3f99722e165a98d8 (patch) | |
| tree | 86722cb80f07d4569f90088eeaea2fc2f6e2ef94 /js/dojo/dojox/rpc/JsonRPC.js | |
Diffstat (limited to 'js/dojo/dojox/rpc/JsonRPC.js')
| -rw-r--r-- | js/dojo/dojox/rpc/JsonRPC.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/js/dojo/dojox/rpc/JsonRPC.js b/js/dojo/dojox/rpc/JsonRPC.js new file mode 100644 index 0000000..248afcd --- /dev/null +++ b/js/dojo/dojox/rpc/JsonRPC.js @@ -0,0 +1,55 @@ +//>>built +define("dojox/rpc/JsonRPC", ["dojo", "dojox", "dojox/rpc/Service"], function(dojo, dojox) { + + function jsonRpcEnvelope(version){ + return { + serialize: function(smd, method, data, options){ + //not converted to json it self. This will be done, if + //appropriate, at the transport level + + var d = { + id: this._requestId++, + method: method.name, + params: data + }; + if(version){ + d.jsonrpc = version; + } + return { + data: dojo.toJson(d), + handleAs:'json', + contentType: 'application/json', + transport:"POST" + }; + }, + + deserialize: function(obj){ + if ('Error' == obj.name){ + obj = dojo.fromJson(obj.responseText); + } + if(obj.error) { + var e = new Error(obj.error.message || obj.error); + e._rpcErrorObject = obj.error; + return e; + } + return obj.result; + } + }; + } + dojox.rpc.envelopeRegistry.register( + "JSON-RPC-1.0", + function(str){ + return str == "JSON-RPC-1.0"; + }, + dojo.mixin({namedParams:false},jsonRpcEnvelope()) // 1.0 will only work with ordered params + ); + + dojox.rpc.envelopeRegistry.register( + "JSON-RPC-2.0", + function(str){ + return str == "JSON-RPC-2.0"; + }, + jsonRpcEnvelope("2.0") + ); + +}); |
