Ejemplo n.º 1
0
 public function __construct($addr = "127.0.0.1", $port = 8080)
 {
     $this->port = $port;
     $this->addr = $addr;
     // Setup basic stuff
     error_reporting(E_ALL & ~E_NOTICE);
     $base = realpath(dirname(__FILE__) . '/../');
     $paths = array('.', realpath($base . '/library'), get_include_path());
     $this->base = $base;
     // Setup autoloading ...
     set_include_path(implode(PATH_SEPARATOR, $paths));
     require_once 'Zend/Loader/Autoloader.php';
     $autoloader = Zend_Loader_Autoloader::getInstance();
     $autoloader->registerNamespace('EvHttp_');
     $resourceLoader = new Zend_Loader_Autoloader_Resource(array('basePath' => realpath($base . '/application'), 'namespace' => '', 'resourceTypes' => array('model' => array('namespace' => 'Model', 'path' => 'models/'), 'api' => array('namespace' => 'Service', 'path' => 'apis/'))));
     // Load config
     $this->config = new Zend_Config_Ini($this->base . '/deploy/config.ini', 'default');
     Zend_Registry::set('config', $this->config);
     // Connect database
     $dbType = $this->config->database->type;
     $params = $this->config->database->toArray();
     $db = Zend_Db::factory($dbType, $params);
     Zend_Db_Table::setDefaultAdapter($db);
     Zend_Registry::set('db', $db);
     // Setup Xml-Rpc Server
     $this->xmlrpc_server = new Zend_XmlRpc_Server();
     $this->xmlrpc_server->setClass('Service_Poll', 'poll');
     Zend_XmlRpc_Server_Fault::attachFaultException('Exception');
     // Setup Json-Rpc Server
     $this->jsonrpc_server = new Zend_Json_Server();
     $this->jsonrpc_server->setClass('Service_Poll', 'poll')->setAutoEmitResponse(false)->setTarget('/jsonrpc')->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
 }
Ejemplo n.º 2
0
 /**
  * ping method for pingback xmlrpc server
  *
  * @param string $sourceURI The absolute URI of the post on the source page containing the link to the target site.
  * @param string $targetURI The absolute URI of the target of the link, as given on the source page.
  * @throws Zend_XmlRpc_Server_Fault on caugth exceptions
  * @return string on success
  */
 public static function ping($sourceURI, $targetURI)
 {
     $pb = new PingBack($sourceURI, $targetURI);
     Zend_XmlRpc_Server_Fault::attachFaultException("PingBackException");
     $ret = $pb->pong();
     // do something
     return "OK";
 }
Ejemplo n.º 3
0
 public function xmlrpcServerAction()
 {
     Zend_XmlRpc_Server_Fault::attachFaultException('Exception');
     $server = new Zend_XmlRpc_Server();
     $server->setClass('MyProject_BL_Member', 'member');
     header('Content-Type: text/xml');
     echo $server->handle();
     exit(0);
 }
Ejemplo n.º 4
0
 /**
  * Set up zend service class
  * @return void
  */
 protected function init_zend_server() {
     parent::init_zend_server();
     // this exception indicates request failed
     Zend_XmlRpc_Server_Fault::attachFaultException('moodle_exception');
     //when DEBUG >= NORMAL then the thrown exceptions are "casted" into a plain PHP Exception class
     //in order to display the $debuginfo (see moodle_zend_xmlrpc_server class - MDL-29435)
     if (debugging()) {
         Zend_XmlRpc_Server_Fault::attachFaultException('Exception');
     }
 }
Ejemplo n.º 5
0
 public function fault($fault = null, $code = 404)
 {
     if (!$fault instanceof Exception) {
         $fault = (string) $fault;
         if (empty($fault)) {
             $fault = 'Unknown Error';
         }
         // require_once 'Zend/XmlRpc/Server/Exception.php';
         $fault = new Zend_XmlRpc_Server_Exception($fault, $code);
     }
     return Zend_XmlRpc_Server_Fault::getInstance($fault);
 }
Ejemplo n.º 6
0
 public function xmlrpcServerAction()
 {
     // disable layout and view
     $this->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     // set output format
     header('Content-Type: text/xml');
     // handle server request
     Zend_XmlRpc_Server_Fault::attachFaultException('Exception');
     $server = new Zend_XmlRpc_Server();
     $server->setClass('MyProject_Service_XmlRpc_Example', 'example');
     $response = $server->handle();
     // display response
     echo $response;
     exit(0);
 }
Ejemplo n.º 7
0
 public function run()
 {
     $enable = $this->get_enable();
     if (empty($enable)) {
         die;
     }
     include "Zend/Loader.php";
     Zend_Loader::registerAutoload();
     Zend_XmlRpc_Server_Fault::attachFaultException('moodle_exception');
     // retrieve the token from the url
     // if the token doesn't exist, set a class containing only get_token()
     $token = optional_param('token', null, PARAM_ALPHANUM);
     if (empty($token)) {
         $server = new Zend_XmlRpc_Server();
         $server->setClass("ws_authentication", "authentication");
         echo $server->handle();
     } else {
         // if token exist, do the authentication here
         /// TODO: following function will need to be modified
         $user = webservice_lib::mock_check_token($token);
         if (empty($user)) {
             throw new moodle_exception('wrongidentification');
         } else {
             /// TODO: probably change this
             global $USER;
             $USER = $user;
         }
         //retrieve the api name
         $classpath = optional_param(classpath, null, PARAM_ALPHA);
         require_once dirname(__FILE__) . '/../../' . $classpath . '/external.php';
         /// run the server
         $server = new Zend_XmlRpc_Server();
         $server->setClass($classpath . "_external", $classpath);
         echo $server->handle();
     }
 }
Ejemplo n.º 8
0
 /**
  * __toString() test
  */
 public function test__toString()
 {
     $dom = new DOMDocument('1.0', 'UTF-8');
     $r = $dom->appendChild($dom->createElement('methodResponse'));
     $f = $r->appendChild($dom->createElement('fault'));
     $v = $f->appendChild($dom->createElement('value'));
     $s = $v->appendChild($dom->createElement('struct'));
     $m1 = $s->appendChild($dom->createElement('member'));
     $m1->appendChild($dom->createElement('name', 'faultCode'));
     $cv = $m1->appendChild($dom->createElement('value'));
     $cv->appendChild($dom->createElement('int', 411));
     $m2 = $s->appendChild($dom->createElement('member'));
     $m2->appendChild($dom->createElement('name', 'faultString'));
     $sv = $m2->appendChild($dom->createElement('value'));
     $sv->appendChild($dom->createElement('string', 'Testing fault'));
     $xml = $dom->saveXML();
     // require_once 'Zend/XmlRpc/Server/Exception.php';
     $e = new Zend_XmlRpc_Server_Exception('Testing fault', 411);
     $fault = Zend_XmlRpc_Server_Fault::getInstance($e);
     $this->assertEquals(trim($xml), trim($fault->__toString()));
 }
Ejemplo n.º 9
0
 /**
  * Set up zend service class
  * @return void
  */
 protected function init_zend_server()
 {
     parent::init_zend_server();
     // this exception indicates request failed
     Zend_XmlRpc_Server_Fault::attachFaultException('moodle_exception');
 }
Ejemplo n.º 10
0
 /**
  * Raise an xmlrpc server fault
  * 
  * @param string|Exception $fault 
  * @param int $code 
  * @return Zend_XmlRpc_Server_Fault
  */
 public function fault($fault, $code = 404)
 {
     if (!$fault instanceof Exception) {
         $fault = (string) $fault;
         $fault = new Zend_XmlRpc_Server_Exception($fault, $code);
     }
     return Zend_XmlRpc_Server_Fault::getInstance($fault);
 }
Ejemplo n.º 11
0
 * Force the cache manager because for some reason it ends up empty without
 * setting the manager manually
 */
$cache = Zend_Controller_Action_HelperBroker::getStaticHelper('Cache');
$cache->setManager($application->getBootstrap()->getResource('cachemanager'));
switch ($_GET['format']) {
    case 'json':
        $server = new Zend_Json_Server();
        // Indicate the URL endpoint, and the JSON-RPC version used:
        $server->setTarget('/api/jsonrpc/')->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
        $contentTypeHeader = 'Content-Type: text/json';
        break;
    case 'xml':
        $server = new Zend_XmlRpc_Server();
        Zend_XmlRpc_Server_Fault::attachFaultException('FFR_Exception');
        Zend_XmlRpc_Server_Fault::attachFaultException('Zend_Exception');
        $contentTypeHeader = 'Content-Type: text/xml';
        break;
}
$apiList = Zym_Message_Dispatcher::get()->post('buildApi')->getResult('buildApi');
foreach ($apiList as $key => $services) {
    foreach ($services as $service => $class) {
        $server->setClass($class, $service);
    }
}
if ('GET' == $_SERVER['REQUEST_METHOD'] && $_GET['format'] == 'json') {
    // Grab the SMD
    $smd = $server->getServiceMap();
    // Return the SMD to the client
    header($contentTypeHeader);
    echo $smd;
Ejemplo n.º 12
0
 /**
  * Raise an xmlrpc server fault
  *
  * @param string|Exception $fault
  * @param int $code
  * @return Zend_XmlRpc_Server_Fault
  */
 public function fault($fault = null, $code = 404)
 {
     if (!$fault instanceof Exception) {
         $fault = (string) $fault;
         if (empty($fault)) {
             $fault = 'Unknown error';
         }
         $fault = new Zend_XmlRpc_Server_Exception($fault, $code);
     }
     return Zend_XmlRpc_Server_Fault::getInstance($fault);
 }
Ejemplo n.º 13
0
#!/usr/bin/env php
<?php 
chdir(dirname(__FILE__));
require_once '../php/setup.php';
// map errors to exceptions
function errorHandler($errno, $errstr, $errfile, $errline)
{
    if (error_reporting()) {
        throw new Exception($errstr);
        // internal error not to be mapped to fault
    }
    return true;
}
error_reporting(E_ALL & ~E_NOTICE);
set_error_handler('errorHandler', E_ALL & ~E_NOTICE);
// construct facade objects
$server = new Zend_XmlRpc_Server();
$server->setClass(new Wikidot_Facade_User(), 'user');
$server->setClass(new Wikidot_Facade_Site(), 'site');
$server->setClass(new Wikidot_Facade_Page(), 'page');
$server->setClass(new Wikidot_Facade_Forum(), 'forum');
Zend_XmlRpc_Server_Cache::save('/tmp/xmlrpcapi.cache', $server);
// map Wikidot_Facade_Exception to XML-RPC faults
Zend_XmlRpc_Server_Fault::attachFaultException('Wikidot_Facade_Exception');
Zend_XmlRpc_Server_Fault::attachFaultException('WDPermissionException');
// run XML-RPC server
echo $server->handle(new Zend_XmlRpc_Request_Stdin());
Ejemplo n.º 14
0
 /**
  * Set up zend service class - mainly about fault handling
  *
  * @return void
  */
 protected function init_zend_server()
 {
     parent::init_zend_server();
     // this exception indicates request failed
     Zend_XmlRpc_Server_Fault::attachFaultException('WebserviceException');
     Zend_XmlRpc_Server_Fault::attachFaultException('MaharaException');
     Zend_XmlRpc_Server_Fault::attachFaultException('UserException');
     Zend_XmlRpc_Server_Fault::attachFaultException('NotFoundException');
     Zend_XmlRpc_Server_Fault::attachFaultException('SystemException');
     Zend_XmlRpc_Server_Fault::attachFaultException('InvalidArgumentException');
     Zend_XmlRpc_Server_Fault::attachFaultException('AccessDeniedException');
     Zend_XmlRpc_Server_Fault::attachFaultException('ParameterException');
     Zend_XmlRpc_Server_Fault::attachFaultException('WebserviceParameterException');
     Zend_XmlRpc_Server_Fault::attachFaultException('WebserviceInvalidParameterException');
     Zend_XmlRpc_Server_Fault::attachFaultException('WebserviceInvalidResponseException');
     if (ws_debugging()) {
         Zend_XmlRpc_Server_Fault::attachFaultException('Exception');
     }
 }