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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
<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 test calls a whole set of functions to test each of the primitive
data types. The comparison results should all end with ": true", and
the last test generates an Application Error (#1000). No other test
generates that error, so receiving it means the complete set of tests
was run.
</p>
<p>
These functions all use the synchronous interface. You should not use
the synchronous interface because with some browsers, the entire browser
environment locks up during a synchronous call. If the server hangs for
a minute or two, so will the browser! You have been warned.
</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);
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 path:"));
var service = new qx.ui.form.TextField("qooxdoo.test");
layout1.add(service);
var start = new qx.ui.form.Button("Start test");
layout1.add(start);
var rpc;
var mycall = null;
var test;
start.addEventListener("execute", function() {
try
{
var rpc = new qx.io.remote.Rpc(url.getValue(), service.getValue());
rpc.setTimeout(10000);
test = "getCurrentTimestamp";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test);
layout1.warn("result: now=" + result.now);
layout1.warn("result: jsonDate=" + result.json.toString());
test = "getInteger";
layout1.warn("Calling '" + test + "'");
var result = rpc.callSync(test);
layout1.warn("result: {" + result + "}");
layout1.warn("Returns a number, got " + typeof(result) + ": " + (typeof(result) == "number" && isFinite(result) ? "true" : "false"));
test = "isInteger";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test, 1);
layout1.warn("result: {" + result + "}");
layout1.warn("Returns an integer: " + result);
test = "getString";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test);
layout1.warn("result: {" + result + "}");
layout1.warn("Returns a string: " + (typeof(result) == "string"));
test = "isString";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test, "Hello World");
layout1.warn("result: {" + result + "}");
layout1.warn("Returns a string: " + result);
test = "getNull";
layout1.warn("Calling '" + test + "'");
var result = rpc.callSync(test);
layout1.warn("result: {" + result + "}");
layout1.warn("Returns null: " + (typeof(result) == "object" && result === null ? "true" : "false"));
test = "isNull";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test, null);
layout1.warn("result: {" + result + "}");
layout1.warn("Returns null: " + result);
test = "getArrayInteger";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test);
layout1.warn("result: {" + result + "}");
layout1.warn("Returns an array: " + ((typeof(result) == "object") && (result instanceof Array)));
test = "getArrayString";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test);
layout1.warn("result: {" + result + "}");
layout1.warn("Returns an array: " + ((typeof(result) == "object") && (result instanceof Array)));
var dataArray = new Array(5);
for (i=0; i<5; i++)
{
dataArray[i] = i;
};
test = "isArray";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test, dataArray);
layout1.warn("result: {" + result + "}");
dataArray = new Array(5);
for (i=0; i<5; i++)
{
dataArray[i] = "Element " + i;
};
test = "isArray";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test, dataArray);
layout1.warn("result: {" + result + "}");
test = "getFloat";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test);
layout1.warn("result: {" + result + "}");
layout1.warn("Returns a float: " + (typeof(result) == "number"));
test = "getObject";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test);
layout1.warn("result: {" + result + "}");
layout1.warn("Returns an object: " + (typeof(result) == "object"));
test = "isObject";
layout1.warn("Calling '" + test + "'");
obj = new Object();
obj.s = "Hi there.";
obj.n = 23;
obj.o = new Object();
obj.o.s = "This is a test.";
result = rpc.callSync(test, obj);
layout1.warn("result: {" + result.toString() + "}");
layout1.warn("Returns an object: " + result);
test = "getTrue";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test);
layout1.warn("result: {" + result.toString() + "}");
layout1.warn("Returns a boolean = true: " + (typeof(result) == "boolean"));
test = "getFalse";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test);
layout1.warn("result: {" + result.toString() + "}");
layout1.warn("Returns a boolean = false: " + (typeof(result) == "boolean"));
test = "isBoolean";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test, true);
layout1.warn("result: {" + result.toString() + "}");
layout1.warn("Returns a boolean: " + result);
test = "isBoolean";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test, false);
layout1.warn("result: {" + result.toString() + "}");
layout1.warn("Returns a boolean: " + result);
Date.prototype.classname = "Date";
var date = new Date();
test = "getParam";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test, date);
layout1.warn("result: {" + result + "}");
layout1.warn("Returns a date object, got " + (result.classname == date.classname));
layout1.warn("Returns matching time " + date.getTime() + " = " + result.getTime() + " :" + (result.getTime() == date.getTime()));
dataArray = new Array();
dataArray[0] = true;
dataArray[1] = false;
dataArray[2] = 1;
dataArray[3] = 1.1;
dataArray[4] = "Hello World";
dataArray[5] = new Array(5);
dataArray[6] = new Object();
dataArray[7] = new Date();
test = "getParams";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test, dataArray[0], dataArray[1], dataArray[2], dataArray[3], dataArray[4], dataArray[5], dataArray[6], dataArray[7]);
layout1.warn("result: {" + result + "}");
for (i=0; i< dataArray.length; i++)
{
layout1.warn("Returned parameter (" + i + ") value '" + result[i] + "' matches '" + dataArray[i] + "': " + (result[i].toString() == dataArray[i].toString()));
layout1.warn("Returned parameter (" + i + ") type '" + typeof(result[i]) + "' matches '" + typeof(dataArray[i]) + "': " + (typeof(result[i]) == typeof(dataArray[i])));
};
test = "getError";
layout1.warn("Calling '" + test + "'");
result = rpc.callSync(test);
// should never get here; we should receive an exception
layout1.warn("ERROR: Should have received an exception! Got: " + result);
}
catch (ex)
{
alert("Exception on test " + test + ": " + ex);
}
});
var d = qx.ui.core.ClientDocument.getInstance();
d.add(layout1);
});
</script>
</body>
</html>
|