Since just few documentation for XMLRPC is available, I try to write some piece of code to help beginners with examples of java XMLRPC clients
I can upload the docbook source if needed.
http://appietto.free.fr/mambo/XML_RPC_Mambo.html Also including below beta source code to add basic HTTP authentification in xmlrpc.server.php (it uses new user mambot to retrieve user infos)
Code:
<?php
/**
* @version $Id: xmlrpc.server.php,v 1.6 2005/07/11 01:16:19 johanjanssens Exp $
* @package Mambo
* @copyright (C) 2000 - 2005 Miro International Pty Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* Mambo is Free Software
*/
/** Set flag that this is a parent file */
define( "_VALID_MOS", 1 );
// crank up mambo
require_once( 'configuration.php' );
if (!$mosConfig_xmlrpc_server) {
die( 'XML-RPC server not enabled.' );
}
require_once( $mosConfig_absolute_path . '/includes/mambo.php' );
$mainframe = new mosMainFrame( $database, '' );
$mainframe->initSession();
/**
* CUSTOM HANDLER FOR METHOD NOT FOUND
*/
function domXmlRpcFault( &$server, $methodName, &$params ) {
// error code according to http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
$server->serverError = -32601;
$server->serverErrorString = 'I don\'t know about ' . $methodName;
return $server->raiseFault();
} //faultExample
function domXmlRpcAuthError( &$server) {
$server->serverError = 0;
$server->serverErrorString = 'Incorrect username or password';
$server->respond($server->raiseFault());
}
// Includes the required class file for the XML-RPC Server
require_once( $mosConfig_absolute_path . '/includes/domit/dom_xmlrpc_server.php' );
require_once( DOM_XMLRPC_INCLUDE_PATH . 'dom_xmlrpc_fault.php' );
$_LANG = mosFactory::getLanguage();
$_LANG->debug( $mosConfig_debug );
$xmlrpcServer =& new dom_xmlrpc_server();
$xmlrpcServer->setMethodNotFoundHandler( 'domXmlRpcFault' );
// authenticate xmlrpc client
// using basic auth method
// fore more information see http://www.ietf.org/rfc/rfc2617.txt
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="'.$mosConfig_sitename.' Realm"');
header('HTTP/1.0 401 Unauthorized');
exit;
}
if(!$mainframe->login($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW'])){
domXmlRpcAuthError($xmlrpcServer);
exit();
}
/** get the information about the current user from the sessions table */
$GLOBALS['my'] =& $mainframe->getUser();
// load all available remote calls
$_MAMBOTS->loadBotGroup( 'xmlrpc' );
$allCalls = $_MAMBOTS->trigger( 'onGetWebServices' );
// add all calls to the connector object
foreach ($allCalls as $calls) {
foreach ($calls as $call) {
$xmlrpcServer->addMethod( new dom_xmlrpc_method( $call ) );
}
}
// pass individual arguments to the called method
$xmlrpcServer->tokenizeParams( true );
// process the call
$xmlrpcServer->receive();
?>
Also I found 2 bugs in DOM XML-RPC for PHP :
in file php_http_client_generic.php
Code:
/**
* Sends data through the client connection
* @param string The message to be sent
* @return string The http response
*/
function &send($message) {
$conn =& $this->connection;
if ($conn->isOpen()) {
//build header info
$request = $this->requestMethod . ' ' . $this->requestPath . ' ' . $this->protocol .
'/' . $this->protocolVersion . CRLF;
$request .= $this->headers->toString() . CRLF;
$request .= $message;
//init variables
$response = $headers = $body = '';
$readState = HTTP_READ_STATE_BEGIN;
$this->fireEvent('onRequest', $request);
//send request
$connResource =& $conn->connection;
fputs ($connResource, $request);
//read response
$this->response->message ='';
$this->response->headers = '';
while (!feof($connResource)) {
$data = fgets($connResource, 4096);
$this->fireEvent('onRead', $data);
switch ($readState) {
case HTTP_READ_STATE_BEGIN:
$this->response->statusLine = $data;
$readState = HTTP_READ_STATE_HEADERS;
break;
case HTTP_READ_STATE_HEADERS:
if (trim($data) == '') { //end of headers is signalled by a blank line
$readState = HTTP_READ_STATE_BODY;
}
else {
if ($this->responseHeadersAsObject) {
$this->response->setUnformattedHeader($data);
}
else {
$this->response->headers .= $data;
}
}
break;
case HTTP_READ_STATE_BODY:
$this->response->message .= $data;
break;
}
}
$this->normalizeResponseIfChunked();
$headerString = is_object($this->response->headers) ?
$this->response->headers->toString() : $this->response->headers;
$this->fireEvent('onResponseHeaders', $headerString);
$this->fireEvent('onResponseBody', $this->response->message);
$this->fireEvent('onResponse', $this->response->headers . $this->response->message);
return $this->response;
}
else {
HTTPExceptions::raiseException(HTTP_SOCKET_CONNECTION_ERR, ('HTTP Transport Error - Unable to establish connection to host ' .
$conn->host));
}
} //send
and in file php_http_client_generic.php
Code:
/**
* Specifies a user name and password for basic authentication
* @param string The user name
* @param string The password
*/
function setAuthorization($user, $password) {
$encodedChallengeResponse = 'Basic ' . base64_encode($user . ':' . $password);
$this->setHeader('Authorization', $encodedChallengeResponse);
} //setAuthorization
} //php_http_request