Fossil SCM

Some touch-ups in the JS code. Started adding Rhino-based tests for integration/unit-testing CGI/server modes.

stephan 2011-09-30 14:11 UTC json
Commit 42a07be4c5460a1f461e42522aa07be217218be3
--- a/ajax/i-test/rhino-test.js
+++ b/ajax/i-test/rhino-test.js
@@ -0,0 +1,51 @@
1
+//osb.flush(cription = 'Log ou'http://localhost:8080'68.1.62:8080'
2
+ //'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi'
3
+ ,
4
+ verbose:true,
5
+ fossilBinary:'fossil',
6
+ wiki:{}
7
+};
8
+(function bootstrap() {
9
+ var srcdir = '../js/';
10
+ var includes = [srcdir+'json2.js',
11
+ srcdir+'whajaj.js',
12
+ srcdir+'fossil-ajaj.js'
13
+ ];
14
+ for( var i in includes ) {
15
+ load(includes[i]);
16
+ () {
17
+ var srcdir = '../js/'h.Connectoes = [srcdir+ },
18
+ afterSend:',
19
+ srcd // ,
20
+ {
21
+ load(includes["+ soptl-json.cgi'
22
+ //'afterSend//'http://fossil.wanderinghorse.print("SENT REQUEST: "+ soptl-json.cgi'
23
+ //'http://192.1d = fun verbose:true,
24
+ fossilBinary:'fossil',
25
+ wiki:{}
26
+};
27
+(function bootstrap() {
28
+ var src;
29
+ var includes = [srcdir+'json2.js',
30
+ srcdir+'whajaj.js',
31
+ srcdir+'fossil-ajaj.js'
32
+ ];
33
+ for( var i in includes ) {
34
+ load(includes[i]);
35
+ () {
36
+ var srcdir = '../js/'h.Connectoes = [srcdir+ },
37
+ print // ,
38
+ ver ];
39
+ for( var throw new Error( for( var i in includes ) {
40
+ load(includes[i]);
41
+ );
42
+ }
43
+ WhAjaj.Connector.pr },
44
+ onError:',
45
+ srcd asynchronousnous:false, /* rhino- ,
46
+ verlBinary:TestApp.fossilBinary
47
+ });
48
+ var cb = TestApp.fossil.ajaj.callbacks;
49
+ cb.befo }
50
+ }); if(!TestApp.verbose) return;
51
+ print("SENDING REQUEST: AJA
--- a/ajax/i-test/rhino-test.js
+++ b/ajax/i-test/rhino-test.js
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/ajax/i-test/rhino-test.js
+++ b/ajax/i-test/rhino-test.js
@@ -0,0 +1,51 @@
1 //osb.flush(cription = 'Log ou'http://localhost:8080'68.1.62:8080'
2 //'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi'
3 ,
4 verbose:true,
5 fossilBinary:'fossil',
6 wiki:{}
7 };
8 (function bootstrap() {
9 var srcdir = '../js/';
10 var includes = [srcdir+'json2.js',
11 srcdir+'whajaj.js',
12 srcdir+'fossil-ajaj.js'
13 ];
14 for( var i in includes ) {
15 load(includes[i]);
16 () {
17 var srcdir = '../js/'h.Connectoes = [srcdir+ },
18 afterSend:',
19 srcd // ,
20 {
21 load(includes["+ soptl-json.cgi'
22 //'afterSend//'http://fossil.wanderinghorse.print("SENT REQUEST: "+ soptl-json.cgi'
23 //'http://192.1d = fun verbose:true,
24 fossilBinary:'fossil',
25 wiki:{}
26 };
27 (function bootstrap() {
28 var src;
29 var includes = [srcdir+'json2.js',
30 srcdir+'whajaj.js',
31 srcdir+'fossil-ajaj.js'
32 ];
33 for( var i in includes ) {
34 load(includes[i]);
35 () {
36 var srcdir = '../js/'h.Connectoes = [srcdir+ },
37 print // ,
38 ver ];
39 for( var throw new Error( for( var i in includes ) {
40 load(includes[i]);
41 );
42 }
43 WhAjaj.Connector.pr },
44 onError:',
45 srcd asynchronousnous:false, /* rhino- ,
46 verlBinary:TestApp.fossilBinary
47 });
48 var cb = TestApp.fossil.ajaj.callbacks;
49 cb.befo }
50 }); if(!TestApp.verbose) return;
51 print("SENDING REQUEST: AJA
--- ajax/js/fossil-ajaj.js
+++ ajax/js/fossil-ajaj.js
@@ -179,6 +179,32 @@
179179
FossilAjaj.prototype.HAI = function(ajajOpt) {
180180
this.sendCommand('/json/HAI', null, ajajOpt);
181181
};
182182
183183
184
-
184
+/**
185
+ Sends a /json/whoami request. Updates this.userName and this.authToken
186
+ based on the response, removing them if the response does not contain
187
+ that data.
188
+*/
189
+FossilAjaj.prototype.whoami = function(ajajOpt) {
190
+ var self = this;
191
+ ajajOpt = this.ajaj.normalizeAjaxParameters( ajajOpt || {} );
192
+ var oldOnResponse = ajajOpt.onResponse;
193
+ ajajOpt.onResponse = function(resp,req) {
194
+ var thisOpt = this;
195
+ //alert('login response:\n'+WhAjaj.stringify(resp));
196
+ if( resp && resp.payload ){
197
+ if( resp.payload.authToken ) self.authToken = resp.payload.authToken;
198
+ if( resp.payload.name ) self.userName = resp.payload.name;
199
+ }
200
+ else {
201
+ delete self.userName;
202
+ delete self.authToken
203
+ }
204
+ if( WhAjaj.isFunction(oldOnResponse) ) {
205
+ try { oldOnResponse.apply(thisOpt,[resp,req]); }
206
+ catch(e) {}
207
+ }
208
+ };
209
+ self.sendCommand('/json/whoami', undefined, ajajOpt);
210
+};
185211
--- ajax/js/fossil-ajaj.js
+++ ajax/js/fossil-ajaj.js
@@ -179,6 +179,32 @@
179 FossilAjaj.prototype.HAI = function(ajajOpt) {
180 this.sendCommand('/json/HAI', null, ajajOpt);
181 };
182
183
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
--- ajax/js/fossil-ajaj.js
+++ ajax/js/fossil-ajaj.js
@@ -179,6 +179,32 @@
179 FossilAjaj.prototype.HAI = function(ajajOpt) {
180 this.sendCommand('/json/HAI', null, ajajOpt);
181 };
182
183
184 /**
185 Sends a /json/whoami request. Updates this.userName and this.authToken
186 based on the response, removing them if the response does not contain
187 that data.
188 */
189 FossilAjaj.prototype.whoami = function(ajajOpt) {
190 var self = this;
191 ajajOpt = this.ajaj.normalizeAjaxParameters( ajajOpt || {} );
192 var oldOnResponse = ajajOpt.onResponse;
193 ajajOpt.onResponse = function(resp,req) {
194 var thisOpt = this;
195 //alert('login response:\n'+WhAjaj.stringify(resp));
196 if( resp && resp.payload ){
197 if( resp.payload.authToken ) self.authToken = resp.payload.authToken;
198 if( resp.payload.name ) self.userName = resp.payload.name;
199 }
200 else {
201 delete self.userName;
202 delete self.authToken
203 }
204 if( WhAjaj.isFunction(oldOnResponse) ) {
205 try { oldOnResponse.apply(thisOpt,[resp,req]); }
206 catch(e) {}
207 }
208 };
209 self.sendCommand('/json/whoami', undefined, ajajOpt);
210 };
211
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -871,11 +871,63 @@
871871
{
872872
args.errorMessage = e.toString();
873873
WhAjaj.Connector.sendHelper.onSendError( request, args );
874874
return undefined;
875875
}
876
- }/*jQuery*/
876
+ }/*jQuery*/,
877
+ /**
878
+ This is a concrete implementation of
879
+ WhAjaj.Connector.prototype.sendImpl() which uses the rhino
880
+ Java API to send requests and fetch the responses.
881
+
882
+ Limitations vis-a-vis the interface:
883
+
884
+ - timeouts are not supported.
885
+
886
+ - asynchronous mode is not supported because implementing it
887
+ requires the ability to kill a running thread (which is deprecated
888
+ in the Java API).
889
+ */
890
+ rhino:function(request,args)
891
+ {
892
+ var data = request || undefined;
893
+ if( data ) {
894
+ if('string'!==typeof data) {
895
+ try {
896
+ data = JSON.stringify(data);
897
+ }
898
+ catch(e) {
899
+ WhAjaj.Connector.sendHelper.onSendError( request, args );
900
+ return;
901
+ }
902
+ }
903
+ }
904
+ var url = new java.net.URL( args.url );
905
+ var con;
906
+ var IO = new JavaImporter(java.io);
907
+ var wr;
908
+ var rd, ln, json = [];
909
+ try{
910
+ con = url.openConnection();
911
+ con.setDoOutput( true );
912
+ wr = new IO.OutputStreamWriter(con.getOutputStream())
913
+ wr.write(data);
914
+ wr.flush();
915
+ rd = new IO.BufferedReader(new IO.InputStreamReader(con.getInputStream()));
916
+ while ((line = rd.readLine()) != null) {
917
+ json.push(line);
918
+ }
919
+
920
+ }catch(e){
921
+ args.errorMessage = e.toString();
922
+ WhAjaj.Connector.sendHelper.onSendError( request, args );
923
+ return undefined;
924
+ }
925
+ try { wr.close(); } catch(e) { /*ignore*/}
926
+ try { rd.close(); } catch(e) { /*ignore*/}
927
+ WhAjaj.Connector.sendHelper.onSendSuccess( request, json.join(''), args );
928
+ }
877929
};
878930
879931
/**
880932
An internal function which takes an object containing properties
881933
for a WhAjaj.Connector network request. This function creates a new
@@ -1029,6 +1081,7 @@
10291081
can be replaced with a custom implementation if one follows the rules
10301082
described throughout this API. See WhAjaj.Connector.sendImpls for
10311083
the concrete implementations included with this API.
10321084
*/
10331085
WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.XMLHttpRequest;
1086
+//WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino;
10341087
//WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.jQuery;
10351088
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -871,11 +871,63 @@
871 {
872 args.errorMessage = e.toString();
873 WhAjaj.Connector.sendHelper.onSendError( request, args );
874 return undefined;
875 }
876 }/*jQuery*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
877 };
878
879 /**
880 An internal function which takes an object containing properties
881 for a WhAjaj.Connector network request. This function creates a new
@@ -1029,6 +1081,7 @@
1029 can be replaced with a custom implementation if one follows the rules
1030 described throughout this API. See WhAjaj.Connector.sendImpls for
1031 the concrete implementations included with this API.
1032 */
1033 WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.XMLHttpRequest;
 
1034 //WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.jQuery;
1035
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -871,11 +871,63 @@
871 {
872 args.errorMessage = e.toString();
873 WhAjaj.Connector.sendHelper.onSendError( request, args );
874 return undefined;
875 }
876 }/*jQuery*/,
877 /**
878 This is a concrete implementation of
879 WhAjaj.Connector.prototype.sendImpl() which uses the rhino
880 Java API to send requests and fetch the responses.
881
882 Limitations vis-a-vis the interface:
883
884 - timeouts are not supported.
885
886 - asynchronous mode is not supported because implementing it
887 requires the ability to kill a running thread (which is deprecated
888 in the Java API).
889 */
890 rhino:function(request,args)
891 {
892 var data = request || undefined;
893 if( data ) {
894 if('string'!==typeof data) {
895 try {
896 data = JSON.stringify(data);
897 }
898 catch(e) {
899 WhAjaj.Connector.sendHelper.onSendError( request, args );
900 return;
901 }
902 }
903 }
904 var url = new java.net.URL( args.url );
905 var con;
906 var IO = new JavaImporter(java.io);
907 var wr;
908 var rd, ln, json = [];
909 try{
910 con = url.openConnection();
911 con.setDoOutput( true );
912 wr = new IO.OutputStreamWriter(con.getOutputStream())
913 wr.write(data);
914 wr.flush();
915 rd = new IO.BufferedReader(new IO.InputStreamReader(con.getInputStream()));
916 while ((line = rd.readLine()) != null) {
917 json.push(line);
918 }
919
920 }catch(e){
921 args.errorMessage = e.toString();
922 WhAjaj.Connector.sendHelper.onSendError( request, args );
923 return undefined;
924 }
925 try { wr.close(); } catch(e) { /*ignore*/}
926 try { rd.close(); } catch(e) { /*ignore*/}
927 WhAjaj.Connector.sendHelper.onSendSuccess( request, json.join(''), args );
928 }
929 };
930
931 /**
932 An internal function which takes an object containing properties
933 for a WhAjaj.Connector network request. This function creates a new
@@ -1029,6 +1081,7 @@
1081 can be replaced with a custom implementation if one follows the rules
1082 described throughout this API. See WhAjaj.Connector.sendImpls for
1083 the concrete implementations included with this API.
1084 */
1085 WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.XMLHttpRequest;
1086 //WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.rhino;
1087 //WhAjaj.Connector.prototype.sendImpl = WhAjaj.Connector.sendImpls.jQuery;
1088

Keyboard Shortcuts

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