Moodle
  1. Moodle
  2. MDL-21553

amf web service : In Flash an array has normally a numerical key

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: Web Services
    • Labels:
      None
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Rank:
      26565

      Description

      From amf should be able to return AND accept an object type instead of an array type for arrays with string keys ie. external_single_structures.

      So in the patch attached to MDL-20808 I have modified the validate_parameters so that :

      • it can accept an object instead of an array where a external_single_structure param is expected. An object is automatically cast to an array.
      • also am using validate_parameters static function to cast the return result to the proper types. Have added a parameter that defaults to false that tells the function to return an external_single_structures as an object.

        Issue Links

          Activity

          Hide
          Jérôme Mouneyrac added a comment -

          Hi Jamie, I see why you want to do that but is it possible to do it in the AMF server? I haven't check deeply the Zend Amf documentation but I remember that it was possible to intercept what the server receives and sends. So at these moments you could cast objects/arrays expected by the validate_parameters function (when the flash client is passing a object as parameter) and by the flex/flash client (when the Amf server is returning an array).

          I've just seen that the entire Zend library changed the version number from 1.9 to 1.10. The servers support multiple class load (as you told me), and other little things. I'll test your client this avo and I will also have a new look to the Zend library.

          Show
          Jérôme Mouneyrac added a comment - Hi Jamie, I see why you want to do that but is it possible to do it in the AMF server? I haven't check deeply the Zend Amf documentation but I remember that it was possible to intercept what the server receives and sends. So at these moments you could cast objects/arrays expected by the validate_parameters function (when the flash client is passing a object as parameter) and by the flex/flash client (when the Amf server is returning an array). I've just seen that the entire Zend library changed the version number from 1.9 to 1.10. The servers support multiple class load (as you told me), and other little things. I'll test your client this avo and I will also have a new look to the Zend library.
          Hide
          Jérôme Mouneyrac added a comment -

          I forgot ... thanks Jamie

          Show
          Jérôme Mouneyrac added a comment - I forgot ... thanks Jamie
          Hide
          Jamie Pratt added a comment -

          Didn't find a way to do the casting of the parameters or the return value within the zend server.

          Show
          Jamie Pratt added a comment - Didn't find a way to do the casting of the parameters or the return value within the zend server.
          Hide
          Jamie Pratt added a comment -

          I looked at various options. I did not want to make any changes to the externallib code. But this seemed like the way that made the most sense.

          Allowing objects as well as arrays for external_single_structure makes sense to me and automatically casting them to arrays. And including the code to cast the return value in the dynamically created amf service class also seems to make sense to me as we have the name of the method available there and thus it is easy to refer to the return value description method to cast the values to the right types.

          Show
          Jamie Pratt added a comment - I looked at various options. I did not want to make any changes to the externallib code. But this seemed like the way that made the most sense. Allowing objects as well as arrays for external_single_structure makes sense to me and automatically casting them to arrays. And including the code to cast the return value in the dynamically created amf service class also seems to make sense to me as we have the name of the method available there and thus it is easy to refer to the return value description method to cast the values to the right types.
          Hide
          Jérôme Mouneyrac added a comment - - edited

          I found how I managed to manipulate parameters in Zend server for XMLRPC server: (it was a long time ago so I forgot)
          http://cvs.moodle.org/moodle/webservice/xmlrpc/lib.php?hideattic=0&view=markup

                      $server = new Zend_XmlRpc_Server();
                      $server->setClass("ws_authentication", "authentication");
                      // Create a request object
                      $request = new Zend_XmlRpc_Request_Http();
                      $params = $request->getParams();
                      $this->convertXmlrpcParams($params);
                      $request->setParams($params);
                      echo $server->handle($request);
          
          Show
          Jérôme Mouneyrac added a comment - - edited I found how I managed to manipulate parameters in Zend server for XMLRPC server: (it was a long time ago so I forgot) http://cvs.moodle.org/moodle/webservice/xmlrpc/lib.php?hideattic=0&view=markup $server = new Zend_XmlRpc_Server(); $server->setClass( "ws_authentication" , "authentication" ); // Create a request object $request = new Zend_XmlRpc_Request_Http(); $params = $request->getParams(); $ this ->convertXmlrpcParams($params); $request->setParams($params); echo $server->handle($request);
          Hide
          Jamie Pratt added a comment -

          Unfortunately this does not work with the amf server. The amf_request class does not have a getParams or setParams method.

          But I found another solution. The Zend_Amf_Server _dispatch method does the actual calling of the method in the service class and can be overridden in a custom Moodle child class.

          Show
          Jamie Pratt added a comment - Unfortunately this does not work with the amf server. The amf_request class does not have a getParams or setParams method. But I found another solution. The Zend_Amf_Server _dispatch method does the actual calling of the method in the service class and can be overridden in a custom Moodle child class.
          Hide
          Jérôme Mouneyrac added a comment -

          Very good I'll retest this avo the updated client from yesterday.

          Show
          Jérôme Mouneyrac added a comment - Very good I'll retest this avo the updated client from yesterday.
          Hide
          Jamie Pratt added a comment -

          In the end I found the neatest way to do this was to put function calls in the dynamically generated service class to process the params for each method call and to process the return value to convert them to the proper type.

          Show
          Jamie Pratt added a comment - In the end I found the neatest way to do this was to put function calls in the dynamically generated service class to process the params for each method call and to process the return value to convert them to the proper type.
          Hide
          Jérôme Mouneyrac added a comment -

          Is it into the Amf server code or into lib/externallib.php? Saying it without knowing if it's possible or not, I would prefer any additional code into Amf server code. (excepted if it's going to be used by other the protocols)

          Show
          Jérôme Mouneyrac added a comment - Is it into the Amf server code or into lib/externallib.php? Saying it without knowing if it's possible or not, I would prefer any additional code into Amf server code. (excepted if it's going to be used by other the protocols)
          Hide
          Jamie Pratt added a comment -

          All additional code has gone into the amf plug in. Except for a small hook to override part of the dynamic service class code generation in child classes of webservice_zend_server.

          Show
          Jamie Pratt added a comment - All additional code has gone into the amf plug in. Except for a small hook to override part of the dynamic service class code generation in child classes of webservice_zend_server.
          Hide
          Jamie Pratt added a comment -

          Committed a fix for this along with MDL-20808.

          Show
          Jamie Pratt added a comment - Committed a fix for this along with MDL-20808 .

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: