Permalink
Browse files

MDL-29435 SOAP/XMLRPC server return debuginfo into the exception mess…

…age when DEBUG >= NORMAL
  • Loading branch information...
1 parent 228d24f commit 2c28fa7643b168006883a81a2421012d357a22d6 @mouneyrac mouneyrac committed Oct 7, 2011
Showing with 80 additions and 2 deletions.
  1. +1 −0 lib/zend/readme_moodle.txt
  2. +43 −1 webservice/soap/locallib.php
  3. +36 −1 webservice/xmlrpc/locallib.php
@@ -7,4 +7,5 @@ Do not use outside of our /webservice/* or mnet !!
Changes:
* lots of files removed
* small fix to error reporting in reflection (MDL-21460, ZF-8980)
+* SOAP and XMLRPC servers overwrite the fault() functions
@@ -24,6 +24,43 @@
*/
require_once("$CFG->dirroot/webservice/lib.php");
+require_once 'Zend/Soap/Server.php';
+
+/**
+ * The Zend XMLRPC server but with a fault that returns debuginfo
+ */
+class moodle_zend_soap_server extends Zend_Soap_Server {
+
+ /**
+ * Generate a server fault
+ *
+ * Note that the arguments are reverse to those of SoapFault.
+ *
+ * Moodle note: the difference with the Zend server is that we throw a SoapFault exception
+ * with the debuginfo integrated to the exception message when DEBUG >= NORMAL
+ *
+ * If an exception is passed as the first argument, its message and code
+ * will be used to create the fault object if it has been registered via
+ * {@Link registerFaultException()}.
+ *
+ * @link http://www.w3.org/TR/soap12-part1/#faultcodes
+ * @param string|Exception $fault
+ * @param string $code SOAP Fault Codes
+ * @return SoapFault
+ */
+ public function fault($fault = null, $code = "Receiver")
+ {
+ //intercept any exceptions with debug info and transform it in Moodle exception
+ if ($fault instanceof Exception) {
+ //add the debuginfo to the exception message if debuginfo must be returned
+ if (debugging() and isset($fault->debuginfo)) {
+ $fault = new SoapFault('Receiver', $fault->getMessage() . ' | DEBUG INFO: ' . $fault->debuginfo);
+ }
+ }
+
+ return parent::fault($fault, $code);
+ }
+}
/**
* SOAP service server implementation.
@@ -43,7 +80,7 @@ public function __construct($authmethod) {
if (optional_param('wsdl', 0, PARAM_BOOL)) {
parent::__construct($authmethod, 'Zend_Soap_AutoDiscover');
} else {
- parent::__construct($authmethod, 'Zend_Soap_Server');
+ parent::__construct($authmethod, 'moodle_zend_soap_server');
}
$this->wsname = 'soap';
}
@@ -79,6 +116,11 @@ protected function init_zend_server() {
$this->zend_server->registerFaultException('webservice_parameter_exception');
$this->zend_server->registerFaultException('invalid_parameter_exception');
$this->zend_server->registerFaultException('invalid_response_exception');
+ //when DEBUG >= NORMAL then the thrown exceptions are "casted" into a PHP SoapFault expception
+ //in order to diplay the $debuginfo (see moodle_zend_soap_server class - MDL-29435)
+ if (debugging()) {
+ $this->zend_server->registerFaultException('SoapFault');
+ }
}
}
@@ -24,6 +24,36 @@
*/
require_once("$CFG->dirroot/webservice/lib.php");
+require_once 'Zend/XmlRpc/Server.php';
+
+/**
+ * The Zend XMLRPC server but with a fault that return debuginfo
+ */
+class moodle_zend_xmlrpc_server extends Zend_XmlRpc_Server {
+
+ /**
+ * Raise an xmlrpc server fault
+ *
+ * Moodle note: the difference with the Zend server is that we throw a plain PHP Exception
+ * with the debuginfo integrated to the exception message when DEBUG >= NORMAL
+ *
+ * @param string|Exception $fault
+ * @param int $code
+ * @return Zend_XmlRpc_Server_Fault
+ */
+ public function fault($fault = null, $code = 404)
+ {
+ //intercept any exceptions with debug info and transform it in Moodle exception
+ if ($fault instanceof Exception) {
+ //add the debuginfo to the exception message if debuginfo must be returned
+ if (debugging() and isset($fault->debuginfo)) {
+ $fault = new Exception($fault->getMessage() . ' | DEBUG INFO: ' . $fault->debuginfo, 0);
+ }
+ }
+
+ return parent::fault($fault, $code);
+ }
+}
/**
* XML-RPC service server implementation.
@@ -36,7 +66,7 @@ class webservice_xmlrpc_server extends webservice_zend_server {
*/
public function __construct($authmethod) {
require_once 'Zend/XmlRpc/Server.php';
- parent::__construct($authmethod, 'Zend_XmlRpc_Server');
+ parent::__construct($authmethod, 'moodle_zend_xmlrpc_server');
$this->wsname = 'xmlrpc';
}
@@ -48,6 +78,11 @@ protected function init_zend_server() {
parent::init_zend_server();
// this exception indicates request failed
Zend_XmlRpc_Server_Fault::attachFaultException('moodle_exception');
+ //when DEBUG >= NORMAL then the thrown exceptions are "casted" into a plain PHP Exception class
+ //in order to display the $debuginfo (see moodle_zend_xmlrpc_server class - MDL-29435)
+ if (debugging()) {
+ Zend_XmlRpc_Server_Fault::attachFaultException('Exception');
+ }
}
}

0 comments on commit 2c28fa7

Please sign in to comment.