MDL-20808 Fixes for amf web services and test client - a web service browser.
authorJamie Pratt <me@jamiep.org>
Thu, 11 Feb 2010 03:39:02 +0000 (03:39 +0000)
committerJamie Pratt <me@jamiep.org>
Thu, 11 Feb 2010 03:39:02 +0000 (03:39 +0000)
Fixed the bugs that Jerome mentions in the comments for this issue :

* No exception thrown when there is no return value now.
* No exception thrown when there are extra keys in the return value that are not in the description. Now the extra keys are ignored and not returned which is what the other web services do.
* Improved information about exceptions in the test client.

webservice/amf/locallib.php
webservice/amf/testclient/AMFTester.mxml
webservice/amf/testclient/AMFTester.swf
webservice/lib.php

index 9715a0b..1e92b54 100644 (file)
@@ -67,21 +67,21 @@ class webservice_amf_server extends webservice_zend_server {
        $descriptionmethod = $function->methodname.'_returns()';
        $callforreturnvaluedesc = $function->classname.'::'.$descriptionmethod;
        return
-'        return webservice_amf_server::validate_and_cast_values('.$callforreturnvaluedesc.', '.$externallibcall.', true)';
+'        return webservice_amf_server::validate_and_cast_values('.$callforreturnvaluedesc.', '.$externallibcall.');';
     }
     /**
      * Validates submitted value, comparing it to a description. If anything is incorrect
      * invalid_return_value_exception is thrown. Also casts the values to the type specified in
      * the description.
-     * @param external_description $description description of parameters
+     * @param mixed $description description of parameters or null if no return value
      * @param mixed $value the actual values
      * @param boolean $singleasobject specifies whether a external_single_structure should be cast to a stdClass object
      *                                 should always be false for use in validating parameters in externallib functions.
      * @return mixed params with added defaults for optional items, invalid_parameters_exception thrown if any problem found
      */
-    public static function validate_and_cast_values(external_description $description, $value) {
+    public static function validate_and_cast_values($description, $value) {
        if (is_null($description)){
-               return $value;
+               return;
        }
         if ($description instanceof external_value) {
             if (is_array($value) or is_object($value)) {
@@ -116,9 +116,10 @@ class webservice_amf_server extends webservice_zend_server {
                 }
                 unset($value[$key]);
             }
-            if (!empty($value)) {
+/*          Was decided that extra keys should just be ignored and not returned.
+ *          if (!empty($value)) {
                 throw new invalid_return_value_exception('Unexpected keys detected in parameter array.');
-            }
+            }*/
             return (object)$result;
 
         } else if ($description instanceof external_multiple_structure) {
index ef7eee6..e26aa97 100644 (file)
@@ -30,9 +30,9 @@
                        import mx.messaging.channels.AMFChannel;
                        import com.adobe.serialization.json.JSON;
                        
-/*                     // Import the debugger
-                       import nl.demonsters.debugger.MonsterDebugger;
- */                    
+                       // Import the debugger
+//                     import nl.demonsters.debugger.MonsterDebugger;
+                       
                        public var api:AMFConnector;
                        protected var methods:Array;
                        protected var introspector:String;
                        protected function process(event:Event):void
                        {
                                if (api.error) {
-                                       push(input, time() + ": Exception (code: "+api.data.code+", description: "+api.data.description+", detail: "+api.data.detail+", line: "+api.data.line+")\n");
+                                       push(input, time() + ": Exception (faultString: "+api.data.faultString+", extendedData: "+api.data.extendedData+", faultDetail: "+api.data.faultDetail+")\n");
                                } else {
                                        push(input, time() + ": "+JSON.encode(api.data)+"\n");
                                }
+//                             MonsterDebugger.trace(this, {"data":api.data, "error":api.error});
 //                             MonsterDebugger.trace(this, api.data);
                        }
                        
                        <mx:TextArea id="methodDescription" text="" width="100%" height="120"/>
                        <mx:HBox width="100%">
                                <mx:Label id="larg1" text="Arg 1"/>
-                               <mx:TextInput id="arg1" toolTip="{argumentToolTip}"/>
+                               <mx:TextInput id="arg1" toolTip="{argumentToolTip}" width="100%"/>
                        </mx:HBox>
                        <mx:HBox width="100%">
                                <mx:Label id="larg2" text="Arg 2"/>
-                               <mx:TextInput id="arg2" toolTip="{argumentToolTip}"/>
+                               <mx:TextInput id="arg2" toolTip="{argumentToolTip}" width="100%"/>
                        </mx:HBox>
                        <mx:HBox width="100%">
                                <mx:Label id="larg3" text="Arg 3"/>
-                               <mx:TextInput id="arg3" toolTip="{argumentToolTip}"/>
+                               <mx:TextInput id="arg3" toolTip="{argumentToolTip}" width="100%"/>
                        </mx:HBox>
                        <mx:HBox width="100%">
                                <mx:Label id="larg4" text="Arg 4"/>
-                               <mx:TextInput id="arg4" toolTip="{argumentToolTip}"/>
+                               <mx:TextInput id="arg4" toolTip="{argumentToolTip}" width="100%"/>
                        </mx:HBox>
                        <mx:HBox width="100%">
                                <mx:Label id="larg5" text="Arg 5"/>
-                               <mx:TextInput id="arg5" toolTip="{argumentToolTip}"/>
+                               <mx:TextInput id="arg5" toolTip="{argumentToolTip}" width="100%"/>
                        </mx:HBox>
                        <mx:HBox width="100%">
                                <mx:Label id="larg6" text="Arg 6"/>
-                               <mx:TextInput id="arg6" toolTip="{argumentToolTip}"/>
+                               <mx:TextInput id="arg6" toolTip="{argumentToolTip}" width="100%"/>
                        </mx:HBox>
                        <mx:HBox width="100%">
                                <mx:Label id="larg7" text="Arg 7"/>
-                               <mx:TextInput id="arg7" toolTip="{argumentToolTip}"/>
+                               <mx:TextInput id="arg7" toolTip="{argumentToolTip}" width="100%"/>
                        </mx:HBox>
                        <mx:HBox width="100%">
                                <mx:Button id="call" label="Call" click="execute()"/>
index 8819ff3..4aac723 100644 (file)
Binary files a/webservice/amf/testclient/AMFTester.swf and b/webservice/amf/testclient/AMFTester.swf differ
index 9d29c5e..f8f6d13 100644 (file)
@@ -443,7 +443,7 @@ class '.$classname.' {
 '.$return.'
      */
     public function '.$function->name.'('.$params.') {
-'.$serviceclassmethodbody.';
+'.$serviceclassmethodbody.'
     }
 ';
         return $code;
@@ -458,7 +458,7 @@ class '.$classname.' {
      * @return string body of the method for $function ie. everything within the {} of the method declaration.
      */
     protected function service_class_method_body($function, $params){
-       return '        return '.$function->classname.'::'.$function->methodname.'('.$params.')';
+       return '        return '.$function->classname.'::'.$function->methodname.'('.$params.');';
     }
     
     /**