--
You've received this message because you've subscribed to the Gaelyk Google Group.
To send an email to the group, please write to: gae...@googlegroups.com
To unsuscribe from this group: gaelyk+un...@googlegroups.com
To show more options: http://groups.google.fr/group/gaelyk?hl=en
Have you tried also something simpler like:
def jsonPayload = request.reader.text
Guillaume
> --
> You've received this message because you've subscribed to the Gaelyk Google Group.
> To send an email to the group, please write to: gae...@googlegroups.com
> To unsuscribe from this group: gaelyk+un...@googlegroups.com
> To show more options: http://groups.google.fr/group/gaelyk?hl=en
>
--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
out << request.reader.text
And I also got the error message:
GroovyServlet Error: script: '/receivejson.groovy': Script
processing failed.STREAMEDorg.mortbay.jetty.Request.getReader(Request.java:935)
Hmmm....
Guillaume
Guillaume
I was not properly "posting" my json payload to my groovlet.
Whether it's behind a URL route or not, doesn't matter, in both cases
I managed to make things work, without getting that ugly exception.
Soooo without further ado.
In my groovlet, I have that content:
def content = request.reader.text
System.out.println "Content: $content"
That way, I can see in the console the content I receive.
You can also use request.inputStream.text, and it works, but because
of possible encoding issues, it's better to use the reader instead, as
it should try its best to use the proper encoding.
Then, from the command-line, with curl, I do:
curl -v -H "Content-Type: application/json" -X POST -d
'{"screencast":{"subject":"tools"}}'
http://localhost:8080/receivejson.groovy
And I properly receive the content, and it's printed on the console,
so all's working fine.
I think it all depends on how you send your payload to the groovlet.
I'm not a curl expert, but I found some help on StackOverflow, with
one of the various options folks had submitted:
http://stackoverflow.com/questions/813487/how-to-post-json-to-php-with-curl
Guillaume
Hope this helps.
Guillaume
I suspect (but not sure 100%) that it's the blobstore filter that does
this, as uploaded files for the blobstore are submitted through forms.
So it certainly calls the getInputStream() to see if there's an
uploaded file, and the magic key expected by the filter (when we
create an upload url).
And then, when you call the reader on the request, too bad, the input
stream had already been acquired, so you can't open the reader
afterwards, and you get that very unhelpful error from Jetty.
> Thanks for the tip of how to get the content:
> def content = request.reader.text
> That will make my code much more groovy.. :.-)
Yeah, I like to teach some cool shortcuts, that makes the code much
more readable and more maintainable in the long run!
Guillaume