Changeset 487

Show
Ignore:
Timestamp:
04/12/07 23:08:36 (2 years ago)
Author:
schst
Message:

Catch some errors, do not validate the id

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/websites/processors/stubJsonRpcProcessor.php

    r486 r487  
    2222 * @todo        Make methods testable 
    2323 * @todo        Check for annotations 
     24 * @todo        Do not validate the RAW POST Data using a regexp, as json_decode does enough validation 
    2425 */ 
    2526class stubJsonRpcProcessor extends stubAbstractProcessor { 
     
    4344     * Regexp to validate json param 
    4445     */ 
    45     const JSON_PATTERN = '^{\"method\":\"(.*)\",\"params\"(.*),\"id\":\"\d{6,7}\"}$'; 
    46  
    47     /** 
    48      * The JSON response 
    49      * 
    50      * @var array 
    51      */ 
    52     protected $jsonRpcResponse = array ( 
    53                                     'id'      => null, 
    54                                     'result'  => null, 
    55                                     'error'   => null, 
    56                                 ); 
    57  
     46    const JSON_PATTERN = '^{\"method\":\"(.*)\",\"params\"(.*),\"id\":\"\d{1,10}\"}$'; 
    5847 
    5948    /** 
     
    111100 
    112101        try { 
    113             $this->checkRequestId($phpJsonObj->id); 
    114102            $result = $this->invokeServiceMethod($phpJsonObj->method, $phpJsonObj->params); 
    115103            $this->sendResponse($phpJsonObj->id, $result); 
     
    137125 
    138126        $method = $clazz->getMethod($methodName); 
     127        if ($method == null) { 
     128            throw new stubException('Unknown method ' . $className . '.' . $methodName . '.'); 
     129        } 
    139130        if ($method->getNumberOfRequiredParameters() > count($params)) { 
    140131            throw new stubException('Invalid amount of parameters passed.'); 
     
    165156 
    166157            $params = $this->retrieveGETParams($classAndMethod); 
    167  
    168             $this->checkRequestId($requestId); 
    169158            $result = $this->invokeServiceMethod($classAndMethod, $params); 
    170159            $this->sendResponse($requestId, $result); 
     
    216205        } 
    217206        return $paramValues; 
    218     } 
    219  
    220     protected function checkRequestId($id) { 
    221         if (!isset($id)) { 
    222             $this->setError('id has to have 6-7 digits'); 
    223         } 
    224207    } 
    225208