Quick links: Content - sections - sub sections
EN FR

Trace: rights2 restfull 1.2 1.3 responses debugging templates responseajax jelix-scripts responsexmlrpc

Wiki: Sitemap - Recent changes - Back link

Jelix 1.3.1

Section: XML-RPC

« JSON-RPC ^ Web services SOAP »
Switch to language:FR

Jelix supports xml-rpc. this a protocol specified for data exchange in XML format.A client send a request containing XML content, an action to execute and parameters. Server executes action indicated with its parameters and send back an XML result.

RPC = remote procedure call

Entry point

An XML-RPC request cannot be treated as a classic request, thus you can't use "classic" request object. You have to create a specific entry point in www/ directory, xmlrpc.php. This entry point will instantiate a jXmlRpcRequest instead of a jClassicRequest.

The new entry point should look like:

require_once ('../../myapp/application.init.php');
 
$config_file = 'xmlrpc/config.ini.php';
 
require_once (JELIX_LIB_CORE_PATH.'request/jXmlRpcRequest.class.php');
 
$jelix = new jCoordinator($config_file);
$jelix->process(new jXmlRpcRequest());

Don't forget to add this entry point in urls engine configuration section. If you have selected simple url engine, in section simple_urlengine_entrypoints configuration file, just add:

xmlrpc = "@xmlrpc"

xmlrpc is the entry point name and @xmlrpc is the entry point request type.

If you have selected significant url engine, just add :

<entrypoint type="jsonrpc" name="xmlrpc " default="true" />

Independently of url engines, you retrieve an url for a xmlrpc action like this:

  $url = jUrl::get("module~action@xmlrpc ");

Controller

As XML-RPC is a specific request type, a controller filename must be suffixed by ”.xmlrpc.php”. A “default” controller file would be: “default.xmlrpc.php”. (it can co-exists with a “default” classic controller such as “default.classic.php”).

Controller content is similar to those of a classic controller. You just have to use a jResponseXmlRpc response (alias:“xmlrpc”):

class defaultCtrl extends jController {
 
  function index(){
 
    $resp = $this->getResponse('xmlrpc');
 
    // any data types : integer, string, array, objects...
    $data_php = ... ;
 
    $resp->response = $data_php;
 
    return $resp;
 
  }
}

Client request

To send a XML-RPC request, as specified in xml-rpc spec, you have to use a specific XML string:

<?xml version="1.0" ?>
<methodCall>
   <methodName>module:default:index</methodName>
  <params>
     <param><string>Allo ?</string></param>
  </params>
</methodCall>

methodName parameter indicates which action to execute. In a Jelix application, it must be an action selector:

method:"myModule:default:index"

Note: ”~” can not be used as separator between module name and action name. It must be replaced by ”:” (tilde character is not permitted in XML-RPC method name). As a result, it is mandatory to indicate in the selector: a module, a controller and an action.

To retrieve received parameters, you will do:

  $parameters = $this->param('params');

Of course, $parameters will contain “php” data. The XML string is automatically decoded by jXmlRpcRequest.

en/manual-1.3/responsexmlrpc.txt · Last modified: 2011/04/23 10:34 (external edit)
Recent changes RSS feed Creative Commons License