Throw Horde_Rpc_Exception.
authorJan Schneider <jan@horde.org>
Tue, 4 May 2010 10:19:32 +0000 (12:19 +0200)
committerJan Schneider <jan@horde.org>
Tue, 4 May 2010 10:21:07 +0000 (12:21 +0200)
framework/Rpc/lib/Horde/Rpc.php
framework/Rpc/lib/Horde/Rpc/Exception.php
framework/Rpc/lib/Horde/Rpc/Jsonrpc.php
framework/Rpc/lib/Horde/Rpc/Phpgw.php
framework/Rpc/lib/Horde/Rpc/Soap.php
framework/Rpc/lib/Horde/Rpc/Xmlrpc.php

index 8fdc5db..f3c008f 100644 (file)
@@ -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())
     {
index 17650ce..d87fcfc 100644 (file)
@@ -1,9 +1,16 @@
 <?php
 /**
+ * Exception handler for the Horde_Rpc library.
  *
- * @package Horde_Rpc
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
  *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author   Jan Schneider <jan@horde.org>
+ * @category Horde
+ * @package  Horde_Rpc
  */
-class Horde_Rpc_Exception extends Exception
+class Horde_Rpc_Exception extends Horde_Exception_Prior
 {
 }
index 3686981..da1522f 100644 (file)
@@ -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);
index ac1bcc5..dc95b52 100644 (file)
@@ -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(), '<?xml') === false) {
-            return PEAR::raiseError(_("No valid XML data returned"), 'horde.error', null, null, $http->getResponseBody());
+            throw new Horde_Rpc_Exception(_("No valid XML data returned:\n") . $http->getResponseBody());
         } else {
             $response = @xmlrpc_decode(substr($http->getResponseBody(), strpos($http->getResponseBody(), '<?xml')));
             if (is_array($response) && isset($response['faultString'])) {
-                return PEAR::raiseError($response['faultString'], 'horde.error');
+                throw new Horde_Rpc_Exception($response['faultString']);
             } elseif (is_array($response) && isset($response[0]) &&
                       is_array($response[0]) && isset($response[0]['faultString'])) {
-                return PEAR::raiseError($response[0]['faultString'], 'horde.error');
+                throw new Horde_Rpc_Exception($response[0]['faultString']);
             }
             return $response;
         }
index 7aed022..05429c6 100644 (file)
@@ -103,31 +103,32 @@ class Horde_Rpc_Soap extends Horde_Rpc
      *
      * This statically called method is actually the SOAP client.
      *
-     * @param string $url     The path to the SOAP 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 SOAP 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
-     *                  namespace
-     *                  soapaction
-     *                  from                - SMTP, from address
-     *                  transfer-encoding   - SMTP, sets the
-     *                                        Content-Transfer-Encoding header
-     *                  subject             - SMTP, subject header
-     *                  headers             - SMTP, array-hash of extra smtp
-     *                                        headers
+     *                  - 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
+     *                  - namespace:
+     *                  - soapaction:
+     *                  - from:              SMTP, from address
+     *                  - transfer-encoding: SMTP, sets the
+     *                                       Content-Transfer-Encoding header
+     *                  - subject:           SMTP, subject header
+     *                  - headers:           SMTP, array-hash of extra smtp
+     *                                       headers
      *
-     * @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())
     {
@@ -148,9 +149,15 @@ class Horde_Rpc_Soap extends Horde_Rpc
         }
         $options['location'] = (string)$url;
         $options['uri'] = $options['namespace'];
-
-        $soap = new SoapClient(null, $options);
-        return $soap->__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);
+        }
     }
 
 }
index fe4a0fe..ff57e9f 100644 (file)
@@ -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(), '<?xml') === false) {
-            return PEAR::raiseError('No valid XML data returned', 'horde.error', null, null, $http->getResponseBody());
+            throw new Horde_Rpc_Exception("No valid XML data returned:\n" . $http->getResponseBody());
         } else {
             $response = @xmlrpc_decode(substr($http->getResponseBody(), strpos($http->getResponseBody(), '<?xml')));
             if (is_array($response) && isset($response['faultString'])) {
-                return PEAR::raiseError($response['faultString'], 'horde.error');
+                throw new Horde_Rpc_Exception($response['faultString']);
             } elseif (is_array($response) && isset($response[0]) &&
                       is_array($response[0]) && isset($response[0]['faultString'])) {
-                return PEAR::raiseError($response[0]['faultString'], 'horde.error');
+                throw new Horde_Rpc_Exception($response[0]['faultString']);
             }
             return $response;
         }