2

When I send a GET request with an empty body to my grails 1.3.7 controller by using the .json file extension (eg http://localhost:8080/myapp/mycontroller/myaction.json) I get a request parsing exception and it seems that grails is trying to parse my empty body to JSON. If I send the same request to the same action but without the .json extension, I don't have any error.

How can I get rid of this error?

Sebastien
  • 3,583
  • 4
  • 43
  • 82

2 Answers2

1

My best stab at this is to have separate clauses in the URL mapping and making sure that for GETtish requests, parseRequest is set to false, i.e.

static mappings = {
  "/$controller/show/$id?"(parseRequest:false,action:'show'){
        constraints {
            // apply constraints here
        }
    }

  "/$controller/$action?/$id?"(parseRequest:true){
        constraints {
            // apply constraints here
        }
    }

(Yes, this still happens in 2.0.0 RC1)

Ulrich Schwarz
  • 7,598
  • 1
  • 36
  • 48
0

Do you have an action in your controller that looks like this:

def myaction.json()

if not then you are sending data to an action that doesn't exist. if you are trying to parse JSON then use grails.converters for that matter:

import grails.converters

def jsonData = JSON.parse(params)

also this tuto might help: http://www.ibm.com/developerworks/java/library/j-grails11188/index.html

z.eljayyo
  • 1,289
  • 1
  • 10
  • 16
  • I don't have a json action. Here "json" is used as a content negotiation extension that tells grails I want a JSON response. The problem is that request parsing kicks in and fails because my request body is empty, which is normal because it's a GET. In fact, it turns out it's a bug in Grails so I created a JIRA issue for that: http://jira.grails.org/browse/GRAILS-7423 – Sebastien Apr 08 '11 at 13:44