Changeset 921

Show
Ignore:
Timestamp:
09/16/07 14:31:26 (10 months ago)
Author:
schst
Message:

Implement enhancement #59: Generation of SMD for JSON-RPC services

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/docroot/json-rpc/index.php

    r866 r921  
    8484  A: <input type="text" id="a" size="3"/> B: <input type="text" id="b" size="3"/><br/> 
    8585  <input type="button" onclick="math.add(document.getElementById('a').value, document.getElementById('b').value);" value="A+B"/> 
     86  <p> 
     87   SMD for this service:<br/> 
     88   <iframe height="50" width="100%" src="<?php echo dirname($_SERVER['PHP_SELF']);?>/jsonrpc.php?processor=jsonrpc&__smd=MathService"></iframe> 
     89  </p> 
    8690</fieldset> 
    8791 
     
    96100  <input type="button" onclick="nameServ.getName();" value="Get Name"/> 
    97101  <input type="button" onclick="nameServ.setName(document.getElementById('name').value);" value="Set Name"/> 
     102  <p> 
     103   SMD for this service:<br/> 
     104   <iframe height="50" width="100%" src="<?php echo dirname($_SERVER['PHP_SELF']);?>/jsonrpc.php?processor=jsonrpc&__smd=NameService"></iframe> 
     105  </p> 
    98106</fieldset> 
    99107 
  • trunk/src/main/php/net/stubbles/service/jsonrpc/stubJsonRpcProcessor.php

    r888 r921  
    8686                $this->generateProxies(explode(',', $classes)); 
    8787            } 
     88        } elseif ($this->request->hasValue('__smd')) { 
     89            $smdClassvalidator = new stubRegexValidator('^[A-Za-z0-9_\.]+$'); 
     90            $class = $this->request->getValidatedValue($smdClassvalidator, '__smd', stubRequest::SOURCE_PARAM); 
     91            $this->generateSmd($class); 
     92        } elseif ($this->request->getMethod() === 'post') { 
    8893        } elseif ($this->request->getMethod() === 'post') { 
    8994            $this->processPostRequest(); 
     
    172177        } 
    173178    } 
     179 
     180    /** 
     181     * Generate and send SMD for the specified class 
     182     * 
     183     * @param  string  $class 
     184     */ 
     185    public function generateSmd($class) 
     186    { 
     187        stubClassLoader::load('net.stubbles.service.jsonrpc.util.stubSmdGenerator'); 
     188        $tmp        = parse_url($this->request->getURI()); 
     189        $serviceUrl = '//' . $tmp['path']; 
     190        if ($this->request->hasValue('processor')) { 
     191            $processor   = $this->request->getValidatedValue(new stubPassThruValidator(), 'processor', stubRequest::SOURCE_PARAM); 
     192            $serviceUrl .= '?processor='.$processor; 
     193        } 
     194 
     195        $generator = new stubSmdGenerator($serviceUrl); 
     196        try { 
     197            $classInfo = $this->classMap[$class]; 
     198            $this->response->write($generator->generateSmd($classInfo['className'], $class)); 
     199        } catch (Exception $e) { 
     200            if ($this->serviceConfig['use-firebug'] === true) { 
     201                $this->response->write("console.error('Generation of SMD for {$serviceConfig['className']} failed.');\n"); 
     202                $this->response->write($this->convertStringToFirebug($e->__toString())); 
     203            } 
     204        } 
     205    } 
     206 
    174207 
    175208    /** 
     
    301334            throw new stubException('Invalid amount of parameters passed.'); 
    302335        } 
    303          
     336 
    304337        $binder = stubRegistry::get('net.stubbles.ioc.stubBinder'); 
    305338        if (($binder instanceof stubBinder) === false) { 
    306339            throw new stubRuntimeException('No instance of net.stubbles.ioc.stubBinder in registry.'); 
    307340        } 
    308          
     341 
    309342        $instance = $binder->getInjector()->getInstance($class->getName()); 
    310343        return $method->invokeArgs($instance, $params);