Announcement Announcement Module
Collapse
No announcement yet.
passing URLs as parameters to Spring Roo json REST server Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

    http://localhost:8080/longurl/lookup...it.ly%2fp8TVYG

    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:

    http://localhost:8080/longurl/urlmaps?form
    gives me a form to create my records,

    http://localhost:8080/longurl/urlmaps?page=1&size=10
    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

    http://localhost:8080/longurl/lookup/aaa

    ("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)

    http://localhost:8080/longurl/lookup.../bit.ly/p8TVYG

    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

    http://localhost:8080/longurl/lookup...it.ly%2fp8TVYG

    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
    json all
    web mvc install view --path ext --title "Ext JS WS" --viewName index
    perform eclipse
    controller scaffold --entity ~.domain.UrlMap --class ~.web.UrlLookupController
    perform eclipse
    finder list --class ~.domain.UrlMap
    finder add --finderName findUrlMapsByShortUrlEquals
    quit


    PS I am using a library ExtJS WS from BTI360 to help me test my REST functionality.

  • #2
    Originally posted by alexmc6 View Post
    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

    http://localhost:8080/longurl/lookup/aaa

    ("aaa" was inserted as a url into my database, but of course it is not a real url)

    Code:
    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
    json all
    web mvc install view --path ext --title "Ext JS WS" --viewName index
    controller scaffold --entity ~.domain.UrlMap --class ~.web.UrlLookupController
    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:
    • 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.

    Comment


    • #3
      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

      http://localhost:8080/longurl/lookup...me%2FpipNk-4QE
      (Accept: application/json)

      It correctly looks up the URL "http://wp.me/pipNk-4QE" in my database.


      What I could not get working was

      http://localhost:8080/longurl/lookup...me%2FpipNk-4QE

      I can live without this, but I feel that the bottom version is more correct than the top.

      Comment


      • #4
        I'm not sure the latter form is even a valid URL; do you know?

        Comment


        • #5
          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.

          Comment

          Working...
          X