You are here

class ServicesClientConnectionXmlrpcServer in Services Client 7

Same name and namespace in other branches
  1. 7.2 services_client_connection/plugins/ServicesClientConnectionXmlrpcServer.inc \ServicesClientConnectionXmlrpcServer

@file XMLRPC server

Hierarchy

Expanded class hierarchy of ServicesClientConnectionXmlrpcServer

1 string reference to 'ServicesClientConnectionXmlrpcServer'
_services_client_connection_server in services_client_connection/include/plugin_definition.inc
List of server plugins provided by module

File

services_client_connection/plugins/ServicesClientConnectionXmlrpcServer.inc, line 8
XMLRPC server

View source
class ServicesClientConnectionXmlrpcServer extends ServicesClientConnectionServer {

  /**
   * Include Drupal core XML-RPC library
   */
  private function includeXmlrpcLibrary() {
    require_once DRUPAL_ROOT . '/includes/xmlrpc.inc';
  }
  public function prepareRequest(ServicesClientConnectionHttpRequest &$request) {
    parent::prepareRequest($request);
    $this
      ->includeXmlrpcLibrary();

    // No special changes to URL
    $request->url = $this->connection->endpoint;

    // All xml-rpc calls are post
    $request->http_method = 'POST';
    $request->http_headers['Content-Type'] = 'text/xml';
    $method = $request->resource . '.' . $request->action;
    if ($request->id) {
      $data = $request->data;
      $request->data = array(
        'id' => $request->id,
      );
      if (!empty($data)) {
        $request->data += array(
          $data,
        );
      }
    }
    $xml_request = xmlrpc_request($method, $request->data);
    $request->data = $xml_request->xml;
  }
  public function processResponse(ServicesClientConnectionResponse &$response) {
    parent::processResponse($response);

    // Add library
    $this
      ->includeXmlrpcLibrary();

    // Try to retrieve error message
    $message = xmlrpc_message($response->raw_response);

    // Try to get error code from response
    if (ServicesClientConnectionHttp::isError($response->response_code)) {
      $response->error_code = $response->response_code;
      $response->error_message = ServicesClientConnectionHttp::getHttpMessage($response->response_code);
    }
    elseif (!empty($message) && !xmlrpc_message_parse($message)) {
      $response->error_code = -32700;
      $response->error_message = t('Parse error. Not well formed');
    }
    elseif ($message->messagetype == 'fault') {
      $response->error_code = $message->fault_code;
      $response->error_message = $message->fault_string;
    }
    else {
      $response->data = $message->params[0];
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ServicesClientConnectionPlugin::$client protected property Reference to client
ServicesClientConnectionPlugin::$config protected property Plugin specific configuration
ServicesClientConnectionPlugin::$connection protected property Connection definition
ServicesClientConnectionPlugin::configForm public function Configuration form options 5
ServicesClientConnectionPlugin::configFormSubmit public function 5
ServicesClientConnectionPlugin::configFormValidate public function 1
ServicesClientConnectionPlugin::__construct public function 1
ServicesClientConnectionXmlrpcServer::includeXmlrpcLibrary private function Include Drupal core XML-RPC library
ServicesClientConnectionXmlrpcServer::prepareRequest public function Allows module to alter data in process of request Overrides ServicesClientConnectionPlugin::prepareRequest
ServicesClientConnectionXmlrpcServer::processResponse public function Overrides ServicesClientConnectionPlugin::processResponse