summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
Diffstat (limited to 'framework')
-rw-r--r--framework/Web/Services/TRpcService.php24
1 files changed, 17 insertions, 7 deletions
diff --git a/framework/Web/Services/TRpcService.php b/framework/Web/Services/TRpcService.php
index 5f3a0b7e..1b52c06b 100644
--- a/framework/Web/Services/TRpcService.php
+++ b/framework/Web/Services/TRpcService.php
@@ -71,10 +71,8 @@ class TRpcService extends TService
if(($_rpcServerClass = $_properties->remove('server')) === null)
$_rpcServerClass = self::BASE_RPC_SERVER;
- prado::using($_rpcServerClass);
-
$_rpcServerClassName = ($_pos = strrpos($_rpcServerClass, '.')) !== false ? substr($_rpcServerClass, $_pos + 1) : $_rpcServerClass;
- if(!is_subclass_of($_rpcServerClassName, self::BASE_RPC_SERVER))
+ if($_rpcServerClassName!==self::BASE_RPC_SERVER && !is_subclass_of($_rpcServerClassName, self::BASE_RPC_SERVER))
throw new TConfigurationException('rpcservice_rpcserver_invalid');
$_apiProvider = new $_providerClassName(new $_rpcServerClassName($protocolHandler));
@@ -311,6 +309,8 @@ abstract class TRpcProtocol
if(!isset($this->rpcMethods[$methodName]))
throw new TRpcException('Method "'.$methodName.'" not found');
+ if(!is_array($parameters))
+ throw new TRpcException('Invalid parameters');
return call_user_func_array($this->rpcMethods[$methodName]['method'], $parameters);
}
}
@@ -328,7 +328,7 @@ abstract class TRpcProtocol
class TJsonRpcProtocol extends TRpcProtocol
{
// methods
-
+ protected $_id=0;
/**
* Handles the RPC request
* @param string $requestPayload
@@ -337,10 +337,14 @@ class TJsonRpcProtocol extends TRpcProtocol
public function callMethod($requestPayload)
{
$_request = $this->decode($requestPayload);
-
try
{
+ if(!isset($_request['id']))
+ throw new TRpcException('Missing mandatory request id');
+
+ $this->_id=$_request['id'];
return $this->encode(array(
+ 'id' => $this->_id,
'result' => $this->callApiMethod($_request['method'], $_request['params']),
'error' => null
));
@@ -355,6 +359,7 @@ class TJsonRpcProtocol extends TRpcProtocol
}
catch(Exception $e)
{
+ error_log(Prado::varDump($e));
return $this->createErrorResponse(new TRpcException('An internal error occured'));
}
}
@@ -367,8 +372,13 @@ class TJsonRpcProtocol extends TRpcProtocol
public function createErrorResponse(TRpcException $exception)
{
return $this->encode(array(
- 'faultCode' => $exception->getCode(),
- 'faultString' => $exception->getMessage()
+ 'id' => $this->_id,
+ 'result' => null,
+ 'error'=> array(
+ 'code' => $exception->getCode(),
+ 'message'=> $exception->getMessage(),
+ 'data' => null,
+ )
));
}