Grails
  1. Grails
  2. GRAILS-8443

parseRequest not working with named URL mappings

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-RC3
    • Fix Version/s: 2.0.1, 2.1-RC1
    • Component/s: None
    • Labels:
    • Environment:
      Ubuntu 10.10, java-6-sun version "1.6.0_26" (64)

      Description

      This may well be present in earlier versions also.

      When switching from a normal URL mapping to a named URL mapping, the request JSON is no longer automatically parsed.

      UrlMappings.groovy
      
      class UrlMappings {
      
      	static mappings = {
      
              "/user/$id"(controller: "user", parseRequest: true) {
                  action = [POST:"update"]
              }
      
              name userId: "/nameduser/$id" {
                  controller = "user"
                  parseRequest = true
                  action = [POST:"update"]
              }
      
      	}
      }
      
      UserController.groovy
      package restful
      
      class UserController {
      
          def update() {
              println params
              assert params.username == "NewUsername"
              render "ok"
          }
      }
      
      

      POSTing to /user/1 with the JSON

      {'username': "NewUsername"}

      is successful, however posting the same data to /nameduser/1 fails as the username is not added to params.

      Successful request:
      curl -i -H 'Content-Type:application/json' -X POST -d '

      {username: "NewUsername"}

      ' http://127.0.0.1:9090/restful/user/1

      Failing request:
      curl -i -H 'Content-Type:application/json' -X POST -d '

      {username: "NewUsername"}

      ' http://127.0.0.1:9090/restful/nameduser/1

      [id:1, action:[POST:update], controller:user]
      | Error 2011-12-05 12:05:05,665 ["http-bio-9090"-exec-10] ERROR errors.GrailsExceptionResolver  - PowerAssertionError occurred when processing request: [POST] /restful/nameduser/1
      assert params.username == "NewUsername"
             |      |        |
             |      null     false
             [id:1, action:[POST:update], controller:user]. Stacktrace follows:
      

        Activity

        Hide
        Jeff Scott Brown added a comment -

        FYI...

        I do not think this is peculiar to named url mappings. I think the problem applies to all mappings defined with a closure and no named arguments.

        This works:

            "/path"(controller: 'foo') {
                parseRequest = true
            }
        

        This does not work:

            "/path" {
                controller = 'foo'
                parseRequest = true
            }
        

        We will get it resolved right away.

        Show
        Jeff Scott Brown added a comment - FYI... I do not think this is peculiar to named url mappings. I think the problem applies to all mappings defined with a closure and no named arguments. This works: "/path"(controller: 'foo') { parseRequest = true } This does not work: "/path" { controller = 'foo' parseRequest = true } We will get it resolved right away.
        Hide
        Bill Thornton added a comment -

        Many thanks.

        Show
        Bill Thornton added a comment - Many thanks.
        Hide
        Jeff Scott Brown added a comment -

        Bill,

        Thanks for reporting the issue.

        If you are interested in helping validate the fix you can grab the latest 2.1 snapshot build from http://hudson.grails.org/job/grails_core_2.1.x/lastSuccessfulBuild/artifact/build/distributions/ or the latest 2.0.1 snapshot build from http://hudson.grails.org/job/grails_core_2.0.x/lastSuccessfulBuild/artifact/build/distributions/ and give it a spin. If you do that, please leave a comment here.

        Thanks again.

        Show
        Jeff Scott Brown added a comment - Bill, Thanks for reporting the issue. If you are interested in helping validate the fix you can grab the latest 2.1 snapshot build from http://hudson.grails.org/job/grails_core_2.1.x/lastSuccessfulBuild/artifact/build/distributions/ or the latest 2.0.1 snapshot build from http://hudson.grails.org/job/grails_core_2.0.x/lastSuccessfulBuild/artifact/build/distributions/ and give it a spin. If you do that, please leave a comment here. Thanks again.

          People

          • Assignee:
            Jeff Scott Brown
            Reporter:
            Bill Thornton
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development