*
* 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())
{
<?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
{
}
*
* 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())
{
$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') &&
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);
*
* 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())
{
$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;
}
*
* 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())
{
}
$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);
+ }
}
}
*
* 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())
{
$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;
}