Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-3376

Generated controllers violate W3C HTTP PUT specification



    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Complete
    • 1.2.3.RELEASE
    • 1.2.4.RELEASE
    • WEB MVC
    • None


      The JSON controllers generated by Roo violate the specification of the HTTP PUT method defined by W3C (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html)

      The URL called for PUT has to be a single resource e.g 'myServer/persons/1' where '1' is the unique identifier of a person resource.

      If the resource exists, it gets replaced, else it will be created with the given identifier.

      The SpringMVC code generated by Roo maps HTTP PUT requests 'myServer/persons' to the updateFromJson method. The unique identifier is parsed from the body and is not in the url. This is wrong and most RESTful clients will call PUT with the identifier in the URL.

      Things are even worse because Roo also creates a showJson method mapped to 'myServer/persons/1' which is NOT limited to a GET request.

      This results in getting the showJson method called instead of the updateFromJson method if a proper PUT request with identifier is sent. This makes the use of most of the existing client-side REST frameworks like AngularJS very painful because every controller has to be corrected "by hand".

      I attached a Roo script which creates a (wrong) PersonController and I also attached a corrected PersonController that IMHO fits the W3C specification.

      BTW: There are other REST dependent issues with like not returning the link of the created resource in createFromJson (HATEOAS) but these will no be part of this issue (Spring Data REST creates quite good REST controllers btw.)


        1. diff_1_of_3.jpg
          192 kB
        2. diffs_2_and_3_of_3.jpg
          224 kB
        3. PersonController_Roo_Controller_Json.aj
          4 kB
        4. pizzashop_test.sh
          3 kB
        5. restapp.roo
          0.4 kB



            stewarta Alan Stewart
            rvillars Roger Villars
            7 Vote for this issue
            8 Start watching this issue