samedi 18 avril 2015

Grails 3 and Json: "Request method 'POST' not supported"

I'm porting a working webapp from Grails 2.3 to 3.0.1. When I post the Json string {"command":"ping"} to the server i get the following result:



{"timestamp":1429380750958,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/rps/request"}


Here's the controller:



import org.grails.web.json.JSONObject
class RequestController {
def index() {
def jsonManagerService
JSONObject json = request.JSON
if(!json){
render "{json or gtfo}"
return
}
render jsonManagerService.parseJson(json)
}
}


And here's the JsonManagerService:



import grails.transaction.Transactional
import org.grails.web.json.JSONObject
@Transactional
class JsonManagerService {
def parseJson(JSONObject o) {
switch (o.command){
case("ping"):
return '{"result":"pong"}'
break;
default:
return '{"result":"unknown command"}'
}
}
}


It looks like a Spring related issue. All the search on this matter provided no results. Any idea?


Aucun commentaire:

Enregistrer un commentaire