HTTP request params in a PUT never reach the controller

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

HTTP request params in a PUT never reach the controller

matthias_k
Hi,

I am implementing a RESTy service API backed by a Grails controller. In my
URLMappings.groovy I map the different HTTP verbs to actions in that controller.

GET and POST work fine, but as soon as I map PUT to an action, any request
parameters sent in a PUT go poof somewhere on the road.

Ex.:

curl -X PUT --trace-ascii http_dump.txt http://localhost:8080/app/api/users -d
"userId=5"

trace:

== Info: About to connect() to localhost port 8080 (#0)
== Info:   Trying 127.0.0.1... == Info: connected
== Info: Connected to localhost (127.0.0.1) port 8080 (#0)
=> Send header, 239 bytes (0xef)
0000: PUT /app/api/users HTTP/1.1
0023: User-Agent: curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenS
0063: SL/0.9.8g zlib/1.2.3.3 libidn/1.1
0086: Host: localhost:8080
009c: Accept: */*
00a9: Content-Length: 8
00bc: Content-Type: application/x-www-form-urlencoded
00ed:
=> Send data, 8 bytes (0x8)
0000: userId=5

so, the data is correctly sent to the web app.

The action mapped to that verb/Url is called correctly (I set a breakpoint), but
params is always the empty map and binding command objects fails as well (fields
are left to null).

Am I missing something?

Thanks,
Matthias


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: HTTP request params in a PUT never reach the controller

Dustin Whitney
I remember running into this problem a while ago and finding out that the java servlet spec doesn't support PUT.   You ought to look over the Restlet library (http://www.restlet.org/).  If nothing else, it will give you some insight into your problem and a possible solution.

-Dustin

On Sat, May 31, 2008 at 2:09 PM, Matthias <[hidden email]> wrote:
Hi,

I am implementing a RESTy service API backed by a Grails controller. In my
URLMappings.groovy I map the different HTTP verbs to actions in that controller.

GET and POST work fine, but as soon as I map PUT to an action, any request
parameters sent in a PUT go poof somewhere on the road.

Ex.:

curl -X PUT --trace-ascii http_dump.txt http://localhost:8080/app/api/users -d
"userId=5"

trace:

== Info: About to connect() to localhost port 8080 (#0)
== Info:   Trying 127.0.0.1... == Info: connected
== Info: Connected to localhost (127.0.0.1) port 8080 (#0)
=> Send header, 239 bytes (0xef)
0000: PUT /app/api/users HTTP/1.1
0023: User-Agent: curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenS
0063: SL/0.9.8g zlib/1.2.3.3 libidn/1.1
0086: Host: localhost:8080
009c: Accept: */*
00a9: Content-Length: 8
00bc: Content-Type: application/x-www-form-urlencoded
00ed:
=> Send data, 8 bytes (0x8)
0000: userId=5

so, the data is correctly sent to the web app.

The action mapped to that verb/Url is called correctly (I set a breakpoint), but
params is always the empty map and binding command objects fails as well (fields
are left to null).

Am I missing something?

Thanks,
Matthias


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: HTTP request params in a PUT never reach the controller

matthias_k
Hi Dustin,

Dustin Whitney <dustin.whitney <at> gmail.com> writes:

> I remember running into this problem a while ago and finding out that the java
servlet spec doesn't support PUT. [...]

I don't think that is true. HTTPServlet provides a doPut() method, see
http://tinyurl.com/5ejgvf

Plus, why would the Grails people set up instructions about how to create
RESTful Web-services with Grails, if it's not actually supported? See
http://grails.org/doc/1.0.x/guide/single.html#13.1%20REST

Here it explicitly says:

"To support updates such as PUT and POST you can use the params object which
Grails enhances with the ability to read an incoming XML packet."

just that it doesn't work with PUT, only with POST.

Best,
Matthias


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Re: HTTP request params in a PUT never reach the controller

Dustin Whitney
Oh, you're totally right, I was thinking of the HTML 4.0 form element (http://www.w3.org/TR/html401/interact/forms.html#h-17.3) which does not support PUT.  Drat!  I hate being the source of misinformation!

-Dustin

On Sat, May 31, 2008 at 2:55 PM, Matthias <[hidden email]> wrote:
Hi Dustin,

Dustin Whitney <dustin.whitney <at> gmail.com> writes:

> I remember running into this problem a while ago and finding out that the java
servlet spec doesn't support PUT. [...]

I don't think that is true. HTTPServlet provides a doPut() method, see
http://tinyurl.com/5ejgvf

Plus, why would the Grails people set up instructions about how to create
RESTful Web-services with Grails, if it's not actually supported? See
http://grails.org/doc/1.0.x/guide/single.html#13.1%20REST

Here it explicitly says:

"To support updates such as PUT and POST you can use the params object which
Grails enhances with the ability to read an incoming XML packet."

just that it doesn't work with PUT, only with POST.

Best,
Matthias


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: HTTP request params in a PUT never reach the controller

Peter Ledbrook
In reply to this post by matthias_k
> GET and POST work fine, but as soon as I map PUT to an action, any request
> parameters sent in a PUT go poof somewhere on the road.

It's possible that the servlet container will not parse PUT data as if
it's POST data. I assume that if you use the URL:

  http://localhost:8080/app/api/users?userId=5

then "userId" will appear in the "params" object. However, Grails
handles the parsing of XML and JSON requests, so it you were to send
your parameters as XML, they would probably appear in the "params"
instance.

Cheers,

Peter

--
Software Engineer
G2One, Inc.
http://www.g2one.com/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: HTTP request params in a PUT never reach the controller

rmachado
Hi,

I have the same problem. I need that the PUT body is read, and apparently it is not reading it.
I am using grails 1.3.7...any ideas???

Thanks,

Rodrigo
Reply | Threaded
Open this post in threaded view
|

Re: HTTP request params in a PUT never reach the controller

Jonathan Rosenberg
I remember running into this problem long ago with Tomcat.  I think it
has something to do with how PUT parameters are handled by the app
server.  Tomcat does not parse the parameters and put them in the
request, if I recall.

I think I worked around this by adding a Grails filter, but my memory
is foggy and I can't find the code right now.

--
Jonathan Rosenberg
Founder & Executive Director
Tabby's Place, a Cat Sanctuary
http://www.tabbysplace.org/


On Tue, Mar 6, 2012 at 9:01 AM, rmachado <[hidden email]> wrote:

> Hi,
>
> I have the same problem. I need that the PUT body is read, and apparently it
> is not reading it.
> I am using grails 1.3.7...any ideas???
>
> Thanks,
>
> Rodrigo
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/HTTP-request-params-in-a-PUT-never-reach-the-controller-tp1353329p4449931.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: HTTP request params in a PUT never reach the controller

rmachado
Thanks Jonathan.

Was it something like this?
http://stackoverflow.com/questions/1046721/accessing-the-raw-body-of-a-put-or-post-request

I will try it an post again if it works
Reply | Threaded
Open this post in threaded view
|

Re: HTTP request params in a PUT never reach the controller

Jonathan Rosenberg
Yes, though I seem to recall much less code.

Try posting to the Tomcat user group.

--
Jonathan Rosenberg
Founder & Executive Director
Tabby's Place, a Cat Sanctuary
http://www.tabbysplace.org/


On Tue, Mar 6, 2012 at 11:56 AM, rmachado <[hidden email]> wrote:

> Thanks Jonathan.
>
> Was it something like this?
> http://stackoverflow.com/questions/1046721/accessing-the-raw-body-of-a-put-or-post-request
>
> I will try it an post again if it works
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/HTTP-request-params-in-a-PUT-never-reach-the-controller-tp1353329p4450529.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email