Changeset 504

Show
Ignore:
Timestamp:
04/14/07 00:22:52 (1 year ago)
Author:
schst
Message:

Added config file for JSON-RPC services, added second JSON-RPC example

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docroot/jsonrpclab/testBuddyQuoteService.php

    r499 r504  
    2020 
    2121var bq = new BuddyQuoteService(callbackObj); 
     22 
     23var MathCallbackObj = { 
     24  callback__add: function(id, result, error) { 
     25    alert(result); 
     26  } 
     27}; 
     28var math = new MathService(MathCallbackObj); 
    2229</script> 
    2330 
     
    2936</fieldset> 
    3037 
     38<fieldset> 
     39  <legend>Second JSON-RPC example</legend> 
     40  A: <input type="text" id="a" size="3"/> B: <input type="text" id="b" size="3"/><br/> 
     41  <input type="button" onclick="math.add(document.getElementById('a').value, document.getElementById('b').value);" value="A+B"/> 
     42</fieldset> 
    3143 
    3244</head> 
  • trunk/src/main/php/net/stubbles/websites/processors/stubJsonRpcProcessor.php

    r499 r504  
    4444     * 
    4545     * @var array 
    46      * @todo read this from a configuration file 
    47      */ 
    48     protected $classMap = array( 
    49                             'BuddyQuoteService' => '_test.BuddyQuoteService' 
    50                           ); 
     46     */ 
     47    protected $classMap = array(); 
    5148 
    5249    /** 
     
    7269     */ 
    7370    public function doProcess() { 
     71 
     72        $xjconf = new stubXJConfFacade(array('__default' => stubXJConfLoader::getInstance())); 
     73        $xjconf->parseAndAddDefinitions(stubFactory::getResourceURIs('xjconf/json-rpc-service.xml')); 
     74        $configFile = stubConfig::getConfigPath() . '/xml/json-rpc-service.xml'; 
     75        $xjconf->parse($configFile); 
     76        $this->classMap = $xjconf->getConfigValue('services'); 
    7477 
    7578        if ($this->request->hasValue('__generateProxy', stubRequest::SOURCE_PARAM)) { 
     
    9295        stubClassLoader::load('net.stubbles.service.jsonrpc.util.stubJsonRpcProxyGenerator'); 
    9396        $jsCode = ''; 
    94         foreach ($this->classMap as $jsClass => $fqClass) { 
    95             $jsCode = stubJsonRpcProxyGenerator::generateJavascriptProxy($fqClass, $jsClass, $jsCode); 
     97        foreach ($this->classMap as $jsClass => $serviceConfig) { 
     98            $jsCode = stubJsonRpcProxyGenerator::generateJavascriptProxy($serviceConfig['className'], $jsClass, $jsCode); 
    9699        } 
    97100        $this->response->write($jsCode); 
     
    194197            throw new Exception('Unknown class ' . $class . '.'); 
    195198        } 
    196         $fqClass = $this->classMap[$class]
     199        $fqClass = $this->classMap[$class]['className']
    197200        $classObj = new stubReflectionClass($fqClass); 
    198201        return $classObj;