Fossil SCM

Added another AJAX impl which uses a local fossil binary for the back-end while using the FossilAjaj front-end interface.

stephan 2011-10-11 21:04 UTC json-multitag-test
Commit 155516632c8929d1009f18a418611a524bf29ab3
--- ajax/i-test/rhino-test.js
+++ ajax/i-test/rhino-test.js
@@ -4,10 +4,11 @@
44
//'http://fjson/cgi-bin/fossil-json.cgi'
55
//'http://192.168.1.62:8080'
66
//'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi'
77
,
88
verbose:false,
9
+ fossilBinary:'fossil',
910
wiki:{}
1011
};
1112
(function bootstrap() {
1213
var srcdir = '../js/';
1314
var includes = [srcdir+'json2.js',
@@ -19,11 +20,12 @@
1920
}
2021
WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino;
2122
TestApp.fossil = new FossilAjaj({
2223
asynchronous:false, /* rhino-based impl doesn't support async or timeout. */
2324
timeout:0,
24
- url:TestApp.serverUrl
25
+ url:TestApp.serverUrl,
26
+ fossilBinary:TestApp.fossilBinary
2527
});
2628
var cb = TestApp.fossil.ajaj.callbacks;
2729
cb.beforeSend = function(req,opt){
2830
if(!TestApp.verbose) return;
2931
print("SENDING REQUEST: AJAJ options="+JSON.stringify(opt));
@@ -55,11 +57,11 @@
5557
throw new Error("Assertion failed: "+descr);
5658
// aarrgghh. Exceptions are of course swallowed by
5759
// the AJAX layer, to keep from killing a browser's
5860
// script environment.
5961
}else{
60
- print("Assertion OK: "+descr);
62
+ if(TestApp.verbose) print("Assertion OK: "+descr);
6163
}
6264
}
6365
6466
/**
6567
Calls func() in a try/catch block and throws an exception if
@@ -74,11 +76,11 @@
7476
ex = e;
7577
}
7678
if(!ex){
7779
throw new Error("Function did not throw (as expected): "+descr);
7880
}else{
79
- print("Function threw (as expected): "+descr+": "+ex);
81
+ if(TestApp.verbose) print("Function threw (as expected): "+descr+": "+ex);
8082
}
8183
}
8284
8385
/**
8486
Convenience form of TestApp.fossil.sendCommand(command,payload,ajajOpt).
@@ -187,28 +189,72 @@
187189
});
188190
assertResponseError(rs);
189191
}
190192
testAnonLogout.description = 'Log out anonymous user.';
191193
194
+function testExternalProcess(){
195
+
196
+ var req = { command:"HAI", requestId:'testExternalProcess()' };
197
+ var args = [TestApp.fossilBinary, 'json', '--json-input', '-'];
198
+ var p = java.lang.Runtime.getRuntime().exec(args);
199
+ var outs = p.getOutputStream();
200
+ var osr = new java.io.OutputStreamWriter(outs);
201
+ var osb = new java.io.BufferedWriter(osr);
202
+ var json = JSON.stringify(req);
203
+ osb.write(json,0, json.length);
204
+ //osb.flush();
205
+ osb.close();
206
+ var ins = p.getInputStream();
207
+ var isr = new java.io.InputStreamReader(ins);
208
+ var br = new java.io.BufferedReader(isr);
209
+ var line;
210
+
211
+ while( null !== (line=br.readLine())){
212
+ print(line);
213
+ }
214
+ //outs.close();
215
+ ins.close();
216
+}
217
+testExternalProcess.description = 'Run fossil as external process.';
218
+
219
+function testExternalProcessHandler(){
220
+ var aj = TestApp.fossil.ajaj;
221
+ var oldImpl = aj.sendImpl;
222
+ aj.sendImpl = FossilAjaj.rhinoLocalBinarySendImpl;
223
+ var rs;
224
+ TestApp.fossil.sendCommand('/json/HAI',undefined,{
225
+ onResponse:function(resp,opt){
226
+ rs = resp;
227
+ }
228
+ });
229
+ aj.sendImpl = oldImpl;
230
+ assertResponseOK(rs);
231
+ print("Using local fossil binary via AJAX interface, we fetched: "+
232
+ WhAjaj.stringify(rs));
233
+}
234
+testExternalProcessHandler.description = 'Try local fossil binary via AJAX interface.';
235
+
192236
(function runAllTests(){
193237
var testList = [
194238
testHAI,
195239
testIAmNobody,
196240
testAnonymousLogin,
197241
testAnonWiki,
198
- testAnonLogout
242
+ testAnonLogout,
243
+ //testExternalProcess,
244
+ testExternalProcessHandler
199245
];
200246
var i, f;
201247
for( i = 0; i < testList.length; ++i ){
202248
f = testList[i];
203249
try{
204250
print("Running test #"+(i+1)+": "+(f.description || "no description."));
205251
f();
206252
}catch(e){
207
- print("Test failed: "+e);
253
+ print("Test #"+(i+1)+" failed: "+e);
208254
throw e;
209255
}
210256
}
211257
212258
})();
213259
214
-print("Done!");
260
+print("Done! If you don't see an exception message in the last few lines, you win!");
215261
--- ajax/i-test/rhino-test.js
+++ ajax/i-test/rhino-test.js
@@ -4,10 +4,11 @@
4 //'http://fjson/cgi-bin/fossil-json.cgi'
5 //'http://192.168.1.62:8080'
6 //'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi'
7 ,
8 verbose:false,
 
9 wiki:{}
10 };
11 (function bootstrap() {
12 var srcdir = '../js/';
13 var includes = [srcdir+'json2.js',
@@ -19,11 +20,12 @@
19 }
20 WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino;
21 TestApp.fossil = new FossilAjaj({
22 asynchronous:false, /* rhino-based impl doesn't support async or timeout. */
23 timeout:0,
24 url:TestApp.serverUrl
 
25 });
26 var cb = TestApp.fossil.ajaj.callbacks;
27 cb.beforeSend = function(req,opt){
28 if(!TestApp.verbose) return;
29 print("SENDING REQUEST: AJAJ options="+JSON.stringify(opt));
@@ -55,11 +57,11 @@
55 throw new Error("Assertion failed: "+descr);
56 // aarrgghh. Exceptions are of course swallowed by
57 // the AJAX layer, to keep from killing a browser's
58 // script environment.
59 }else{
60 print("Assertion OK: "+descr);
61 }
62 }
63
64 /**
65 Calls func() in a try/catch block and throws an exception if
@@ -74,11 +76,11 @@
74 ex = e;
75 }
76 if(!ex){
77 throw new Error("Function did not throw (as expected): "+descr);
78 }else{
79 print("Function threw (as expected): "+descr+": "+ex);
80 }
81 }
82
83 /**
84 Convenience form of TestApp.fossil.sendCommand(command,payload,ajajOpt).
@@ -187,28 +189,72 @@
187 });
188 assertResponseError(rs);
189 }
190 testAnonLogout.description = 'Log out anonymous user.';
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192 (function runAllTests(){
193 var testList = [
194 testHAI,
195 testIAmNobody,
196 testAnonymousLogin,
197 testAnonWiki,
198 testAnonLogout
 
 
199 ];
200 var i, f;
201 for( i = 0; i < testList.length; ++i ){
202 f = testList[i];
203 try{
204 print("Running test #"+(i+1)+": "+(f.description || "no description."));
205 f();
206 }catch(e){
207 print("Test failed: "+e);
208 throw e;
209 }
210 }
211
212 })();
213
214 print("Done!");
215
--- ajax/i-test/rhino-test.js
+++ ajax/i-test/rhino-test.js
@@ -4,10 +4,11 @@
4 //'http://fjson/cgi-bin/fossil-json.cgi'
5 //'http://192.168.1.62:8080'
6 //'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi'
7 ,
8 verbose:false,
9 fossilBinary:'fossil',
10 wiki:{}
11 };
12 (function bootstrap() {
13 var srcdir = '../js/';
14 var includes = [srcdir+'json2.js',
@@ -19,11 +20,12 @@
20 }
21 WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino;
22 TestApp.fossil = new FossilAjaj({
23 asynchronous:false, /* rhino-based impl doesn't support async or timeout. */
24 timeout:0,
25 url:TestApp.serverUrl,
26 fossilBinary:TestApp.fossilBinary
27 });
28 var cb = TestApp.fossil.ajaj.callbacks;
29 cb.beforeSend = function(req,opt){
30 if(!TestApp.verbose) return;
31 print("SENDING REQUEST: AJAJ options="+JSON.stringify(opt));
@@ -55,11 +57,11 @@
57 throw new Error("Assertion failed: "+descr);
58 // aarrgghh. Exceptions are of course swallowed by
59 // the AJAX layer, to keep from killing a browser's
60 // script environment.
61 }else{
62 if(TestApp.verbose) print("Assertion OK: "+descr);
63 }
64 }
65
66 /**
67 Calls func() in a try/catch block and throws an exception if
@@ -74,11 +76,11 @@
76 ex = e;
77 }
78 if(!ex){
79 throw new Error("Function did not throw (as expected): "+descr);
80 }else{
81 if(TestApp.verbose) print("Function threw (as expected): "+descr+": "+ex);
82 }
83 }
84
85 /**
86 Convenience form of TestApp.fossil.sendCommand(command,payload,ajajOpt).
@@ -187,28 +189,72 @@
189 });
190 assertResponseError(rs);
191 }
192 testAnonLogout.description = 'Log out anonymous user.';
193
194 function testExternalProcess(){
195
196 var req = { command:"HAI", requestId:'testExternalProcess()' };
197 var args = [TestApp.fossilBinary, 'json', '--json-input', '-'];
198 var p = java.lang.Runtime.getRuntime().exec(args);
199 var outs = p.getOutputStream();
200 var osr = new java.io.OutputStreamWriter(outs);
201 var osb = new java.io.BufferedWriter(osr);
202 var json = JSON.stringify(req);
203 osb.write(json,0, json.length);
204 //osb.flush();
205 osb.close();
206 var ins = p.getInputStream();
207 var isr = new java.io.InputStreamReader(ins);
208 var br = new java.io.BufferedReader(isr);
209 var line;
210
211 while( null !== (line=br.readLine())){
212 print(line);
213 }
214 //outs.close();
215 ins.close();
216 }
217 testExternalProcess.description = 'Run fossil as external process.';
218
219 function testExternalProcessHandler(){
220 var aj = TestApp.fossil.ajaj;
221 var oldImpl = aj.sendImpl;
222 aj.sendImpl = FossilAjaj.rhinoLocalBinarySendImpl;
223 var rs;
224 TestApp.fossil.sendCommand('/json/HAI',undefined,{
225 onResponse:function(resp,opt){
226 rs = resp;
227 }
228 });
229 aj.sendImpl = oldImpl;
230 assertResponseOK(rs);
231 print("Using local fossil binary via AJAX interface, we fetched: "+
232 WhAjaj.stringify(rs));
233 }
234 testExternalProcessHandler.description = 'Try local fossil binary via AJAX interface.';
235
236 (function runAllTests(){
237 var testList = [
238 testHAI,
239 testIAmNobody,
240 testAnonymousLogin,
241 testAnonWiki,
242 testAnonLogout,
243 //testExternalProcess,
244 testExternalProcessHandler
245 ];
246 var i, f;
247 for( i = 0; i < testList.length; ++i ){
248 f = testList[i];
249 try{
250 print("Running test #"+(i+1)+": "+(f.description || "no description."));
251 f();
252 }catch(e){
253 print("Test #"+(i+1)+" failed: "+e);
254 throw e;
255 }
256 }
257
258 })();
259
260 print("Done! If you don't see an exception message in the last few lines, you win!");
261
--- ajax/js/fossil-ajaj.js
+++ ajax/js/fossil-ajaj.js
@@ -198,5 +198,78 @@
198198
oldOnResponse.apply(thisOpt,[resp,req]);
199199
}
200200
};
201201
self.sendCommand('/json/whoami', undefined, ajajOpt);
202202
};
203
+
204
+/**
205
+ EXPERIMENTAL concrete WhAjaj.Connector.sendImpl() implementation which
206
+ uses Rhino to connect to a local fossil binary for input and output. Its
207
+ signature and semantics are as described for
208
+ WhAjaj.Connector.prototype.sendImpl(), with a few exceptions and
209
+ additions:
210
+
211
+ - It does not support timeouts or asynchronous mode.
212
+
213
+ - The args.fossilBinary property must point to the local fossil binary
214
+ (it need not be a complete path if fossil is in the $PATH). This
215
+ function throws (without calling any request callbacks) if
216
+ args.fossilBinary is not set. fossilBinary may be set on
217
+ WhAjaj.Connector.options.ajax, in the FossilAjaj constructor call, as
218
+ the ajax options parameter to any of the FossilAjaj.sendCommand() family
219
+ of functions, or by setting
220
+ aFossilAjajInstance.ajaj.options.fossilBinary on a specific
221
+ FossilAjaj instance.
222
+
223
+ - It uses the args.url field to create the "command" property of the
224
+ request, constructs a request envelope, spawns a fossil process in JSON
225
+ mode, feeds it the request envelope, and returns the response envelope
226
+ via the same mechanisms defined for the HTTP-based implementations.
227
+
228
+ The interface is otherwise compatible with the "normal"
229
+ FossilAjaj.sendCommand() front-end (it is, however, fossil-specific, and
230
+ not back-end agnostic like the WhAjaj.sendImpl() interface intends).
231
+
232
+
233
+*/
234
+FossilAjaj.rhinoLocalBinarySendImpl = function(request,args){
235
+ var self = this;
236
+ request = request || {};
237
+ if(!args.fossilBinary){
238
+ throw new Error("fossilBinary is not set on AJAX options!");
239
+ }
240
+ var url = args.url.split('?')[0].split(/\/+/);
241
+ if(url.length>1){
242
+ // 3x shift(): protocol, host, 'json' part of path
243
+ request.command = (url.shift(),url.shift(),url.shift(), url.join('/'));
244
+ }
245
+ delete args.url;
246
+ //print("rhinoLocalBinarySendImpl SENDING: "+WhAjaj.stringify(request));
247
+ var json;
248
+ try{
249
+ var pargs = [args.fossilBinary, 'json', '--json-input', '-'];
250
+ var p = java.lang.Runtime.getRuntime().exec(pargs);
251
+ var outs = p.getOutputStream();
252
+ var osr = new java.io.OutputStreamWriter(outs);
253
+ var osb = new java.io.BufferedWriter(osr);
254
+
255
+ json = JSON.stringify(request);
256
+ osb.write(json,0, json.length);
257
+ osb.close();
258
+ var ins = p.getInputStream();
259
+ var isr = new java.io.InputStreamReader(ins);
260
+ var br = new java.io.BufferedReader(isr);
261
+ var line;
262
+ json = [];
263
+ while( null !== (line=br.readLine())){
264
+ json.push(line);
265
+ }
266
+ ins.close();
267
+ }catch(e){
268
+ args.errorMessage = e.toString();
269
+ WhAjaj.Connector.sendHelper.onSendError.apply( self, [request, args] );
270
+ return undefined;
271
+ }
272
+ json = json.join('');
273
+ //print("READ IN JSON: "+json);
274
+ WhAjaj.Connector.sendHelper.onSendSuccess.apply( self, [request, json, args] );
275
+}/*rhinoLocalBinary*/
203276
--- ajax/js/fossil-ajaj.js
+++ ajax/js/fossil-ajaj.js
@@ -198,5 +198,78 @@
198 oldOnResponse.apply(thisOpt,[resp,req]);
199 }
200 };
201 self.sendCommand('/json/whoami', undefined, ajajOpt);
202 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
--- ajax/js/fossil-ajaj.js
+++ ajax/js/fossil-ajaj.js
@@ -198,5 +198,78 @@
198 oldOnResponse.apply(thisOpt,[resp,req]);
199 }
200 };
201 self.sendCommand('/json/whoami', undefined, ajajOpt);
202 };
203
204 /**
205 EXPERIMENTAL concrete WhAjaj.Connector.sendImpl() implementation which
206 uses Rhino to connect to a local fossil binary for input and output. Its
207 signature and semantics are as described for
208 WhAjaj.Connector.prototype.sendImpl(), with a few exceptions and
209 additions:
210
211 - It does not support timeouts or asynchronous mode.
212
213 - The args.fossilBinary property must point to the local fossil binary
214 (it need not be a complete path if fossil is in the $PATH). This
215 function throws (without calling any request callbacks) if
216 args.fossilBinary is not set. fossilBinary may be set on
217 WhAjaj.Connector.options.ajax, in the FossilAjaj constructor call, as
218 the ajax options parameter to any of the FossilAjaj.sendCommand() family
219 of functions, or by setting
220 aFossilAjajInstance.ajaj.options.fossilBinary on a specific
221 FossilAjaj instance.
222
223 - It uses the args.url field to create the "command" property of the
224 request, constructs a request envelope, spawns a fossil process in JSON
225 mode, feeds it the request envelope, and returns the response envelope
226 via the same mechanisms defined for the HTTP-based implementations.
227
228 The interface is otherwise compatible with the "normal"
229 FossilAjaj.sendCommand() front-end (it is, however, fossil-specific, and
230 not back-end agnostic like the WhAjaj.sendImpl() interface intends).
231
232
233 */
234 FossilAjaj.rhinoLocalBinarySendImpl = function(request,args){
235 var self = this;
236 request = request || {};
237 if(!args.fossilBinary){
238 throw new Error("fossilBinary is not set on AJAX options!");
239 }
240 var url = args.url.split('?')[0].split(/\/+/);
241 if(url.length>1){
242 // 3x shift(): protocol, host, 'json' part of path
243 request.command = (url.shift(),url.shift(),url.shift(), url.join('/'));
244 }
245 delete args.url;
246 //print("rhinoLocalBinarySendImpl SENDING: "+WhAjaj.stringify(request));
247 var json;
248 try{
249 var pargs = [args.fossilBinary, 'json', '--json-input', '-'];
250 var p = java.lang.Runtime.getRuntime().exec(pargs);
251 var outs = p.getOutputStream();
252 var osr = new java.io.OutputStreamWriter(outs);
253 var osb = new java.io.BufferedWriter(osr);
254
255 json = JSON.stringify(request);
256 osb.write(json,0, json.length);
257 osb.close();
258 var ins = p.getInputStream();
259 var isr = new java.io.InputStreamReader(ins);
260 var br = new java.io.BufferedReader(isr);
261 var line;
262 json = [];
263 while( null !== (line=br.readLine())){
264 json.push(line);
265 }
266 ins.close();
267 }catch(e){
268 args.errorMessage = e.toString();
269 WhAjaj.Connector.sendHelper.onSendError.apply( self, [request, args] );
270 return undefined;
271 }
272 json = json.join('');
273 //print("READ IN JSON: "+json);
274 WhAjaj.Connector.sendHelper.onSendSuccess.apply( self, [request, json, args] );
275 }/*rhinoLocalBinary*/
276
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -1044,11 +1044,11 @@
10441044
try { if(wr) wr.close(); } catch(e) { /*ignore*/}
10451045
try { if(rd) rd.close(); } catch(e) { /*ignore*/}
10461046
json = json.join('');
10471047
//print("READ IN JSON: "+json);
10481048
WhAjaj.Connector.sendHelper.onSendSuccess.apply( self, [request, json, args] );
1049
- }/*rhino()*/
1049
+ }/*rhino*/
10501050
};
10511051
10521052
/**
10531053
An internal function which takes an object containing properties
10541054
for a WhAjaj.Connector network request. This function creates a new
10551055
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -1044,11 +1044,11 @@
1044 try { if(wr) wr.close(); } catch(e) { /*ignore*/}
1045 try { if(rd) rd.close(); } catch(e) { /*ignore*/}
1046 json = json.join('');
1047 //print("READ IN JSON: "+json);
1048 WhAjaj.Connector.sendHelper.onSendSuccess.apply( self, [request, json, args] );
1049 }/*rhino()*/
1050 };
1051
1052 /**
1053 An internal function which takes an object containing properties
1054 for a WhAjaj.Connector network request. This function creates a new
1055
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -1044,11 +1044,11 @@
1044 try { if(wr) wr.close(); } catch(e) { /*ignore*/}
1045 try { if(rd) rd.close(); } catch(e) { /*ignore*/}
1046 json = json.join('');
1047 //print("READ IN JSON: "+json);
1048 WhAjaj.Connector.sendHelper.onSendSuccess.apply( self, [request, json, args] );
1049 }/*rhino*/
1050 };
1051
1052 /**
1053 An internal function which takes an object containing properties
1054 for a WhAjaj.Connector network request. This function creates a new
1055

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button