summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorctrlaltca <>2012-08-29 09:31:36 +0000
committerctrlaltca <>2012-08-29 09:31:36 +0000
commitf4890e8916741e5c7b3472a7803d9a9c9d02f721 (patch)
tree51032d5b08fb87cce40f9d39fc63e5857e78173f /framework/Web
parente0706ed1eab90fe9f08a6f9f0ad36e61fb7c2d86 (diff)
tweaked TJsonRpcService enough to make it conform to the old (version 1) standard
Diffstat (limited to 'framework/Web')
-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,
+ )
));
}