Jul 8th, 2011, 05:33 AM
passing URLs as parameters to Spring Roo json REST server
I am trying to create a very simple REST server with Roo, and have it working - of sorts... What I am having problems with is incorporating urls into parameters such that I can pass them to my REST server.
In summary I am trying to create a Spring Roo app which responds to this REST request, does some work, and returns the value found in the database, should it be found.
Should I be able to do this in Spring Roo, or Spring, or have I misunderstood something about REST GET calls?
More detailed info:
I have a single table with an id number, a short url, and a long url.
I have generated web based screens as well as json so the following works:
gives me a form to create my records,
lists them, and so on.
I have created a second Spring Roo controller with a different url map annotation so the following also works as a REST GET call - Accept application/json
("aaa" was inserted as a url into my database, but of course it is not a real url)
If I substitute a real url it doesn't work (of course)
but what is interesting is that I get a "Resource not found" from Spring. It doesn't even call my code for "longurl/lookup". Is that correct behaviour? I would assume not...
So lets do some url encoding and try this
That fails too - but in a different way... Error code 400, Bad Request.
Here is my log.roo with a few lines edited out for clarity
// Spring Roo 1.1.4.RELEASE [rev f787ce7] log opened at 2011-07-07 15:12:39
project --topLevelPackage me.longurl --java 6 --projectName longurl
persistence setup --provider HIBERNATE --database MYSQL --databaseName roo_longurl
database properties set --key database.username --value redacted
database properties set --key database.password --value redacted
entity --class ~.domain.UrlMap
field string --fieldName shortUrl --column SHORTURL --notNull
field string --fieldName longUrl --column LONGURL --notNull
web mvc setup
web mvc all --package ~.web
web mvc install view --path ext --title "Ext JS WS" --viewName index
controller scaffold --entity ~.domain.UrlMap --class ~.web.UrlLookupController
finder list --class ~.domain.UrlMap
finder add --finderName findUrlMapsByShortUrlEquals
PS I am using a library ExtJS WS from BTI360 to help me test my REST functionality.
Jul 10th, 2011, 09:00 PM
The first thing I can tell you is that an application generated using the above script will throw an exception at deploy time because these two controllers are both mapped to the "/urlmaps" servlet path:
Originally Posted by alexmc6
- UrlMapController (generated by the "web mvc all" command), and
- UrlLookupController (generated by the "controller scaffold" command)
Presumably you have modified the annotations on the latter controller to map to the "/lookup" path instead.
But what I'm most unclear about is the significance of URLs in your application; are they a first-class domain type as your script would suggest, or are they simply meant to be part of your REST plumbing? If you could explain more about what your application is intended to do (e.g. some concrete use cases in domain language), I could advise you further on whether you're going the right way about it.
Jul 11th, 2011, 03:17 PM
Thanks very much Andrew. Yes, the two controllers had overlapping request mappings. I fixed that. I have a work around so this isn't urgent any more.
Here is a concrete example...
I can get this working as a Spring Roo/Spring MVC web app
It correctly looks up the URL "http://wp.me/pipNk-4QE" in my database.
What I could not get working was
I can live without this, but I feel that the bottom version is more correct than the top.
Jul 11th, 2011, 06:13 PM
I'm not sure the latter form is even a valid URL; do you know?
Jul 12th, 2011, 04:24 AM
Andrew> I'm not sure the latter form is even a valid URL; do you know?
That's what I am trying to find out :-)
I thought the point behind url encoding was that it was to enable funny chars to be embedded in urls. However it *might* be just to allow funny chars to be embedded in query strings and not the whole url.
In any case, no one seems to be jumping up and saying that they do this with Spring Roo, so maybe I shouldn't be trying it at all.
Thanks for your help.
Tags for this Thread