Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

POST method - unintended side effects

 
Anand Wadhwani
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question sounds me very confusing:

Which of the following HTTP protocol methods is eligible to produce unintended side effects upon multiple identical invocations beyond those caused by single invocation?

a. GET
b. POST
c. HEAD
d. PUT
e. OPTIONS

The answer to this is (b).


Could somebody please explain about PUT method? Does this method not have any unintended side effects, i.g. multiple invokation may upload the same file again and again, or I am wrong in thinking that PUT method is used to upload a file. Could somebody please explain PUT, DELETE, OPTIONS methods with some practical examples, I dont know how do I send such methods/requests from html ?

I know this question may sound stupid, but I really want to understand what is the purpose of other http methods, I recognize the significance of GET/POST only. Also I am getting lazy in reading the specs, want to see some practical use of other 5 methods.

Thanks!
[ April 24, 2005: Message edited by: Anand Wadhwani ]
 
chowdary Thammineedi
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Anand,

seems to me you are getting confused with the terms Idempotent and non-Idempotent.

Keep it simple. The various Http methods are strictly (well almost) constrained to do what their names suggest.

GET - get me this thing and do nothing else
PUT - put this thing and do nothing else.
DELETE - delete this thing and do nothing else

POST - Take this data and charge my credit card.
Also you can store it and make it available to hackers, and then
get away with it.

Idempotency does not refer to the action being performed but rather to the side effects.

PUT does not have a side effect. It does what it is supposed to do. Put a resource on the server. It's not allowed to do anything else, which the user can be held responsible for.Hence, it is Idempotent.

More on PUT here
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6

In HTTP 1.1 only POST is allowed to have side effects.

This is what the HTTP 1.1 RFC 2616 says about Idempotency


9.1.2 Idempotent Methods
Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request. The methods GET, HEAD, PUT and DELETE share this property. Also, the methods OPTIONS and TRACE SHOULD NOT have side effects, and so are inherently idempotent.

However, it is possible that a sequence of several requests is non- idempotent, even if all of the methods executed in that sequence are idempotent. (A sequence is idempotent if a single execution of the entire sequence always yields a result that is not changed by a reexecution of all, or part, of that sequence.) For example, a sequence is non-idempotent if its result depends on a value that is later modified in the same sequence.

A sequence that never has side effects is idempotent, by definition (provided that no concurrent operations are being executed on the same set of resources).



Read all about it here. This is the OFFICIAL word.
Should take only 10 mins.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9
 
Anand Wadhwani
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chawdary, I appreciate the theory very much.

But, it would be very good if you can share with me some code that demostrates how PUT works. Can I use this in HTML, something like:

Is it equivalent to FTPing a file, but then FTP is a different protocol all together!

Thanks for your time & help!
 
chowdary Thammineedi
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Anand

Of course you can. If your form says that the method to be used is PUT, then the HttpServlet's service() method will definitely call your doPut() method.

Now, in your doPut() method you'd better use a getInputStream() of the ServletRequest interface to get the raw binary data and then store them as requested under the requested name.

More info on InputStream
http://java.sun.com/j2se/1.5.0/docs/api/index.html
Browse to java.io.InputStream class

May be you can use FTP protocol to upload files, Why not try FTP to generate Dynamic pages?

Dont both FTP and HTTP use TCP as the underlying mechanism?
[ April 24, 2005: Message edited by: chowdary Thammineedi ]
 
Anand Wadhwani
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry I dont understand this. The method attribute of form tag in html supports only GET / POST method.

http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/method.asp?frame=true

Still, per your confidence I wrote that html and servlet with doPut method to simulate file upload but I got error page (405) saying "HTTP method GET is not supported by this URL", this happened as method=put was not recognized by IE and default GET method was sent to server.

Also please explain how FTP can be used for generating dynamic pages !!! I am surprised on two things, either I am sounding too stupid on my problem, or you must be kidding with me.

Anybody else, PLEASE HELP!
preferably, with some practical examples
 
chowdary Thammineedi
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP 1.1 requires that GET and HEAD requests MUST be supported by EVERY server.

The rest of them are OPTIONAL.

You can add values to the header "Allow" to indicate the methods supported.

If IE does not care about the Allow headers it's IE's own problem and Not with protocols, perhaps.

IE does not care even when the Allow headers are set. Moreover, it can do that, without violating any rules.

Allow is explained clearly here.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7

BTW what can you not do in a doPost(), that you can do in a doPut() through the API's?

How are Dynamic Pages generated through FTP? I was asking you that.
[ April 25, 2005: Message edited by: chowdary Thammineedi ]
 
Debashish Chakrabarty
Ranch Hand
Posts: 231
Firefox Browser Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by chowdary Thammineedi:

Of course you can. If your form says that the method to be used is PUT, then the HttpServlet's service() method will definitely call your doPut() method. Now, in your doPut() method you'd better use a getInputStream() of the ServletRequest interface to get the raw binary data and then store them as requested under the requested name.

May be you can use FTP protocol to upload files, Why not try FTP to generate Dynamic pages? Dont both FTP and HTTP use TCP as the underlying mechanism?

Anand, modern browsers would hardly do anything meaningful with methods other than GET and POST. But you are right, technically PUT is akin to FTP, still you would rather use other means to upload files. See the FAQ here and the excellent detail here. It is always better to Google buddy.
[ April 26, 2005: Message edited by: Debashish Chakrabarty ]
 
Anand Wadhwani
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really appreciate your responses and time, but I really feel pitied about finding a real answer to this question. Believe me, I do recognize the difference between each HTTP methods; what I dont understand is the client use of the 5 http methods (TRACE/OPTIONS/HEAD/PUT/DELETE).

Let me put my question this way:

I have a servlet which implements doPut() method. Now could anyone please send me a client code for this servlet? Defnitely that can't be html because IE does not support method=put in form element. Then would it a program that makes use of URLConnection API and use HTTP methods like PUT/DELETE etc.

In terms of practical use of PUT method, here is what I recently read somewhere:


PUT is used to send data that is to be associated with a given URL. For example, if you PUT a file named a.html (on local machine) to a url http://www.myserver.com/b.html, then the contents of a.html will be stored on the server and will be made accessible through the URL of http://www.myserver.com/b.html. This feature is used mainly by site builder tools.


But still I am curious to see some practical client-side code that uses HTTP PUT/DELETE/OPTIONS/HEAD/TRACE methods.

Please forgive me if I seem to be bothering a lot you guys. All I meant to share with my rancher friends is the thing what's bugging me.

Debashish, your FAQ links dont seem to be correct, those are showing me nothing but api details of HttpServlet class.

Thanks Much!
[ April 25, 2005: Message edited by: Anand Wadhwani ]
 
chowdary Thammineedi
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Debashish, are we sure that your client recognizes "Allow" headers that come along with a "405", method not found error and mandated by the HTTP spec.

As far as I know

The "Allow" header is categorized as an "Entity Header" by the HTTP 1.1 spec meaning that it does not need to be recognized by a client UNLESS the client has a contract with the server about recognizing such headers.

Nonetheless, according to the Servlet 2.4 spec's Reference Implementation the HttpServlet CANNOT ignore the Method PUT, If it has been requested.

Tomcat's HttpServlet class Implements service() method as follows



I, can clearly see that the service method will (I should perhaps say MUST) call your doPut() method in a rather "DOLT" manner if it has been "REQUESTED".

Can you pleease explain why this is "DOLT"?

Anand and me are trying to understand the HTTP protocol's implementation by the Servlet And JSP technolgy. Not by "Modern Browsers".
[ April 25, 2005: Message edited by: chowdary Thammineedi ]
 
Debashish Chakrabarty
Ranch Hand
Posts: 231
Firefox Browser Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anand,

The FAQ link is http://www.jguru.com/faq/view.jsp?EID=236578. I have corrected my previous post also. OK so you have another 'detailed' answer, cool

No pun Chowdhuryji, but it is always better to get the questions first and then reply what the poser wants. Anand wants to know how methods such as doPut are used in "real-world". We all have read tons on about how it works. Hence the mention of "modern browsers", to imply that presently we don't do anything meaningful with these methods except GET and POST, except perhaps when you would want to implement a custom protocol.
 
Anand Wadhwani
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Debashish. Really appreciate your patience of understanding my problem in right fashion. I am sorry for responding so late, I had gone out of town so I lost touch!

The jguru link sent by you is not working, please advise how do I navigate to it.

I would see if I find something on PUT usage and post when I find. Thanks a lot anayway!

-ANAND
SCJP, SCWCD(preparing)
[ May 03, 2005: Message edited by: Anand Wadhwani ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic