diff options
Diffstat (limited to 'swat/apps/qooxdoo-examples/test/RPC_2.html')
-rw-r--r-- | swat/apps/qooxdoo-examples/test/RPC_2.html | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/swat/apps/qooxdoo-examples/test/RPC_2.html b/swat/apps/qooxdoo-examples/test/RPC_2.html new file mode 100644 index 0000000000..44ce5c256b --- /dev/null +++ b/swat/apps/qooxdoo-examples/test/RPC_2.html @@ -0,0 +1,133 @@ +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <title>qooxdoo » Demo</title> + <link type="text/css" rel="stylesheet" href="../../resource/css/layout.css"/> + <!--[if IE]> + <link type="text/css" rel="stylesheet" href="../../resource/css/layout_ie.css"/> + <![endif]--> + <script type="text/javascript" src="../../script/qx.js"></script> + <script type="text/javascript" src=".qxrpc"></script> + <!-- With the above script, the service URL for a J2EE application can be + automatically determined, no matter on what path it's deployed. --> +</head> +<body> + <script type="text/javascript" src="../../script/layout.js"></script> + + <div id="demoDescription"> + <p>Test for RPC functionality.</p> + <p> + This tests the ability to issue multiple asynchronous RPC calls to the + same service/method, and determine from which request we have received a + response. We issue multiple 'sleep' calls, for decreasing amounts of + time, and ensure that we can associate the resonses from the + later-issued requests to the earlier-received responses. + </p> + </div> + + <script type="text/javascript"> +// qx.Settings.setCustomOfClass("qx.io.remote.RemoteExchange", "enableDebug", true); + qx.Settings.setCustomOfClass("qx.io.Json", "enableDebug", true); + + qx.core.Init.getInstance().defineMain(function() { + var layout1 = new qx.ui.layout.VerticalBoxLayout(); + layout1.setTop(40); + layout1.setLeft(20); + layout1.setSpacing(4); + + /* + * Sigh. Both IE and Firefox follow (too strictly) RFC2616 and limit + * the number of simultaneous asyncronous HTTP requests to 2. We'll + * allow testing just 2 simultaneous requests or issuing 6 simultaneous + * requests. In the former case, we'll get expected results. In the + * latter, we'll see two at a time being processed. + * + * Note that this applies to both XmlHTTPTransport and IframeTransport. + * It is an HTTP limitation, not a limitation of a particular method of + * issuing a request. + */ + var tooMany = new qx.ui.form.CheckBox("Issue more requests than IE's and Firefox's implementations of HTTP will process simultaneously"); + layout1.add(tooMany); + + var crossDomain = new qx.ui.form.CheckBox("Cross Domain"); + layout1.add(crossDomain); + + layout1.add(new qx.ui.basic.Label("URL:")); + var defaultURL = qx.io.remote.Rpc.makeServerURL(); + if (defaultURL == null) { + defaultURL = "/services/"; + } + var url = new qx.ui.form.TextField(defaultURL); + layout1.add(url); + + layout1.add(new qx.ui.basic.Label("Service:")); + var service = new qx.ui.form.TextField("qooxdoo.test"); + layout1.add(service); + + var layout2 = new qx.ui.layout.HorizontalBoxLayout(); + layout2.setHeight("auto"); + layout2.setVerticalChildrenAlign("middle"); + layout2.setSpacing(4); + var start = new qx.ui.form.Button("Start Test"); + layout2.add(start); + var abort = new qx.ui.form.Button("Abort"); + layout2.add(abort); + layout1.add(layout2); + + // ensure there's room in the queue for all of our requests + qx.io.remote.RemoteRequestQueue.getInstance().setMaxConcurrentRequests(8); + + // We'll be setting url and service upon execute; no need to do it now. + var rpc = new qx.io.remote.Rpc(); + rpc.setTimeout(60000); + var mycall; + var mycalls = []; + + start.addEventListener("execute", function() { + t0 = new Date().getTime(); + + rpc.setCrossDomain(crossDomain.isChecked()); + + rpc.setUrl(url.getValue()); + rpc.setServiceName(service.getValue()); + + var seqnum; + for (i=(tooMany.isChecked() ? 30 : 10); i > 0; i-=5) { + /* + * Always issue an asynchronous request! Issuing a synchronous + * request can lock up the entire browser until a response is + * received. Bad browser developers! Bad! + */ + mycall = rpc.callAsync(function(result, ex, seqnum) { + mycalls[seqnum] = null; + t = new Date().getTime() - t0; + if (ex == null) { + layout1.warn(t + ": response " + seqnum + ": " + result); + } else { + layout1.warn(t + ": exception " + seqnum + ": " + ex); + } + }, "sleep", i.toString()); // FIXME: Why is this sent as a string? + + t = new Date().getTime() - t0; + seqnum = mycall.getSequenceNumber(); + mycalls[seqnum] = mycall; + layout1.warn(t + ": request " + seqnum + " = " + i.toString()); + } + }); + + abort.addEventListener("execute", function() { + for (seqnum in mycalls) { + if (mycalls[seqnum] !== null) { + rpc.abort(mycalls[seqnum]); + mycalls[seqnum] = null; + } + } + mycalls = []; + }); + + var d = qx.ui.core.ClientDocument.getInstance(); + d.add(layout1); + }); + </script> +</body> +</html> |