metadata: Hand back NullTags if we find a file we don't know how to get the tags for
3 JsonRpcTransaction = Class.create();
4 Object.extend(JsonRpcTransaction.prototype,
6 initialize: function(serviceUrl, methodName, params, options) {
9 timeout: 0 /* milliseconds; zero means "do not specify" */
11 Object.extend(this.options, options || {});
12 this.serviceUrl = serviceUrl;
13 this.methodName = methodName;
19 this.errorCallbacks = [];
23 buildRequest: function() {
24 return { version: "1.1",
25 id: JsonRpcRequestId++,
26 method: this.methodName,
27 params: this.params };
30 sendRequest: function() {
31 var headers = ['Content-type', 'application/json',
32 'Accept', 'application/json'];
33 if (this.options.timeout) {
34 headers.push('X-JSON-RPC-Timeout', this.options.timeout);
37 new Ajax.Request(this.serviceUrl,
39 requestHeaders: headers,
40 postBody: JSON.stringify(this.buildRequest()),
41 onComplete: this.receiveReply.bind(this) });
44 receiveReply: function(ajaxRequest) {
45 var response = JSON.parse(ajaxRequest.responseText);
47 if (this.options.debug) {
48 alert("JsonRPC error:\n" +
49 "Service: " + JSON.stringify(this.serviceUrl) + "\n" +
50 "Method: " + JSON.stringify(this.methodName) + "\n" +
51 "Params: " + JSON.stringify(this.params) + "\n" +
52 "Response: " + JSON.stringify(response) + "\n");
54 this.error = response.error;
55 this.errorCallbacks.each(function (cb) {
56 try { cb(response.error, true); }
60 var reply = response.result;
63 this.callbacks.each(function (cb) {
64 try { cb(reply, false); }
70 addCallback: function(cb) {
71 this.callbacks.push(cb);
72 if (this.replyReady) {
73 try { cb(this.reply, false); }
79 addErrorCallback: function(cb) {
80 this.errorCallbacks.push(cb);
82 try { cb(this.error, true); }
89 JsonRpcService = Class.create();
90 Object.extend(JsonRpcService.prototype,
92 initialize: function(serviceUrl, onReady, options) {
94 transactionClass: JsonRpcTransaction,
95 timeout: 0, /* milliseconds; zero means "do not specify" */
98 Object.extend(this.options, options || {});
99 this.serviceUrl = serviceUrl;
101 var txn = new (this.options.transactionClass)(serviceUrl,
104 {debug: this.options.debug});
105 txn.addCallback(receiveServiceDescription);
106 function receiveServiceDescription(sd) {
107 svc.serviceDescription = sd;
108 svc.serviceDescription.procs.each(svc.installGenericProxy.bind(svc));
113 installGenericProxy: function(desc) {
114 this[desc.name] = function () {
115 var actuals = $A(arguments);
116 return new (this.options.transactionClass)(this.serviceUrl,
120 debug: this.options.debug,
121 timeout: this.options.timeout