2000-05-06 00:49:07 +04:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
|
|
|
|
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
|
|
|
|
|
|
|
<window title="XML-RPC test"
|
|
|
|
style="margins: 5 5 5 5"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
|
|
|
|
|
|
|
<script language="javascript"><![CDATA[
|
|
|
|
function getClient() {
|
2000-09-15 03:20:49 +04:00
|
|
|
return Components.classes['@mozilla.org/xml-rpc/client;1']
|
2000-05-06 00:49:07 +04:00
|
|
|
.createInstance(Components.interfaces.nsIXmlRpcClient);
|
|
|
|
}
|
|
|
|
|
|
|
|
var xmlRpcClient;
|
|
|
|
function getXmlRpc() {
|
|
|
|
if (!xmlRpcClient) xmlRpcClient = getClient();
|
|
|
|
return xmlRpcClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
function callAsync() {
|
|
|
|
dump('Call Async\n');
|
|
|
|
var xmlRpc = getXmlRpc();
|
|
|
|
xmlRpc.init('http://betty.userland.com/RPC2');
|
2000-09-15 13:15:31 +04:00
|
|
|
var stateCode = xmlRpc.createType(xmlRpc.INT, {});
|
2000-05-06 00:49:07 +04:00
|
|
|
stateCode.data = document.getElementById('statecode').value;
|
|
|
|
|
2000-09-15 13:15:31 +04:00
|
|
|
xmlRpc.asyncCall(Listener, null, 'examples.getStateName', [stateCode], 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Broken still. :(
|
|
|
|
function callSync() {
|
|
|
|
dump('Call Sync\n');
|
|
|
|
var xmlRpc = getXmlRpc();
|
|
|
|
xmlRpc.init('http://betty.userland.com/RPC2');
|
|
|
|
var stateCode = xmlRpc.createType(xmlRpc.INT, {});
|
|
|
|
stateCode.data = document.getElementById('statecode').value;
|
|
|
|
|
|
|
|
result = xmlRpc.call('examples.getStateName', [stateCode], 1);
|
|
|
|
result = result.QueryInterface(Components.interfaces.nsISupportsString);
|
|
|
|
document.getElementById('statename').setAttribute('value', result.data);
|
2000-05-06 00:49:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var Listener = {
|
|
|
|
onResult: function(client, ctxt, result) {
|
2000-09-15 13:15:31 +04:00
|
|
|
result = result.QueryInterface(Components.interfaces.nsISupportsString);
|
2000-05-06 00:49:07 +04:00
|
|
|
document.getElementById('statename').setAttribute('value', result.data);
|
|
|
|
},
|
|
|
|
|
|
|
|
onFault: function(client, ctxt, fault) {
|
|
|
|
dump('Fault! ' + fault + '\n');
|
|
|
|
},
|
|
|
|
|
|
|
|
onError: function(client, ctxt, status, errorMsg) {
|
|
|
|
dump('Error! <(' + status.toString(16) + ') ' + errorMsg + '>\n');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
]]></script>
|
|
|
|
|
|
|
|
<box orient="vertical" flex="1">
|
|
|
|
<spring flex="1"/>
|
|
|
|
<text value="Enter a state code:"/>
|
2001-03-22 03:15:47 +03:00
|
|
|
<textbox id="statecode"/>
|
2000-05-06 00:49:07 +04:00
|
|
|
<text value="Statename:"/>
|
|
|
|
<text id="statename" value=" "/>
|
|
|
|
<spring flex="1"/>
|
|
|
|
</box>
|
|
|
|
|
|
|
|
<box orient="vertical">
|
|
|
|
<spring flex="1"/>
|
|
|
|
<button value="Call Async." onclick="callAsync()"/>
|
2000-09-15 13:15:31 +04:00
|
|
|
<button value="Call Sync." onclick="callSync()"/>
|
2000-05-06 00:49:07 +04:00
|
|
|
<spring flex="1"/>
|
|
|
|
</box>
|
|
|
|
</window>
|