Closed (fixed)
Project:
amfserver
Version:
7.x-3.0
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
12 Apr 2011 at 16:19 UTC
Updated:
17 Aug 2011 at 22:11 UTC
Jump to comment: Most recent file
It seems that this should generate an exception. the amfserver_service_sleep method requires an argument of type int. no default is set.
yet when I call the method it doesn't generate the exception.
I get the output from the function (in flash): result: !!!!! amfservice.sleep should fail since no required argument was sent. **data** amfservice says: argument to 'sleep' should be between 1 to 10 , yours was:
function amfserver_services_resources() {
return array(
'amfservice' => array(
'retrieve' => array(
'help' => 'retrieves the version of the amfserver',
'callback' => '_amfserver_service_retrieve',
'access arguments' => array(AMFSERVER_PERM_SERVICE_TEST),
),
'actions' => array(
'ping' => array(
'help' => 'pings the amfserver and sends back the optional message you send to it',
'callback' => '_amfserver_service_ping',
'access arguments' => array(AMFSERVER_PERM_SERVICE_TEST),
'args' => array(
array(
'name' => 'message',
'optional' => TRUE,
'source' => array('path' => 0),
'type' => 'string',
'description' => 'a message you want to give to the server',
'default value' => 'nothing'
),
),
),
'sleep' => array(
'help' => 'makes the php script sleep for the number of seconds provided',
'callback' => '_amfserver_service_sleep',
'access arguments' => array(AMFSERVER_PERM_SERVICE_TEST),
'args' => array(
array(
'name' => 'seconds',
'optional' => FALSE,
'source' => array('path' => 0),
'type' => 'int',
'description' => 'an int between 1 and 10',
),
),
),
),
),
);
}
/**
* service method for the amfserver
* it's a testing method for the amfserver, provided as an implementation example
*/
function _amfserver_service_retrieve() {
return "version: " . variable_get( "amfserver_version" );
}
/**
* service method for the amfserver
* it's a testing method for the amfserver, provided as an implementation example
*/
function _amfserver_service_sleep( $seconds ) {
if($seconds >= 1 && $seconds <= 10){
sleep($seconds);
}
return "amfservice says: argument to 'sleep' should be between 1 to 10 , yours was: " . $seconds;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | services-arguments-recquired-1124960-1.patch | 2.05 KB | rolf vreijdenberger |
| Screen shot 2011-04-12 at 18.18.03 .png | 195.2 KB | rolf vreijdenberger | |
| Screen shot 2011-04-12 at 18.18.08 .png | 191.95 KB | rolf vreijdenberger |
Comments
Comment #1
rolf vreijdenberger commentedIt seems like it has to be implemented in the function services_controller_execute() in services.runtime.inc
working on it if I have the time.
Comment #2
rolf vreijdenberger commentedI implemented the folowing and provided a patch for it.
- check for any recquired arguments
- check if there are not too many arguments provided
- set the default values if no default values are provided and the default values are defined.
in my testing, only for the development of the amfserver, it works as expected.
I'm not sure how all the services are implemented, but in case the tests are not written properly they might fail..
an example: a test sends no arguments where one is required, but it gets a default result, so the test passed.
In the new situation, the test will fail because the recquired argument is missing. etc.
the patch is made agains the 7.x dev version of april 16th and is attached.
Comment #3
rolf vreijdenberger commentedOh, and I'm not sure about the status this issue needs.
Is there a help page somewhere where I can find info on the statuses??
Comment #4
kylebrowning commentedNot sure, but the correct status is needs review, once this patch is committed it goes to be ported, for 6.x
Comment #5
kylebrowning commentedWere already setting the default values for arguments here,
private function getControllerArguments($controller, $path, $method, &$sources=array()) { line 182.
It looks like the question is, Should services handle throwing errors if defaults are not supplied, and should services added the default arguments.
Right now, the REST server is throwing errors, so in essence, Servers are required to catch this.
Also, marking this as needs work, Too much arguments should be Too many arguments.
Comment #6
kylebrowning commentedGonna fix this in 3.1
Comment #7
kylebrowning commentedComment #8
kylebrowning commentedIts hard for us to determine when to help developers out and when to not.
Servers ARE required to provide default arguments(and throw exceptions on them).
The reason behind not doing this for you is because different servers handle arguments differently. For Example, we have no way of testing if the node object for node_create is there, because in REST we accept an object of ?name=test as opposed to ?node[name] = test.
REST server excepts both, but you can't check for the former, especially because its resource specific.
That being said, its really easy to check for required arguments and AMServer should just copy and paste this. I havn't fully tested it, but it should open your eyes to how to do it.
Comment #9
rolf vreijdenberger commentedHi Kyle,
I have an implementation of this in the amfserver pretty much from the beginning, so in that case, all is well :)
thanks
Comment #10
rolf vreijdenberger commented