Reputation: 12313
Using wget
I make two posts to the same url with xml in the body. The first works. The second has the content type specified and it does not work. Why is this and how do I get grails to parse the request even when the content type is specified?
first wget:
wget http://localhost:8080/myApp/myMoeView/save --post-file=xmltest.xml
Grails logs (notice the "parsed params"):
2014-02-27 18:44:05,465 [http-bio-8080-exec-9] INFO httplogger.DefaultHttpLogger - << #3425 POST http://localhost:8080/myApp/mrMoeView/save
2014-02-27 18:44:05,465 [http-bio-8080-exec-9] INFO httplogger.DefaultHttpLogger - << #3425 headers [Cookie: JSESSIONID=D5B2399D6FFB800130E826DCD7DB0C37]
2014-02-27 18:44:05,465 [http-bio-8080-exec-9] INFO httplogger.DefaultHttpLogger - << #3425 body: ''
2014-02-27 18:44:05,491 [http-bio-8080-exec-9] INFO httplogger.DefaultHttpLogger - << #3425 dispatched to mrMoeView/save with parsed params ['<?xml version':'{"1.0" encoding="UTF-8" standalone="yes"?><mrMoeView><absoluteTolerance>1.004</absoluteTolerance><endTime>0</endTime><id>4187</id><lastModified>2014-01-07 00:00:00.000 PST</lastModified><modelRealizationId>1193</modelRealizationId><mrMoeId>4187</mrMoeId><mrMoeName>Default MOE from Model 2140</mrMoeName><relativeTolerance>1e-4</relativeTolerance><startTime>0</startTime></mrMoeView>
second wget:
wget http://localhost:8080/myApp/mrMoeView/save --post-file=xmltest.xml --header="Content-Type:application/xml"
Grails logs (notice no parsed params, and the body has all the xml):
2014-02-27 18:46:27,291 [http-bio-8080-exec-5] INFO httplogger.DefaultHttpLogger - << #3427 POST http://localhost:8080/processdb/mrMoeView/save
2014-02-27 18:46:27,291 [http-bio-8080-exec-5] INFO httplogger.DefaultHttpLogger - << #3427 headers [Cookie: JSESSIONID=B1FAAB54422AC7F1E243D4CE68C72B77]
2014-02-27 18:46:27,291 [http-bio-8080-exec-5] INFO httplogger.DefaultHttpLogger - << #3427 body: '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><mrMoeView><absoluteTolerance>1.004</absoluteTolerance><endTime>0</endTime><id>4187</id><lastModified>2014-01-07 00:00:00.000 PST</lastModified><modelRealizationId>1193</modelRealizationId><mrMoeId>4187</mrMoeId><mrMoeName>Default MOE from Model 2140</mrMoeName><relativeTolerance>1e-4</relativeTolerance><startTime>0</startTime></mrMoeView>'
2014-02-27 18:46:27,320 [http-bio-8080-exec-5] INFO httplogger.DefaultHttpLogger - << #3427 dispatched to mrMoeView/save with parsed params [].
Grails version 2.3.5
UPDATE
UrlMapping:
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?"(parseRequest:true){
constraints {
// apply constraints here
}
}
"/"(view:"/index")
"500"(view:'/error')
}
}
Upvotes: 0
Views: 803
Reputation: 50265
With content type specified content will be received as part of request body instead of parsed params.
Body can be accessed as request.XML
in action. Going through the comments, we found out the usage of a older way to bindData
. With Grails 2.3.*, the request payload can be directly bound to a domain object provided the body has a valid id
as :
def save(MyDomain abc){
//use abc.name
}
If a valid id is not present in request body then domain object will be null inside the action.
Upvotes: 1