зеркало из https://github.com/mozilla/gecko-dev.git
bring the xml-rpc code up to date with current APIs (bug 109960)
r=mj@digicool.com sr=darin@netscape.com not part of the build
This commit is contained in:
Родитель
37703a0ee2
Коммит
0745c50724
|
@ -18,9 +18,9 @@
|
|||
|
||||
/*
|
||||
* XPCOM XML-RPC Client, interface definition.
|
||||
* Version: $Revision: 1.2 $
|
||||
* Version: $Revision: 1.3 $
|
||||
*
|
||||
* $Id: nsIXmlRpcClient.idl,v 1.2 2000/09/15 09:15:29 mj%digicool.com Exp $
|
||||
* $Id: nsIXmlRpcClient.idl,v 1.3 2001/11/30 08:04:22 samuel%sieb.net Exp $
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
@ -49,7 +49,7 @@ interface nsIXmlRpcClient: nsISupports {
|
|||
readonly attribute nsIURL serverURL;
|
||||
|
||||
/**
|
||||
* Call remote method methodName with given arguments.
|
||||
* Call remote method methodName asynchronously with given arguments.
|
||||
*
|
||||
* Supported arguments are:
|
||||
* nsISupportsPRUint8, nsISupportsPRUint16,
|
||||
|
@ -80,16 +80,6 @@ interface nsIXmlRpcClient: nsISupports {
|
|||
* nsIXmlRpcFault object can be retreieved with more information on the
|
||||
* fault.
|
||||
*
|
||||
* @param methodName Remote method to call.
|
||||
* @param arguments Array of arguments to pass to remote method.
|
||||
* @return Return value of remote method.
|
||||
*/
|
||||
nsISupports call(in string methodName,
|
||||
[array, size_is(count)] in nsISupports arguments, in PRUint32 count);
|
||||
|
||||
/**
|
||||
* The asynchronous version of call.
|
||||
*
|
||||
* @param listener A nsIXmlRpcClientListener that will get notified
|
||||
* of XML-RPC events.
|
||||
* @param context A context to be passed on to the listener.
|
||||
|
|
|
@ -14,13 +14,15 @@
|
|||
* Creations 2, Inc. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Martijn Pieters <mj@digicool.com> (original author)
|
||||
* Samuel Sieb <samuel@sieb.net> brought it up to date with
|
||||
* current APIs
|
||||
*/
|
||||
|
||||
/*
|
||||
* nsXmlRpcClient XPCOM component
|
||||
* Version: $Revision: 1.17 $
|
||||
* Version: $Revision: 1.18 $
|
||||
*
|
||||
* $Id: nsXmlRpcClient.js,v 1.17 2001/05/08 17:28:07 jst%netscape.com Exp $
|
||||
* $Id: nsXmlRpcClient.js,v 1.18 2001/11/30 08:04:24 samuel%sieb.net Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -94,94 +96,6 @@ nsXmlRpcClient.prototype = {
|
|||
|
||||
get serverUrl() { return this._serverUrl; },
|
||||
|
||||
// BROKEN. Bug 37913
|
||||
call: function(methodName, methodArgs, count) {
|
||||
debug('call');
|
||||
// Check for call in progress.
|
||||
if (this._inProgress)
|
||||
throw Components.Exception('Call in progress!');
|
||||
|
||||
// Check for the server URL;
|
||||
if (!this._serverUrl)
|
||||
throw Components.Exception('Not initilized');
|
||||
|
||||
this._inProgress = true;
|
||||
|
||||
// Clear state.
|
||||
this._status = null;
|
||||
this._errorMsg = null;
|
||||
|
||||
debug('Arguments: ' + methodArgs);
|
||||
|
||||
// Generate request body
|
||||
var xmlWriter = new XMLWriter();
|
||||
this._generateRequestBody(xmlWriter, methodName, methodArgs);
|
||||
|
||||
var requestBody = xmlWriter.data;
|
||||
|
||||
debug('Request: ' + requestBody);
|
||||
|
||||
var channel = this._getChannel(requestBody);
|
||||
|
||||
debug('Do the deed.');
|
||||
|
||||
var input = channel.open(0, 0, 0);
|
||||
input = toScriptableStream(input);
|
||||
|
||||
var now = new Date()
|
||||
// This is broken! See bug 11859
|
||||
// yes, if we use asyncCall on ourselves, we still don't
|
||||
// work. Valeski calls this an event pump blocking problem.
|
||||
while (!input.available()) { // Wait for data
|
||||
if (new Date() - now > 1 * 60 * 1000) {
|
||||
this._inProgress = false;
|
||||
throw Components.Exception('Connection timed out');
|
||||
}
|
||||
}
|
||||
|
||||
this._reponseStatus = channel.responseStatus;
|
||||
this._responseString = channel.responseString;
|
||||
|
||||
// Check for a 200 response.
|
||||
if (channel.responseStatus != 200) {
|
||||
this._status = Components.results.NS_ERROR_FAILURE;
|
||||
this._errorMsg = 'Server returned unexpected status ' +
|
||||
channel.responseStatus;
|
||||
this._inProgress = false;
|
||||
throw Components.Exception('Server returned unexpected status ' +
|
||||
channel.responseStatus);
|
||||
}
|
||||
|
||||
// check content type
|
||||
if (channel.contentType != 'text/xml') {
|
||||
this._status = Components.results.NS_ERROR_FAILURE;
|
||||
this._errorMsg = 'Server returned unexpected content-type ' +
|
||||
channel.contentType;
|
||||
this._inProgress = false;
|
||||
throw Components.Exception('Server returned unexpected ' +
|
||||
'content-type ' + channel.contentType);
|
||||
}
|
||||
|
||||
debug('Viable response. Let\'s parse!');
|
||||
debug('Content length = ' + channel.contentLength);
|
||||
|
||||
try {
|
||||
this._parseResponse(toScriptableStream(inStr),
|
||||
channel.contentLength);
|
||||
debug('Parse finished');
|
||||
debug('Fault? ' + this._fault);
|
||||
debug('Result? ' + this._result);
|
||||
} catch(ex) {
|
||||
this._status = ex.result;
|
||||
this._errorMsg = ex.message;
|
||||
throw ex;
|
||||
} finally {
|
||||
this._inProgress = false;
|
||||
}
|
||||
|
||||
return this._result;
|
||||
},
|
||||
|
||||
// Internal copy of the status, so's we can throw it to the syncnronous
|
||||
// caller.
|
||||
_status: null,
|
||||
|
@ -228,27 +142,24 @@ nsXmlRpcClient.prototype = {
|
|||
// Set up channel.
|
||||
var ioService = getService('@mozilla.org/network/io-service;1',
|
||||
'nsIIOService');
|
||||
var atomService = getService('@mozilla.org/atom-service;1',
|
||||
'nsIAtomService');
|
||||
|
||||
var chann = ioService.newChannelFromURI(this._serverUrl)
|
||||
.QueryInterface(Components.interfaces.nsIHTTPChannel);
|
||||
.QueryInterface(Components.interfaces.nsIHttpChannel);
|
||||
|
||||
// Set the request method.
|
||||
chann.SetRequestMethod(atomService.getAtom('POST'));
|
||||
chann.requestMethod = 'POST';
|
||||
|
||||
// Create a stream out of the request and attach it to the channel
|
||||
// Note: pending bug #37773, an extra \r\n needs to be added.
|
||||
var handler = ioService.getProtocolHandler(this._serverUrl.scheme)
|
||||
.QueryInterface(Components.interfaces.nsIHTTPProtocolHandler);
|
||||
var postStream = handler.NewPostDataStream(false, '\r\n' + request,
|
||||
handler.ENCODE_NORMAL);
|
||||
chann.UploadStream = postStream;
|
||||
|
||||
// Set the request headers
|
||||
chann.SetRequestHeader(atomService.getAtom('content-type'), 'text/xml');
|
||||
chann.SetRequestHeader(atomService.getAtom('content-length'),
|
||||
request.length);
|
||||
// and pending bug 112479, we have to set the headers manually.
|
||||
chann.setRequestHeader('content-type', 'text/xml');
|
||||
chann.setRequestHeader('content-length', request.length);
|
||||
request = "\r\n" + request;
|
||||
var upload = chann.QueryInterface(Components.interfaces.nsIUploadChannel);
|
||||
var postStream = createInstance('@mozilla.org/io/string-input-stream;1',
|
||||
'nsIStringInputStream');
|
||||
postStream.setData(request, request.length);
|
||||
upload.setUploadStream(postStream, 'text/xml', -1);
|
||||
|
||||
return chann;
|
||||
},
|
||||
|
@ -332,8 +243,8 @@ nsXmlRpcClient.prototype = {
|
|||
|
||||
// Store request status and message.
|
||||
channel = channel
|
||||
.QueryInterface(Components.interfaces.nsIHTTPChannel);
|
||||
this._reponseStatus = channel.responseStatus;
|
||||
.QueryInterface(Components.interfaces.nsIHttpChannel);
|
||||
this._responseStatus = channel.responseStatus;
|
||||
this._responseString = channel.responseString;
|
||||
|
||||
// Check for a 200 response.
|
||||
|
@ -822,8 +733,8 @@ XMLWriter.prototype = {
|
|||
},
|
||||
|
||||
write: function(text) {
|
||||
for (var i in text) {
|
||||
var c = text.charAt(i);
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
var c = text[i];
|
||||
switch (c) {
|
||||
case '<':
|
||||
this.data += '<';
|
||||
|
|
|
@ -28,19 +28,6 @@ function callAsync() {
|
|||
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);
|
||||
}
|
||||
|
||||
var Listener = {
|
||||
onResult: function(client, ctxt, result) {
|
||||
result = result.QueryInterface(Components.interfaces.nsISupportsString);
|
||||
|
@ -69,7 +56,6 @@ var Listener = {
|
|||
<vbox>
|
||||
<spacer flex="1"/>
|
||||
<button label="Call Async." onclick="callAsync()"/>
|
||||
<button label="Call Sync." onclick="callSync()"/>
|
||||
<spacer flex="1"/>
|
||||
</vbox>
|
||||
</window>
|
||||
|
|
Загрузка…
Ссылка в новой задаче