3 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
4 <title>qooxdoo
» Demo
</title>
5 <link type=
"text/css" rel=
"stylesheet" href=
"../../resource/css/layout.css"/>
7 <link type="text/css" rel="stylesheet" href="../../resource/css/layout_ie.css"/>
9 <script type=
"text/javascript" src=
"../../script/qx.js"></script>
10 <script type=
"text/javascript" src=
".qxrpc"></script>
11 <!-- With the above script, the service URL for a J2EE application can be
12 automatically determined, no matter on what path it's deployed. -->
15 <script type=
"text/javascript" src=
"../../script/layout.js"></script>
17 <div id=
"demoDescription">
18 <p>Test for RPC functionality.
</p>
20 This test calls a whole set of functions to test each of the primitive
21 data types. The comparison results should all end with
": true", and
22 the last test generates an Application Error (#
1000). No other test
23 generates that error, so receiving it means the complete set of tests
27 These functions all use the asynchronous interface. This is the
28 interface that your applications should use. See the warning in
29 RPC_3.html regarding use of the synchronous interface.
33 <script type=
"text/javascript">
34 // qx.Settings.setCustomOfClass("qx.io.remote.RemoteExchange", "enableDebug", true);
35 qx
.Settings
.setCustomOfClass("qx.io.Json", "enableDebug", true);
37 qx
.core
.Init
.getInstance().defineMain(function() {
38 var layout1
= new qx
.ui
.layout
.VerticalBoxLayout();
41 layout1
.setSpacing(4);
43 var crossDomain
= new qx
.ui
.form
.CheckBox("Cross Domain");
44 layout1
.add(crossDomain
);
46 layout1
.add(new qx
.ui
.basic
.Label("URL:"));
47 var defaultURL
= qx
.io
.remote
.Rpc
.makeServerURL();
48 if (defaultURL
== null) {
49 defaultURL
= "/services/";
51 var url
= new qx
.ui
.form
.TextField(defaultURL
);
54 layout1
.add(new qx
.ui
.basic
.Label("Service path:"));
55 var service
= new qx
.ui
.form
.TextField("qooxdoo.test");
58 var start
= new qx
.ui
.form
.Button("Start test");
65 start
.addEventListener("execute", function() {
71 * Create an array of each of the tests. Each array element is itself
72 * an array of two function: the first to issue the test request, and
73 * the second to validate the result.
80 test
= "getCurrentTimestamp";
81 layout1
.warn("Calling '" + test
+ "'");
82 mycall
= rpc
.callAsync(handler
, test
);
87 layout1
.warn("result: now=" + result
.now
);
88 layout1
.warn("result: jsonDate=" + result
.json
.toString());
96 layout1
.warn("Calling '" + test
+ "'");
97 mycall
= rpc
.callAsync(handler
, test
);
102 layout1
.warn("result: {" + result
+ "}");
103 layout1
.warn("Returns a number, got " + typeof(result
) + ": " + (typeof(result
) == "number" && isFinite(result
) ? "true" : "false"));
111 layout1
.warn("Calling '" + test
+ "'");
112 mycall
= rpc
.callAsync(handler
, test
, 1);
117 layout1
.warn("result: {" + result
+ "}");
118 layout1
.warn("Returns an integer: " + result
);
126 layout1
.warn("Calling '" + test
+ "'");
127 mycall
= rpc
.callAsync(handler
, test
);
132 layout1
.warn("result: {" + result
+ "}");
133 layout1
.warn("Returns a string: " + (typeof(result
) == "string"));
141 layout1
.warn("Calling '" + test
+ "'");
142 mycall
= rpc
.callAsync(handler
, test
, "Hello World");
147 layout1
.warn("result: {" + result
+ "}");
148 layout1
.warn("Returns a string: " + result
);
156 layout1
.warn("Calling '" + test
+ "'");
157 var mycall
= rpc
.callAsync(handler
, test
);
162 layout1
.warn("result: {" + result
+ "}");
163 layout1
.warn("Returns null: " + (typeof(result
) == "object" && mycall
=== null ? "true" : "false"));
171 layout1
.warn("Calling '" + test
+ "'");
172 mycall
= rpc
.callAsync(handler
, test
, null);
177 layout1
.warn("result: {" + result
+ "}");
178 layout1
.warn("Returns null: " + result
);
185 test
= "getArrayInteger";
186 layout1
.warn("Calling '" + test
+ "'");
187 mycall
= rpc
.callAsync(handler
, test
);
192 layout1
.warn("result: {" + result
+ "}");
193 layout1
.warn("Returns an array: " + ((typeof(result
) == "object") && (result
instanceof Array
)));
200 test
= "getArrayString";
201 layout1
.warn("Calling '" + test
+ "'");
202 mycall
= rpc
.callAsync(handler
, test
);
207 layout1
.warn("result: {" + result
+ "}");
208 layout1
.warn("Returns an array: " + ((typeof(result
) == "object") && (result
instanceof Array
)));
215 dataArray
= new Array(5);
223 layout1
.warn("Calling '" + test
+ "'");
224 mycall
= rpc
.callAsync(handler
, test
, dataArray
);
229 layout1
.warn("result: {" + result
+ "}");
230 layout1
.warn("Returns an array: " + result
);
237 dataArray
= new Array(5);
241 dataArray
[i
] = "Element " + i
;
245 layout1
.warn("Calling '" + test
+ "'");
246 mycall
= rpc
.callAsync(handler
, test
, dataArray
);
251 layout1
.warn("result: {" + result
+ "}");
252 layout1
.warn("Returns an array: " + result
);
260 layout1
.warn("Calling '" + test
+ "'");
261 mycall
= rpc
.callAsync(handler
, test
);
266 layout1
.warn("result: {" + result
+ "}");
267 layout1
.warn("Returns a float: " + (typeof(result
) == "number"));
275 layout1
.warn("Calling '" + test
+ "'");
276 mycall
= rpc
.callAsync(handler
, test
);
281 layout1
.warn("result: {" + result
+ "}");
282 layout1
.warn("Returns an object: " + (typeof(result
) == "object"));
290 layout1
.warn("Calling '" + test
+ "'");
294 obj
.o
= new Object();
295 obj
.o
.s
= "This is a test.";
296 mycall
= rpc
.callAsync(handler
, test
, obj
);
301 layout1
.warn("result: {" + result
.toString() + "}");
302 layout1
.warn("Returns an object: " + result
);
310 layout1
.warn("Calling '" + test
+ "'");
311 mycall
= rpc
.callAsync(handler
, test
, false);
316 layout1
.warn("result: {" + result
.toString() + "}");
317 layout1
.warn("Returns a boolean: " + result
);
325 layout1
.warn("Calling '" + test
+ "'");
326 mycall
= rpc
.callAsync(handler
, test
, true);
331 layout1
.warn("result: {" + result
.toString() + "}");
332 layout1
.warn("Returns a boolean: " + result
);
340 layout1
.warn("Calling '" + test
+ "'");
341 mycall
= rpc
.callAsync(handler
, test
);
346 layout1
.warn("result: {" + result
.toString() + "}");
347 layout1
.warn("Returns a boolean = true: " + (typeof(result
) == "boolean"));
355 layout1
.warn("Calling '" + test
+ "'");
356 mycall
= rpc
.callAsync(handler
, test
);
361 layout1
.warn("result: {" + result
.toString() + "}");
362 layout1
.warn("Returns a boolean = false: " + (typeof(result
) == "boolean"));
369 Date
.prototype.classname
= "Date";
372 layout1
.warn("Calling '" + test
+ "'");
373 mycall
= rpc
.callAsync(handler
, test
, date
);
378 layout1
.warn("result: {" + result
+ "}");
379 layout1
.warn("Returns a date object, got " + (result
.classname
== date
.classname
));
380 layout1
.warn("Returns matching time " + date
.getTime() + " = " + result
.getTime() + " :" + (result
.getTime() == date
.getTime()));
387 dataArray
= new Array();
389 dataArray
[1] = false;
392 dataArray
[4] = "Hello World";
393 dataArray
[5] = new Array(5);
394 dataArray
[6] = new Object();
395 dataArray
[7] = new Date();
398 layout1
.warn("Calling '" + test
+ "'");
399 mycall
= rpc
.callAsync(handler
, test
, dataArray
[0], dataArray
[1], dataArray
[2], dataArray
[3], dataArray
[4], dataArray
[5], dataArray
[6], dataArray
[7]);
404 layout1
.warn("result: {" + result
+ "}");
406 for (i
=0; i
< dataArray
.length
; i
++)
408 layout1
.warn("Returned parameter (" + i
+ ") value '" + result
[i
] + "' matches '" + dataArray
[i
] + "': " + (result
[i
].toString() == dataArray
[i
].toString()));
409 layout1
.warn("Returned parameter (" + i
+ ") type '" + typeof(result
[i
]) + "' matches '" + typeof(dataArray
[i
]) + "': " + (typeof(result
[i
]) == typeof(dataArray
[i
])));
418 layout1
.warn("Calling '" + test
+ "'");
419 mycall
= rpc
.callAsync(handler
, test
);
424 // should never get here; we should receive an exception
425 layout1
.warn("ERROR: Should have received an exception! Got: " + result
);
431 * This is the generic handler, used by each of the tests. It
432 * ascertains whether an exception occured and alert()s with the
433 * exception if so; otherwise it calls the result validation function
434 * and then starts the next test.
436 handler = function(result
, ex
, id
) {
439 alert("Async(" + id
+ ") exception: " + ex
);
441 // display results of the completed test
442 tests
[testNum
][1](result
); // [][1] = validate response
444 // start the next test
448 if (testNum
< tests
.length
) {
449 // Nope. Run the next test.
455 // Determine which transport to use
456 rpc
= new qx
.io
.remote
.Rpc(url
.getValue(), service
.getValue());
457 rpc
.setTimeout(10000);
458 rpc
.setCrossDomain(crossDomain
.isChecked());
460 // start the first test
462 tests
[testNum
][0](); // [][0] = request
465 var d
= qx
.ui
.core
.ClientDocument
.getInstance();