From: Jan Schneider Date: Tue, 4 May 2010 10:19:32 +0000 (+0200) Subject: Throw Horde_Rpc_Exception. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=c5366388537acff22cc5f13944051923e30660f9;p=horde.git Throw Horde_Rpc_Exception. --- diff --git a/framework/Rpc/lib/Horde/Rpc.php b/framework/Rpc/lib/Horde/Rpc.php index 8fdc5dbae..f3c008f3e 100644 --- a/framework/Rpc/lib/Horde/Rpc.php +++ b/framework/Rpc/lib/Horde/Rpc.php @@ -205,17 +205,19 @@ class Horde_Rpc * * This statically called method is actually the RPC client. * - * @param string $driver The protocol driver to use. Currently 'soap', - * 'xmlrpc' and 'jsonrpc' are available. - * @param string $url The path to the RPC server on the called host. - * @param string $method The method to call. - * @param array $params A hash containing any necessary parameters for - * the method call. - * @param $options Associative array of parameters depending on - * the selected protocol driver. - * - * @return mixed The returned result from the method or a PEAR - * error object on failure. + * @param string $driver The protocol driver to use. Currently + * 'soap', 'xmlrpc' and 'jsonrpc' are + * available. + * @param string|Horde_Url $url The path to the RPC server on the called + * host. + * @param string $method The method to call. + * @param array $params A hash containing any necessary parameters + * for the method call. + * @param $options Associative array of parameters depending + * on the selected protocol driver. + * + * @return mixed The returned result from the method + * @throws Horde_Rpc_Exception */ public static function request($driver, $url, $method, $params = null, $options = array()) { diff --git a/framework/Rpc/lib/Horde/Rpc/Exception.php b/framework/Rpc/lib/Horde/Rpc/Exception.php index 17650ce22..d87fcfcfd 100644 --- a/framework/Rpc/lib/Horde/Rpc/Exception.php +++ b/framework/Rpc/lib/Horde/Rpc/Exception.php @@ -1,9 +1,16 @@ + * @category Horde + * @package Horde_Rpc */ -class Horde_Rpc_Exception extends Exception +class Horde_Rpc_Exception extends Horde_Exception_Prior { } diff --git a/framework/Rpc/lib/Horde/Rpc/Jsonrpc.php b/framework/Rpc/lib/Horde/Rpc/Jsonrpc.php index 3686981e7..da1522f79 100644 --- a/framework/Rpc/lib/Horde/Rpc/Jsonrpc.php +++ b/framework/Rpc/lib/Horde/Rpc/Jsonrpc.php @@ -136,27 +136,27 @@ class Horde_Rpc_Jsonrpc extends Horde_Rpc * * This statically called method is actually the JSON-RPC client. * - * @param string $url The path to the JSON-RPC server on the called - * host. - * @param string $method The method to call. - * @param array $params A hash containing any necessary parameters for - * the method call. + * @param string|Horde_Url $url The path to the JSON-RPC server on the + * called host. + * @param string $method The method to call. + * @param array $params A hash containing any necessary parameters + * for the method call. * @param $options Optional associative array of parameters which * can be: - * - user - Basic Auth username - * - pass - Basic Auth password - * - proxy_host - Proxy server host - * - proxy_port - Proxy server port - * - proxy_user - Proxy auth username - * - proxy_pass - Proxy auth password - * - timeout - Connection timeout in seconds. - * - allowRedirects - Whether to follow redirects or - * not - * - maxRedirects - Max number of redirects to - * follow + * - user: Basic Auth username + * - pass: Basic Auth password + * - proxy_host: Proxy server host + * - proxy_port: Proxy server port + * - proxy_user: Proxy auth username + * - proxy_pass: Proxy auth password + * - timeout: Connection timeout in seconds. + * - allowRedirects: Whether to follow redirects or + * not + * - maxRedirects: Max number of redirects to + * follow * - * @return mixed The returned result from the method or a PEAR_Error on - * failure. + * @return mixed The returned result from the method. + * @throws Horde_Rpc_Exception */ public static function request($url, $method, $params = null, $options = array()) { @@ -193,7 +193,7 @@ class Horde_Rpc_Jsonrpc extends Horde_Rpc $result = $http->sendRequest(); if (is_a($result, 'PEAR_Error')) { - return $result; + throw new Horde_Rpc_Exception($result); } elseif ($http->getResponseCode() == 500) { $response = Horde_Serialize::unserialize($http->getResponseBody(), Horde_Serialize::JSON); if (is_a($response, 'stdClass') && @@ -201,14 +201,17 @@ class Horde_Rpc_Jsonrpc extends Horde_Rpc is_a($response->error, 'stdClass') && isset($response->error->name) && $response->error->name == 'JSONRPCError') { + throw new Horde_Rpc_Exception($response->error->message); + /* @todo: Include more information if we have an Exception that can handle this. return PEAR::raiseError($response->error->message, $response->error->code, null, null, isset($response->error->error) ? $response->error->error : null); + */ } - return PEAR::raiseError($http->getResponseBody()); + throw new Horde_Rpc_Exception($http->getResponseBody()); } elseif ($http->getResponseCode() != 200) { - return PEAR::raiseError('Request couldn\'t be answered. Returned errorcode: "' . $http->getResponseCode(), 'horde.error'); + throw new Horde_Rpc_Exception($result'Request couldn\'t be answered. Returned errorcode: "' . $http->getResponseCode()); } return Horde_Serialize::unserialize($http->getResponseBody(), Horde_Serialize::JSON); diff --git a/framework/Rpc/lib/Horde/Rpc/Phpgw.php b/framework/Rpc/lib/Horde/Rpc/Phpgw.php index ac1bcc541..dc95b52cb 100644 --- a/framework/Rpc/lib/Horde/Rpc/Phpgw.php +++ b/framework/Rpc/lib/Horde/Rpc/Phpgw.php @@ -107,23 +107,24 @@ class Horde_Rpc_Phpgw extends Horde_Rpc * * This statically called method is actually the XMLRPC client. * - * @param string $url The path to the XMLRPC server on the called host. - * @param string $method The method to call. - * @param array $params A hash containing any necessary parameters for - * the method call. + * @param string|Horde_Url $url The path to the XMLRPC server on the + * called host. + * @param string $method The method to call. + * @param array $params A hash containing any necessary parameters + * for the method call. * @param $options Optional associative array of parameters which can be: - * user - Basic Auth username - * pass - Basic Auth password - * proxy_host - Proxy server host - * proxy_port - Proxy server port - * proxy_user - Proxy auth username - * proxy_pass - Proxy auth password - * timeout - Connection timeout in seconds. - * allowRedirects - Whether to follow redirects or not - * maxRedirects - Max number of redirects to follow + * - user: Basic Auth username + * - pass: Basic Auth password + * - proxy_host: Proxy server host + * - proxy_port: Proxy server port + * - proxy_user: Proxy auth username + * - proxy_pass: Proxy auth password + * - timeout: Connection timeout in seconds. + * - allowRedirects: Whether to follow redirects or not + * - maxRedirects: Max number of redirects to follow * - * @return mixed The returned result from the method or a PEAR - * error object on failure. + * @return mixed The returned result from the method. + * @throws Horde_Rpc_Exception */ public static function request($url, $method, $params = null, $options = array()) { @@ -152,18 +153,18 @@ class Horde_Rpc_Phpgw extends Horde_Rpc $result = $http->sendRequest(); if (is_a($result, 'PEAR_Error')) { - return $result; + throw new Horde_Rpc_Exception($result); } elseif ($http->getResponseCode() != 200) { - return PEAR::raiseError(_("Request couldn't be answered. Returned errorcode: ") . $http->getResponseCode(), 'horde.error'); + throw new Horde_Rpc_Exception(_("Request couldn't be answered. Returned errorcode: ") . $http->getResponseCode()); } elseif (strpos($http->getResponseBody(), 'getResponseBody()); + throw new Horde_Rpc_Exception(_("No valid XML data returned:\n") . $http->getResponseBody()); } else { $response = @xmlrpc_decode(substr($http->getResponseBody(), strpos($http->getResponseBody(), '__soapCall($method, $params); + $options['exceptions'] = true; + + $options['trace'] = true; + try { + $soap = new SoapClient(null, $options); + return $soap->__soapCall($method, $params); + } catch (Exception $e) { + throw new Horde_Rpc_Exception($e); + } } } diff --git a/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php b/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php index fe4a0fe37..ff57e9f3b 100644 --- a/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php +++ b/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php @@ -85,23 +85,24 @@ class Horde_Rpc_Xmlrpc extends Horde_Rpc * * This statically called method is actually the XMLRPC client. * - * @param string $url The path to the XMLRPC server on the called host. - * @param string $method The method to call. - * @param array $params A hash containing any necessary parameters for - * the method call. + * @param string|Horde_Url $url The path to the XMLRPC server on the + * called host. + * @param string $method The method to call. + * @param array $params A hash containing any necessary parameters + * for the method call. * @param $options Optional associative array of parameters which can be: - * user - Basic Auth username - * pass - Basic Auth password - * proxy_host - Proxy server host - * proxy_port - Proxy server port - * proxy_user - Proxy auth username - * proxy_pass - Proxy auth password - * timeout - Connection timeout in seconds. - * allowRedirects - Whether to follow redirects or not - * maxRedirects - Max number of redirects to follow + * - user: Basic Auth username + * - pass: Basic Auth password + * - proxy_host: Proxy server host + * - proxy_port: Proxy server port + * - proxy_user: Proxy auth username + * - proxy_pass: Proxy auth password + * - timeout: Connection timeout in seconds + * - allowRedirects: Whether to follow redirects or not + * - maxRedirects: Max number of redirects to follow * - * @return mixed The returned result from the method or a PEAR - * error object on failure. + * @return mixed The returned result from the method. + * @throws Horde_Rpc_Exception */ public static function request($url, $method, $params = null, $options = array()) { @@ -131,18 +132,18 @@ class Horde_Rpc_Xmlrpc extends Horde_Rpc $result = $http->sendRequest(); if (is_a($result, 'PEAR_Error')) { - return $result; + throw new Horde_Rpc_Exception($result); } elseif ($http->getResponseCode() != 200) { - return PEAR::raiseError('Request couldn\'t be answered. Returned errorcode: "' . $http->getResponseCode(), 'horde.error'); + throw new Horde_Rpc_Exception('Request couldn\'t be answered. Returned errorcode: "' . $http->getResponseCode()); } elseif (strpos($http->getResponseBody(), 'getResponseBody()); + throw new Horde_Rpc_Exception("No valid XML data returned:\n" . $http->getResponseBody()); } else { $response = @xmlrpc_decode(substr($http->getResponseBody(), strpos($http->getResponseBody(), '