summaryrefslogtreecommitdiff
path: root/webapps/qooxdoo-0.6.3-sdk/frontend/demo/source/html/test/RPC_2.html
blob: 14778b3fb0c6e3fab4698fd8fd64f44fac7d46d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>qooxdoo &raquo; 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><strong>Only works together with a RPC backend!</strong></p>
    <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.Exchange", "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.RequestQueue.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>