Orbjson 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +27 -4
- data/bin/orbjson +8 -2
- data/docs/getting_started_with_orbjson_short_version.pdf +0 -0
- data/docs/tutorial_code.tgz +0 -0
- data/examples/cgi/script/jsonrpc.js +1 -1
- data/examples/cgi/script/jsonrpc_async.js +260 -0
- data/examples/webrick/index.html +1 -1
- data/examples/webrick/{index.html,bak → index_async.html} +77 -69
- data/examples/webrick/script/jsonrpc.js +1 -1
- data/examples/webrick/script/jsonrpc_async.js +262 -0
- data/examples/webrick/server.rb +1 -1
- data/lib/orbjson.rb +72 -43
- data/lib/skeleton/script/jsonrpc.js +1 -1
- data/lib/skeleton/script/jsonrpc_async.js +261 -0
- data/lib/skeleton/webrick/config.yml +3 -2
- data/lib/utils.rb +29 -0
- metadata +11 -26
- data/dep/handy/script/jsonrpc.js +0 -187
- data/dep/handy/script/jsonrpc.js,bak +0 -187
- data/dep/required/ruby-json/ruby-json-1.1.1.gem +0 -0
- data/docs/todo.txt +0 -0
- data/examples/cgi/Orbjson.log +0 -66
- data/examples/cgi/index.html,bak +0 -71
- data/examples/cgi/json-rpc.rb,bak +0 -34
- data/examples/cgi/orbjson_cgi.log +0 -35
- data/examples/cgi/script/jsonrpc.js,bak +0 -187
- data/examples/cgi/services/sample.rb,bak +0 -21
- data/examples/webrick/Orbjson.log +0 -49
- data/examples/webrick/script/jsonrpc.js,bak +0 -187
- data/examples/webrick/server.rb,bak +0 -28
- data/examples/webrick/services/sample.rb,bak +0 -21
- data/lib/skeleton/cgi/json-rpc.rb,bak +0 -60
- data/lib/skeleton/script/jsonrpc.js,bak +0 -187
- data/lib/skeleton/webrick/server.rb,bak +0 -57
@@ -1,187 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* JSON-RPC JavaScript client
|
3
|
-
*
|
4
|
-
* $Id: jsonrpc.js,v 1.1.1.1 2005/02/28 03:06:30 jamesgbritt Exp $
|
5
|
-
*
|
6
|
-
* Copyright (c) 2003-2004 Jan-Klaas Kollhof
|
7
|
-
* Copyright (c) 2005 Michael Clark, Metaparadigm Pte Ltd
|
8
|
-
*
|
9
|
-
* This code is based on Jan-Klaas' JavaScript o lait library (jsolait).
|
10
|
-
*
|
11
|
-
* This library is free software; you can redistribute it and/or
|
12
|
-
* modify it under the terms of the GNU Lesser General Public (LGPL)
|
13
|
-
* License as published by the Free Software Foundation; either
|
14
|
-
* version 2.1 of the License, or (at your option) any later version.
|
15
|
-
*
|
16
|
-
* This library is distributed in the hope that it will be useful,
|
17
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
19
|
-
* Lesser General Public License for more details: http://www.gnu.org/
|
20
|
-
*
|
21
|
-
*/
|
22
|
-
|
23
|
-
// TODO: Add async
|
24
|
-
// TODO: Add HTTP auth (user, password)
|
25
|
-
|
26
|
-
Object.prototype.toJSON = function Object_toJSON() {
|
27
|
-
var v = [];
|
28
|
-
for(attr in this) {
|
29
|
-
if(this[attr] == null) v.push("\"" + attr + "\": null");
|
30
|
-
else if(typeof this[attr] == "function"); // skip
|
31
|
-
else v.push("\"" + attr + "\": " + this[attr].toJSON());
|
32
|
-
}
|
33
|
-
return "{" + v.join(", ") + "}";
|
34
|
-
}
|
35
|
-
|
36
|
-
String.prototype.toJSON = function String_toJSON() {
|
37
|
-
return "\"" + this.replace(/([\"\\])/g, "\\$1") + "\"";
|
38
|
-
}
|
39
|
-
|
40
|
-
Number.prototype.toJSON = function Number_toJSON() {
|
41
|
-
return this.toString();
|
42
|
-
}
|
43
|
-
|
44
|
-
Boolean.prototype.toJSON = function Boolean_toJSON() {
|
45
|
-
return this.toString();
|
46
|
-
}
|
47
|
-
|
48
|
-
Date.prototype.toJSON = function Date_toJSON() {
|
49
|
-
this.valueOf().toString();
|
50
|
-
}
|
51
|
-
|
52
|
-
Array.prototype.toJSON = function Array_toJSON() {
|
53
|
-
var v = [];
|
54
|
-
for(var i=0; i<this.length; i++) {
|
55
|
-
if(this[i] == null) v.push("null");
|
56
|
-
else v.push(this[i].toJSON());
|
57
|
-
}
|
58
|
-
return "[" + v.join(", ") + "]";
|
59
|
-
}
|
60
|
-
|
61
|
-
JSONRpcClient = function JSONRpcClient_ctor(serverURL, objectID) {
|
62
|
-
this.serverURL = serverURL;
|
63
|
-
this.objectID = objectID;
|
64
|
-
|
65
|
-
// Lazy initialization of the XMLHttpRequest singleton
|
66
|
-
if(!JSONRpcClient.http)
|
67
|
-
JSONRpcClient.http = JSONRpcClient.getHTTPRequest();
|
68
|
-
|
69
|
-
// Add standard methods
|
70
|
-
this.addMethods(["system.listMethods"]);
|
71
|
-
|
72
|
-
// Query the methods on the server and add them to this object
|
73
|
-
var m = this.sendRequest("system.listMethods", []);
|
74
|
-
this.addMethods(m);
|
75
|
-
}
|
76
|
-
|
77
|
-
JSONRpcClient.Exception = function JSONRpcClient_Exception_ctor(code, msg) {
|
78
|
-
this.code = code;
|
79
|
-
this.msg = msg;
|
80
|
-
}
|
81
|
-
|
82
|
-
JSONRpcClient.Exception.prototype.toString =
|
83
|
-
function JSONRpcClient_Exception_toString(code, msg) {
|
84
|
-
return "JSONRpcClientException: " + this.msg;
|
85
|
-
}
|
86
|
-
|
87
|
-
JSONRpcClient.Method =
|
88
|
-
function JSONRpcClient_Method_ctor(client, methodName) {
|
89
|
-
var fn=function() {
|
90
|
-
var args = [];
|
91
|
-
for(var i=0;i<arguments.length;i++) {
|
92
|
-
args.push(arguments[i]);
|
93
|
-
}
|
94
|
-
return fn.client.sendRequest.call(fn.client, fn.methodName, args);
|
95
|
-
}
|
96
|
-
fn.client = client;
|
97
|
-
fn.methodName = methodName;
|
98
|
-
return fn;
|
99
|
-
}
|
100
|
-
|
101
|
-
JSONRpcClient.prototype.addMethods =
|
102
|
-
function JSONRpcClient_addMethods(methodNames) {
|
103
|
-
for(var i=0; i<methodNames.length; i++) {
|
104
|
-
var obj = this;
|
105
|
-
var names = methodNames[i].split(".");
|
106
|
-
for(var n=0; n<names.length-1; n++){
|
107
|
-
var name = names[n];
|
108
|
-
if(obj[name]){
|
109
|
-
obj = obj[name];
|
110
|
-
}
|
111
|
-
else {
|
112
|
-
obj[name] = new Object();
|
113
|
-
obj = obj[name];
|
114
|
-
}
|
115
|
-
}
|
116
|
-
var name = names[names.length-1];
|
117
|
-
if(!obj[name]){
|
118
|
-
var method = new JSONRpcClient.Method(this, methodNames[i]);
|
119
|
-
obj[name] = method;
|
120
|
-
}
|
121
|
-
}
|
122
|
-
}
|
123
|
-
|
124
|
-
JSONRpcClient.prototype.sendRequest =
|
125
|
-
function JSONRpcClient_sendRequest(methodName, args) {
|
126
|
-
// Make request object
|
127
|
-
var obj = {"method" : methodName, "params" : args};
|
128
|
-
if (this.objectID) obj.objectID = this.objectID;
|
129
|
-
|
130
|
-
// Marshall the request object to a JSON string
|
131
|
-
var req_data = obj.toJSON();
|
132
|
-
|
133
|
-
// Send the request
|
134
|
-
JSONRpcClient.http.open("POST", this.serverURL, false); // no async
|
135
|
-
// setRequestHeader is missing in Opera 8 Beta
|
136
|
-
try {
|
137
|
-
JSONRpcClient.http.setRequestHeader("Content-type", "text/plain");
|
138
|
-
}
|
139
|
-
catch(e) {}
|
140
|
-
JSONRpcClient.http.send(req_data);
|
141
|
-
|
142
|
-
// Unmarshall the response
|
143
|
-
// DEBUG
|
144
|
-
try {
|
145
|
-
eval("var obj = " + JSONRpcClient.http.responseText);
|
146
|
-
}
|
147
|
-
catch(e) {
|
148
|
-
alert( e )
|
149
|
-
alert( JSONRpcClient.http.responseText )
|
150
|
-
obj.err = e.toString()
|
151
|
-
}
|
152
|
-
if( obj.error) {
|
153
|
-
alert( JSONRpcClient.http.responseText )
|
154
|
-
throw new JSONRpcClient.Exception(obj.error.code, obj.error.msg);
|
155
|
-
}
|
156
|
-
var res = obj.result;
|
157
|
-
|
158
|
-
// Handle CallableProxy
|
159
|
-
if(res && res.objectID && res.JSONRPCType == "CallableReference")
|
160
|
-
return new JSONRpcClient(this.serverURL, res.objectID);
|
161
|
-
|
162
|
-
return res;
|
163
|
-
}
|
164
|
-
|
165
|
-
JSONRpcClient.getHTTPRequest = function JSONRpcClient_getHTTPRequest() {
|
166
|
-
try { // to get the mozilla httprequest object
|
167
|
-
return new XMLHttpRequest();
|
168
|
-
}
|
169
|
-
catch(e) {}
|
170
|
-
|
171
|
-
try { // to get MS HTTP request object
|
172
|
-
return new ActiveXObject("Msxml2.XMLHTTP.4.0");
|
173
|
-
}
|
174
|
-
catch(e) {}
|
175
|
-
|
176
|
-
try { // to get MS HTTP request object
|
177
|
-
return new ActiveXObject("Msxml2.XMLHTTP");
|
178
|
-
}
|
179
|
-
catch(e) {}
|
180
|
-
|
181
|
-
try {// to get the old MS HTTP request object
|
182
|
-
return new ActiveXObject("microsoft.XMLHTTP");
|
183
|
-
}
|
184
|
-
catch(e) {}
|
185
|
-
|
186
|
-
throw new JSONRpcClient.Exception(0, "Can't create XMLHttpRequest object");
|
187
|
-
}
|
Binary file
|
data/docs/todo.txt
DELETED
File without changes
|
data/examples/cgi/Orbjson.log
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# Logfile created on Sun Feb 27 14:21:31 US Mountain Standard Time 2005 by logger.rb/1.5.2.4
|
2
|
-
E, [2005-02-27T14:23:55.456000 #1664] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logs
|
3
|
-
E, [2005-02-27T14:23:55.456000 #1664] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Definition_context_factory
|
4
|
-
E, [2005-02-27T14:23:55.456000 #1664] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Log_for
|
5
|
-
E, [2005-02-27T14:23:55.456000 #1664] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Namespace_impl_factory
|
6
|
-
E, [2005-02-27T14:23:55.456000 #1664] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Service_models
|
7
|
-
E, [2005-02-27T14:23:55.456000 #1664] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Interceptor_impl_factory
|
8
|
-
E, [2005-02-27T14:23:55.456000 #1664] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Pipeline_elements
|
9
|
-
E, [2005-02-27T14:23:55.466000 #1664] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logging_interceptor
|
10
|
-
E, [2005-02-27T14:25:10.253000 #1984] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logs
|
11
|
-
E, [2005-02-27T14:25:10.253000 #1984] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Definition_context_factory
|
12
|
-
E, [2005-02-27T14:25:10.253000 #1984] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Log_for
|
13
|
-
E, [2005-02-27T14:25:10.253000 #1984] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Namespace_impl_factory
|
14
|
-
E, [2005-02-27T14:25:10.253000 #1984] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Service_models
|
15
|
-
E, [2005-02-27T14:25:10.253000 #1984] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Interceptor_impl_factory
|
16
|
-
E, [2005-02-27T14:25:10.253000 #1984] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Pipeline_elements
|
17
|
-
E, [2005-02-27T14:25:10.263000 #1984] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logging_interceptor
|
18
|
-
E, [2005-02-27T14:27:13.460000 #1396] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logs
|
19
|
-
E, [2005-02-27T14:27:13.470000 #1396] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Definition_context_factory
|
20
|
-
E, [2005-02-27T14:27:13.480000 #1396] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Log_for
|
21
|
-
E, [2005-02-27T14:27:13.480000 #1396] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Namespace_impl_factory
|
22
|
-
E, [2005-02-27T14:27:13.480000 #1396] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Service_models
|
23
|
-
E, [2005-02-27T14:27:13.480000 #1396] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Interceptor_impl_factory
|
24
|
-
E, [2005-02-27T14:27:13.480000 #1396] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Pipeline_elements
|
25
|
-
E, [2005-02-27T14:27:13.480000 #1396] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logging_interceptor
|
26
|
-
E, [2005-02-27T14:28:39.083000 #124] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logs
|
27
|
-
E, [2005-02-27T14:28:39.183000 #124] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Definition_context_factory
|
28
|
-
E, [2005-02-27T14:28:39.183000 #124] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Log_for
|
29
|
-
E, [2005-02-27T14:28:39.183000 #124] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Namespace_impl_factory
|
30
|
-
E, [2005-02-27T14:28:39.183000 #124] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Service_models
|
31
|
-
E, [2005-02-27T14:28:39.183000 #124] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Interceptor_impl_factory
|
32
|
-
E, [2005-02-27T14:28:39.194000 #124] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Pipeline_elements
|
33
|
-
E, [2005-02-27T14:28:39.194000 #124] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logging_interceptor
|
34
|
-
E, [2005-02-27T14:29:18.710000 #1944] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logs
|
35
|
-
E, [2005-02-27T14:29:18.710000 #1944] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Definition_context_factory
|
36
|
-
E, [2005-02-27T14:29:18.710000 #1944] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Log_for
|
37
|
-
E, [2005-02-27T14:29:18.710000 #1944] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Namespace_impl_factory
|
38
|
-
E, [2005-02-27T14:29:18.710000 #1944] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Service_models
|
39
|
-
E, [2005-02-27T14:29:18.710000 #1944] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Interceptor_impl_factory
|
40
|
-
E, [2005-02-27T14:29:18.710000 #1944] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Pipeline_elements
|
41
|
-
E, [2005-02-27T14:29:18.720000 #1944] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logging_interceptor
|
42
|
-
E, [2005-02-27T14:30:13.149000 #336] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logs
|
43
|
-
E, [2005-02-27T14:30:13.149000 #336] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Definition_context_factory
|
44
|
-
E, [2005-02-27T14:30:13.149000 #336] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Sample
|
45
|
-
E, [2005-02-27T14:30:13.149000 #336] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Log_for
|
46
|
-
E, [2005-02-27T14:30:13.159000 #336] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Namespace_impl_factory
|
47
|
-
E, [2005-02-27T14:30:13.159000 #336] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Service_models
|
48
|
-
E, [2005-02-27T14:30:13.159000 #336] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Interceptor_impl_factory
|
49
|
-
E, [2005-02-27T14:30:13.159000 #336] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Pipeline_elements
|
50
|
-
E, [2005-02-27T14:30:13.159000 #336] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logging_interceptor
|
51
|
-
E, [2005-02-27T14:30:45.445000 #1752] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logs
|
52
|
-
E, [2005-02-27T14:30:45.445000 #1752] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Definition_context_factory
|
53
|
-
E, [2005-02-27T14:30:45.445000 #1752] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Log_for
|
54
|
-
E, [2005-02-27T14:30:45.445000 #1752] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Namespace_impl_factory
|
55
|
-
E, [2005-02-27T14:30:45.445000 #1752] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Service_models
|
56
|
-
E, [2005-02-27T14:30:45.445000 #1752] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Interceptor_impl_factory
|
57
|
-
E, [2005-02-27T14:30:45.445000 #1752] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Pipeline_elements
|
58
|
-
E, [2005-02-27T14:30:45.445000 #1752] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logging_interceptor
|
59
|
-
E, [2005-02-27T14:35:55.901000 #2064] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logs
|
60
|
-
E, [2005-02-27T14:35:55.921000 #2064] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Definition_context_factory
|
61
|
-
E, [2005-02-27T14:35:55.921000 #2064] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Log_for
|
62
|
-
E, [2005-02-27T14:35:55.921000 #2064] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Namespace_impl_factory
|
63
|
-
E, [2005-02-27T14:35:55.921000 #2064] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Service_models
|
64
|
-
E, [2005-02-27T14:35:55.921000 #2064] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Interceptor_impl_factory
|
65
|
-
E, [2005-02-27T14:35:55.921000 #2064] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Pipeline_elements
|
66
|
-
E, [2005-02-27T14:35:55.921000 #2064] ERROR -- : System#list_methods error (eval):1:in `list_methods': uninitialized constant Orbjson::System::Logging_interceptor
|
data/examples/cgi/index.html,bak
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
2
|
-
<html xmlns="http://www.w3.org/1999/xhtml">
|
3
|
-
<head>
|
4
|
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
|
-
<title>Metatagging</title>
|
6
|
-
<script type="text/javascript" src="script/jsonrpc.js"></script>
|
7
|
-
<script language="javascript" type="text/javascript">
|
8
|
-
<!-- Make sure this URL makes sense for your set-up -->
|
9
|
-
var jsonurl = "http://127.0.0.1/orbjson/json-rpc.rb";
|
10
|
-
|
11
|
-
var jsonrpc = null;
|
12
|
-
|
13
|
-
function init() {
|
14
|
-
jsonrpc = new JSONRpcClient( jsonurl );
|
15
|
-
}
|
16
|
-
|
17
|
-
function show_details( topic ) {
|
18
|
-
var el = document.getElementById( 'details' );
|
19
|
-
var html = jsonrpc.details.fetch( topic)
|
20
|
-
el.innerHTML = html;
|
21
|
-
}
|
22
|
-
|
23
|
-
</script>
|
24
|
-
|
25
|
-
<style type="text/css">
|
26
|
-
#metatagFields #reset {
|
27
|
-
text-align: right;
|
28
|
-
}
|
29
|
-
body {
|
30
|
-
font-family: Verdana, Arial, Helvetica, sans-serif;
|
31
|
-
color: #666666;
|
32
|
-
}
|
33
|
-
a {
|
34
|
-
text-decoration: none;
|
35
|
-
}
|
36
|
-
|
37
|
-
fieldset {
|
38
|
-
background-image: url(yellow_crossfade_01.gif);
|
39
|
-
background-repeat: repeat-y;
|
40
|
-
background-position: left top;
|
41
|
-
}
|
42
|
-
|
43
|
-
#metatagFields {
|
44
|
-
width: 300px;
|
45
|
-
margin-top: 10px;
|
46
|
-
}
|
47
|
-
|
48
|
-
#metatagFields legend {
|
49
|
-
background-color: #FFFFFF;
|
50
|
-
border: 1px dashed #333333;
|
51
|
-
}
|
52
|
-
</style>
|
53
|
-
|
54
|
-
</head>
|
55
|
-
<body onload='init()' >
|
56
|
-
|
57
|
-
<div id='instructions'>Select a topic to seee more about it</div>
|
58
|
-
<div id='curentItemList'>
|
59
|
-
<a href='javascript:show_details( "JSON")'>JSON</a>, <a href='javascript:show_details( "JSON-RPC")'>JSON-RPC</a>, <a href='javascript:show_details( "Ruby")' >Ruby</a>
|
60
|
-
</div>
|
61
|
-
|
62
|
-
<div id='currentSelectionSet'>
|
63
|
-
<form name='metatagForm' action='#' method="get">
|
64
|
-
<fieldset id='metatagFields'>
|
65
|
-
<legend>Topic info</legend>
|
66
|
-
<div id='details'></div>
|
67
|
-
</fieldset>
|
68
|
-
</form>
|
69
|
-
</div>
|
70
|
-
</body>
|
71
|
-
</html>
|
@@ -1,34 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby
|
2
|
-
|
3
|
-
|
4
|
-
require 'cgi'
|
5
|
-
require 'rubygems'
|
6
|
-
require "orbjson"
|
7
|
-
require 'logger'
|
8
|
-
|
9
|
-
include Orbjson
|
10
|
-
|
11
|
-
|
12
|
-
$logger = Logger.new( "orbjson_cgi.log" )
|
13
|
-
$logger.level = Logger::DEBUG
|
14
|
-
|
15
|
-
$logger.debug( "Have a request!" )
|
16
|
-
|
17
|
-
# You can config the
|
18
|
-
cfg = 'services/sample:
|
19
|
-
- Details'
|
20
|
-
json_rpc = CGI_JSON_RPC.new( cfg )
|
21
|
-
|
22
|
-
print "content-type: text/javascript\n\n"
|
23
|
-
res = json_rpc.process_request
|
24
|
-
$logger.debug( "Have a resposne:\n#{res}" )
|
25
|
-
|
26
|
-
print res
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# Logfile created on Sun Feb 27 14:21:31 US Mountain Standard Time 2005 by logger.rb/1.5.2.4
|
2
|
-
D, [2005-02-27T14:28:39.063000 #124] DEBUG -- : Have a request!
|
3
|
-
D, [2005-02-27T14:29:18.680000 #1944] DEBUG -- : Have a request!
|
4
|
-
D, [2005-02-27T14:29:18.720000 #1944] DEBUG -- : Have a resposne:
|
5
|
-
{ "result" : ["system.listMethods","system.listMethods","sample.calls_so_far","sample.complex_struct","sample.foo","sample.foo=","sample.metatag_sets","sample.tag_list"], "error":"", "id": "default" }
|
6
|
-
D, [2005-02-27T14:30:13.129000 #336] DEBUG -- : Have a request!
|
7
|
-
D, [2005-02-27T14:30:13.159000 #336] DEBUG -- : Have a resposne:
|
8
|
-
{ "result" : ["system.listMethods","system.listMethods"], "error":"", "id": "default" }
|
9
|
-
D, [2005-02-27T14:30:45.415000 #1752] DEBUG -- : Have a request!
|
10
|
-
D, [2005-02-27T14:30:45.455000 #1752] DEBUG -- : Have a resposne:
|
11
|
-
{ "result" : ["system.listMethods","system.listMethods","details.fetch"], "error":"", "id": "default" }
|
12
|
-
D, [2005-02-27T14:30:48.840000 #1596] DEBUG -- : Have a request!
|
13
|
-
D, [2005-02-27T14:30:48.870000 #1596] DEBUG -- : Have a resposne:
|
14
|
-
{ "result" : "It's got soul, and it's super bad!", "error":"", "id": "default" }
|
15
|
-
D, [2005-02-27T14:30:52.415000 #1752] DEBUG -- : Have a request!
|
16
|
-
D, [2005-02-27T14:30:52.445000 #1752] DEBUG -- : Have a resposne:
|
17
|
-
{ "result" : "It's got soul, and it's super bad!", "error":"", "id": "default" }
|
18
|
-
D, [2005-02-27T14:31:00.076000 #1596] DEBUG -- : Have a request!
|
19
|
-
D, [2005-02-27T14:31:00.106000 #1596] DEBUG -- : Have a resposne:
|
20
|
-
{ "result" : "Like XML-RPC, but use JSON as the wire format.", "error":"", "id": "default" }
|
21
|
-
D, [2005-02-27T14:31:03.491000 #1752] DEBUG -- : Have a request!
|
22
|
-
D, [2005-02-27T14:31:03.511000 #1752] DEBUG -- : Have a resposne:
|
23
|
-
{ "result" : "A serialization format for transmitting native JavaScript objects as plain text.", "error":"", "id": "default" }
|
24
|
-
D, [2005-02-27T14:33:10.594000 #1396] DEBUG -- : Have a request!
|
25
|
-
D, [2005-02-27T14:33:10.624000 #1396] DEBUG -- : Have a resposne:
|
26
|
-
{ "result" : "It's got soul, and it's super bad!", "error":"", "id": "default" }
|
27
|
-
D, [2005-02-27T14:35:55.861000 #2064] DEBUG -- : Have a request!
|
28
|
-
D, [2005-02-27T14:35:55.921000 #2064] DEBUG -- : Have a resposne:
|
29
|
-
{ "result" : ["system.listMethods","system.listMethods","details.fetch"], "error":"", "id": "default" }
|
30
|
-
D, [2005-02-27T14:36:01.119000 #2076] DEBUG -- : Have a request!
|
31
|
-
D, [2005-02-27T14:36:01.139000 #2076] DEBUG -- : Have a resposne:
|
32
|
-
{ "result" : "It's got soul, and it's super bad!", "error":"", "id": "default" }
|
33
|
-
D, [2005-02-27T14:36:09.431000 #1588] DEBUG -- : Have a request!
|
34
|
-
D, [2005-02-27T14:36:09.451000 #1588] DEBUG -- : Have a resposne:
|
35
|
-
{ "result" : "Like XML-RPC, but use JSON as the wire format.", "error":"", "id": "default" }
|
@@ -1,187 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* JSON-RPC JavaScript client
|
3
|
-
*
|
4
|
-
* $Id: jsonrpc.js,v 1.1.1.1 2005/02/28 03:06:30 jamesgbritt Exp $
|
5
|
-
*
|
6
|
-
* Copyright (c) 2003-2004 Jan-Klaas Kollhof
|
7
|
-
* Copyright (c) 2005 Michael Clark, Metaparadigm Pte Ltd
|
8
|
-
*
|
9
|
-
* This code is based on Jan-Klaas' JavaScript o lait library (jsolait).
|
10
|
-
*
|
11
|
-
* This library is free software; you can redistribute it and/or
|
12
|
-
* modify it under the terms of the GNU Lesser General Public (LGPL)
|
13
|
-
* License as published by the Free Software Foundation; either
|
14
|
-
* version 2.1 of the License, or (at your option) any later version.
|
15
|
-
*
|
16
|
-
* This library is distributed in the hope that it will be useful,
|
17
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
19
|
-
* Lesser General Public License for more details: http://www.gnu.org/
|
20
|
-
*
|
21
|
-
*/
|
22
|
-
|
23
|
-
// TODO: Add async
|
24
|
-
// TODO: Add HTTP auth (user, password)
|
25
|
-
|
26
|
-
Object.prototype.toJSON = function Object_toJSON() {
|
27
|
-
var v = [];
|
28
|
-
for(attr in this) {
|
29
|
-
if(this[attr] == null) v.push("\"" + attr + "\": null");
|
30
|
-
else if(typeof this[attr] == "function"); // skip
|
31
|
-
else v.push("\"" + attr + "\": " + this[attr].toJSON());
|
32
|
-
}
|
33
|
-
return "{" + v.join(", ") + "}";
|
34
|
-
}
|
35
|
-
|
36
|
-
String.prototype.toJSON = function String_toJSON() {
|
37
|
-
return "\"" + this.replace(/([\"\\])/g, "\\$1") + "\"";
|
38
|
-
}
|
39
|
-
|
40
|
-
Number.prototype.toJSON = function Number_toJSON() {
|
41
|
-
return this.toString();
|
42
|
-
}
|
43
|
-
|
44
|
-
Boolean.prototype.toJSON = function Boolean_toJSON() {
|
45
|
-
return this.toString();
|
46
|
-
}
|
47
|
-
|
48
|
-
Date.prototype.toJSON = function Date_toJSON() {
|
49
|
-
this.valueOf().toString();
|
50
|
-
}
|
51
|
-
|
52
|
-
Array.prototype.toJSON = function Array_toJSON() {
|
53
|
-
var v = [];
|
54
|
-
for(var i=0; i<this.length; i++) {
|
55
|
-
if(this[i] == null) v.push("null");
|
56
|
-
else v.push(this[i].toJSON());
|
57
|
-
}
|
58
|
-
return "[" + v.join(", ") + "]";
|
59
|
-
}
|
60
|
-
|
61
|
-
JSONRpcClient = function JSONRpcClient_ctor(serverURL, objectID) {
|
62
|
-
this.serverURL = serverURL;
|
63
|
-
this.objectID = objectID;
|
64
|
-
|
65
|
-
// Lazy initialization of the XMLHttpRequest singleton
|
66
|
-
if(!JSONRpcClient.http)
|
67
|
-
JSONRpcClient.http = JSONRpcClient.getHTTPRequest();
|
68
|
-
|
69
|
-
// Add standard methods
|
70
|
-
this.addMethods(["system.listMethods"]);
|
71
|
-
|
72
|
-
// Query the methods on the server and add them to this object
|
73
|
-
var m = this.sendRequest("system.listMethods", []);
|
74
|
-
this.addMethods(m);
|
75
|
-
}
|
76
|
-
|
77
|
-
JSONRpcClient.Exception = function JSONRpcClient_Exception_ctor(code, msg) {
|
78
|
-
this.code = code;
|
79
|
-
this.msg = msg;
|
80
|
-
}
|
81
|
-
|
82
|
-
JSONRpcClient.Exception.prototype.toString =
|
83
|
-
function JSONRpcClient_Exception_toString(code, msg) {
|
84
|
-
return "JSONRpcClientException: " + this.msg;
|
85
|
-
}
|
86
|
-
|
87
|
-
JSONRpcClient.Method =
|
88
|
-
function JSONRpcClient_Method_ctor(client, methodName) {
|
89
|
-
var fn=function() {
|
90
|
-
var args = [];
|
91
|
-
for(var i=0;i<arguments.length;i++) {
|
92
|
-
args.push(arguments[i]);
|
93
|
-
}
|
94
|
-
return fn.client.sendRequest.call(fn.client, fn.methodName, args);
|
95
|
-
}
|
96
|
-
fn.client = client;
|
97
|
-
fn.methodName = methodName;
|
98
|
-
return fn;
|
99
|
-
}
|
100
|
-
|
101
|
-
JSONRpcClient.prototype.addMethods =
|
102
|
-
function JSONRpcClient_addMethods(methodNames) {
|
103
|
-
for(var i=0; i<methodNames.length; i++) {
|
104
|
-
var obj = this;
|
105
|
-
var names = methodNames[i].split(".");
|
106
|
-
for(var n=0; n<names.length-1; n++){
|
107
|
-
var name = names[n];
|
108
|
-
if(obj[name]){
|
109
|
-
obj = obj[name];
|
110
|
-
}
|
111
|
-
else {
|
112
|
-
obj[name] = new Object();
|
113
|
-
obj = obj[name];
|
114
|
-
}
|
115
|
-
}
|
116
|
-
var name = names[names.length-1];
|
117
|
-
if(!obj[name]){
|
118
|
-
var method = new JSONRpcClient.Method(this, methodNames[i]);
|
119
|
-
obj[name] = method;
|
120
|
-
}
|
121
|
-
}
|
122
|
-
}
|
123
|
-
|
124
|
-
JSONRpcClient.prototype.sendRequest =
|
125
|
-
function JSONRpcClient_sendRequest(methodName, args) {
|
126
|
-
// Make request object
|
127
|
-
var obj = {"method" : methodName, "params" : args};
|
128
|
-
if (this.objectID) obj.objectID = this.objectID;
|
129
|
-
|
130
|
-
// Marshall the request object to a JSON string
|
131
|
-
var req_data = obj.toJSON();
|
132
|
-
|
133
|
-
// Send the request
|
134
|
-
JSONRpcClient.http.open("POST", this.serverURL, false); // no async
|
135
|
-
// setRequestHeader is missing in Opera 8 Beta
|
136
|
-
try {
|
137
|
-
JSONRpcClient.http.setRequestHeader("Content-type", "text/plain");
|
138
|
-
}
|
139
|
-
catch(e) {}
|
140
|
-
JSONRpcClient.http.send(req_data);
|
141
|
-
|
142
|
-
// Unmarshall the response
|
143
|
-
// DEBUG
|
144
|
-
try {
|
145
|
-
eval("var obj = " + JSONRpcClient.http.responseText);
|
146
|
-
}
|
147
|
-
catch(e) {
|
148
|
-
alert( e )
|
149
|
-
alert( JSONRpcClient.http.responseText )
|
150
|
-
obj.err = e.toString()
|
151
|
-
}
|
152
|
-
if( obj.error) {
|
153
|
-
alert( JSONRpcClient.http.responseText )
|
154
|
-
throw new JSONRpcClient.Exception(obj.error.code, obj.error.msg);
|
155
|
-
}
|
156
|
-
var res = obj.result;
|
157
|
-
|
158
|
-
// Handle CallableProxy
|
159
|
-
if(res && res.objectID && res.JSONRPCType == "CallableReference")
|
160
|
-
return new JSONRpcClient(this.serverURL, res.objectID);
|
161
|
-
|
162
|
-
return res;
|
163
|
-
}
|
164
|
-
|
165
|
-
JSONRpcClient.getHTTPRequest = function JSONRpcClient_getHTTPRequest() {
|
166
|
-
try { // to get the mozilla httprequest object
|
167
|
-
return new XMLHttpRequest();
|
168
|
-
}
|
169
|
-
catch(e) {}
|
170
|
-
|
171
|
-
try { // to get MS HTTP request object
|
172
|
-
return new ActiveXObject("Msxml2.XMLHTTP.4.0");
|
173
|
-
}
|
174
|
-
catch(e) {}
|
175
|
-
|
176
|
-
try { // to get MS HTTP request object
|
177
|
-
return new ActiveXObject("Msxml2.XMLHTTP");
|
178
|
-
}
|
179
|
-
catch(e) {}
|
180
|
-
|
181
|
-
try {// to get the old MS HTTP request object
|
182
|
-
return new ActiveXObject("microsoft.XMLHTTP");
|
183
|
-
}
|
184
|
-
catch(e) {}
|
185
|
-
|
186
|
-
throw new JSONRpcClient.Exception(0, "Can't create XMLHttpRequest object");
|
187
|
-
}
|