Testing Restful webservices

Hi all:

I continue testing the Restful webservices following the Servoy Wiki examples:
http://wiki.servoy.com/display/public/DOCS/RESTful+Web+Services

In my ws_read() I type the code:

for (var i = 0; i < arguments.length; i++) {
     if (typeof arguments[i] == 'string') { //The URL path additions are passed in as Strings
         application.output('URL Path addition: ' + arguments[i])
     } else {
         for each (var key in arguments[i]) {
              application.output('Query Parameter "' + key + '", values:  "' + arguments[i][key].join(', ') + '"')
         }
     }
}

In theory, If I type http://localhost:8080/servoy-service/re … at&pet=Dog in the web browser, the application should be displayed in the console:

URL Path addition: foo
URL Path addition: bar
Query Parameter “name”, values: “John”

Unfortunately it only show:
URL Path addition: foo
URL Path addition: bar

In debug mode, I get the following results:

=>arguments[0]
“foo”
=>arguments[1]
“bar”
=>arguments[2]
Object {age:array[1],name:array[1],pet:array[2]}
=>key
[“Cat”,“Dog”]

I understand that, the key value should be “name” and not the key values.

I can get the key name if I typing in debug mode:
=>arguments[2].name[0]
“John”
But I need know before the object structure.

Summarizing the post; I need get the key name for check if it is valid in my application, and evidently your value.

Any idea?
Thanks in advance.
Best regards.

At the risk of being taxed as trying to lead you to a big learning curve (which is far from the truth), I would recommend using Velocity, which will ease your pain when receiving parameters and parsing them

With http://localhost:8080/servoy-service/ve … at&pet=Dog.
You would receive a JavaScript object like this:

request : {
    method: "get",
    extraPaths: ["foo", "bar"],
    parameters: {name: "John", age: "30", pet: ["Cat", "Dog"]},
    headers: {},
    cookies: [],
    // etc...
}

I answer to my self. If I change the code:

for each (var key in arguments[i]) 
...

by

for (var key in arguments[i])
...

It show the correct result.

Thanks for the replies.

In Servoy 5.2 ended up using a different approach to parse a query (tip of the hat to GoldCougar for the suggestion).
Instead of directly calling servoy WS, the external service calls a .jsp file placed in application_server/server/webapps/ROOT
e.g. “https://myserver.com/callback.jsp?Reference=1234&Result=OK&ResultCode=F

The jsp converts the values of the known query params into path extensions,
It looks like

<%
	String redirectURL = "http://localhost:8080/servoy-service/rest_ws/mySolution/myForm";
	
	if (request.getParameter("Reference") == null) 
        redirectURL += "/null";
    else
        redirectURL += "/" + request.getParameter("Reference");
        
	if (request.getParameter("Result") == null) 
        redirectURL += "/null";
    else
        redirectURL += "/" + request.getParameter("Result");

	if (request.getParameter("ResultCode") == null) 
        redirectURL += "/null";
    else
        redirectURL += "/" + request.getParameter("ResultCode");
        
	response.sendRedirect(redirectURL);
%>

The last line calls the servoy WS with the new URL, in this example
http://localhost:8080/servoy-service/rest_ws/mySolution/myForm/1234/OK/F
and executes the ws_read method with the arguments 1234, OK, F.

Maybe there’s a way to do it all in Servoy, but try as I might, I can’t read the query parameters from a GET call to Servoy WS.