RE: Trouble Getting Query Parameters
Hi Andrew, Thanks for reporting this issue. I've just updated our FormReader logic to be more flexible. I've also added a regression test case. Checked in SVN trunk. Best regards, Jerome Louvel -- Restlet ~ Founder and Lead developer ~ http://www.restlet.org Noelios Technologies ~ Co-founder ~ http://www.noelios.com -Message d'origine- De : Andrew Moore [mailto:rp.andrew.mo...@gmail.com] Envoyé : jeudi 11 juin 2009 19:59 À : discuss@restlet.tigris.org Objet : Re: Trouble Getting Query Parameters I just did a test with curl both with and without that initial ampersand in there... yes, that ampersand is causing the parsing problem. Since this is EXT.js creating this, I guess I'll have to figure out a way to change it or something. Should the FormReader be able to handle an initial ampersand? Is that a bug, and if so, should I file it? Thanks for your help! -- View this message in context: http://n2.nabble.com/Trouble-Getting-Query-Parameters-tp3063239p3063559.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=23613 95 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2362577
Re: Trouble Getting Query Parameters
I just did a test with curl both with and without that initial ampersand in there... yes, that ampersand is causing the parsing problem. Since this is EXT.js creating this, I guess I'll have to figure out a way to change it or something. Should the FormReader be able to handle an initial ampersand? Is that a bug, and if so, should I file it? Thanks for your help! -- View this message in context: http://n2.nabble.com/Trouble-Getting-Query-Parameters-tp3063239p3063559.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2361395
Re: Trouble Getting Query Parameters
Your URL has an immediate ampersand after the question mark: ?&_dc=1244741620627&callback=stcCallback1001 Maybe try removing the first ampersand: ?_dc=1244741620627&callback=stcCallback1001 I kind of hope that it doesn't care about it, but you never know. Dustin Andrew Moore wrote: > I'm starting to understand what may be going on... when EXT.js makes the > request for my URI, the query string looks like this: > > ?&_dc=1244741620627&callback=stcCallback1001 > > And the org.restlet.engine.util.FormReader is not able to parse the > parameters. Here's the error: > > 06/11/2009 11:33:40.640 [http-0.0.0.0-8080-1] [STDERR] [ERROR] Jun 11, 2009 > 11:33:40 AM org.restlet.engine.util.FormReader addParameters > WARNING: Unable to parse a form parameter. Skipping the remaining > parameters. > java.io.IOException: Empty parameter name detected. Please check your form > data > at > org.restlet.engine.util.FormReader.readNextParameter(FormReader.java:239) > at org.restlet.engine.util.FormReader.addParameters(FormReader.java:132) > at org.restlet.engine.util.FormUtils.parse(FormUtils.java:302) > at org.restlet.data.Form.(Form.java:137) > at org.restlet.data.Form.(Form.java:121) > at org.restlet.data.Form.(Form.java:94) > at org.restlet.data.Reference.getQueryAsForm(Reference.java:1375) > > > I'm not sure how to get around this... Maybe my best option is to try and > modify what EXT.js is appending on my URI when it makes the request? > > Any thoughts? > > Thanks in advance for your help! > > ~ Andrew > -- Dustin N. Jenkins | Tel/Tél: 250.363.3101 | dustin.jenk...@nrc-cnrc.gc.ca facsimile/télécopieur: (250) 363-0045 National Research Council Canada | 5071 West Saanich Rd, Victoria BC. V9E 2E7 Conseil national de recherches Canada | 5071, ch. West Saanich, Victoria (C.-B) V9E 2E7 Government of Canada | Gouvernement du Canada -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2361392
Re: Trouble Getting Query Parameters
I'm starting to understand what may be going on... when EXT.js makes the request for my URI, the query string looks like this: ?&_dc=1244741620627&callback=stcCallback1001 And the org.restlet.engine.util.FormReader is not able to parse the parameters. Here's the error: 06/11/2009 11:33:40.640 [http-0.0.0.0-8080-1] [STDERR] [ERROR] Jun 11, 2009 11:33:40 AM org.restlet.engine.util.FormReader addParameters WARNING: Unable to parse a form parameter. Skipping the remaining parameters. java.io.IOException: Empty parameter name detected. Please check your form data at org.restlet.engine.util.FormReader.readNextParameter(FormReader.java:239) at org.restlet.engine.util.FormReader.addParameters(FormReader.java:132) at org.restlet.engine.util.FormUtils.parse(FormUtils.java:302) at org.restlet.data.Form.(Form.java:137) at org.restlet.data.Form.(Form.java:121) at org.restlet.data.Form.(Form.java:94) at org.restlet.data.Reference.getQueryAsForm(Reference.java:1375) I'm not sure how to get around this... Maybe my best option is to try and modify what EXT.js is appending on my URI when it makes the request? Any thoughts? Thanks in advance for your help! ~ Andrew -- View this message in context: http://n2.nabble.com/Trouble-Getting-Query-Parameters-tp3063239p3063444.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2361391
Trouble Getting Query Parameters
I'm new to Restlet and I'm having trouble accessing the query parameters in my ServerResource. I'm using a URI comparable to: http://localhost:8080/myapp/zipcodes/{zip}/locations/{location}/users/{user}?&callback=someCallbackFunction The client is written in EXT.js and is expecting me to wrap the json object in a function with a name the 'callback' query parameter specifies. I can't for the life of me understand what I'm doing wrong in trying to access this query parameter. My application class is similar to this: package com.myapp.applications; import org.restlet.Application; import org.restlet.Context; import org.restlet.Restlet; import org.restlet.routing.Router; import com.myapp.resources.ZipsLocsUsersResource; public class MyApplication extends Application { public MyApplication() { } public MyApplication(Context context) { super(context); } @Override public Restlet createRoot() { // Create a router Restlet that routes each call to a Router router = new Router(getContext()); router.attach("/myapp/zipcodes/{zip}/locations/{location}/users/{user}", ZipsLocsUsersResource.class); return router; } } And my ServerResource class is similar to this: package com.myapp.resources; import org.restlet.data.Form; import org.restlet.data.Parameter; import org.restlet.data.Reference; import org.restlet.data.Request; import org.restlet.representation.Representation; import org.restlet.representation.StringRepresentation; import org.restlet.resource.Get; import org.restlet.resource.ServerResource; import com.myapp.representation.JsonRepresentation; public class ZipsLocsUsersResource extends ServerResource { private String zip; private String location; private String user; private String callback; @Get public Representation represent() { this.zip = (String) getRequest().getAttributes().get("zip"); this.location = (String) getRequest().getAttributes().get("location"); this.user = (String) getRequest().getAttributes().get("user"); Form form = getRequest().getResourceRef().getQueryAsForm(); this.callback = form.getFirstValue("callback"); String jsonString = "{user:\"" + this.user + "\", loc: \"" + this.location + "\", zip:\"" + this.zip + "\"}"; if (this.callback != null) { jsonString = this.callback + "(" + jsonString + ")"; } Representation result = new JsonRepresentation(jsonString); return result; } } When I run with a debugger, my form always ends up being empty... and when I dig through the request I can't find the parameters anywhere. I am wanting this parameter to be optional. I'm not sure if I'm setting my application up wrong, or if I'm trying to get the parameters the wrong way? This is on a GET request, and everywhere I look, folks seem to not be able to access the query parameters until they try the getRequest().getResourceRef().getQueryAsForm() way of doing it. Thanks in advance for your help! Regards, Andrew -- View this message in context: http://n2.nabble.com/Trouble-Getting-Query-Parameters-tp3063239p3063239.html Sent from the Restlet Discuss mailing list archive at Nabble.com. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2361378