File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Idempotence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Idempotence " Watch "Idempotence " New topic
Author

Idempotence

Elan Ram
Ranch Hand

Joined: Dec 14, 2006
Posts: 40
According to HTTP/1.1 Spec,

1) Safe Methods are GET and HEAD.
2) Unsafe Methods are POST, PUT and DELETE.
3) Idempotent Methods - GET, HEAD, PUT, OPTIONS, TRACE and DELETE

My doubt is How come PUT and DELETE are Idempotent methods, if they are not safe?


Thanks and regards,
Elan
Sayak Banerjee
Ranch Hand

Joined: Nov 28, 2006
Posts: 292
Post your question HERE


Turn on, tune in, drop out.
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
yes


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
If a method is defined as SAFE (e.g. HEAD or GET), it means that they are intended only for information retrieval and should not change the state of the server in any way. In other words, they should not have any side effects at all.

Unsafe methods (like POST, PUT and DELETE) will change the state of the server. POST submits data to be processed. PUT uploads a resource. DELETE deletes a specific resource.

And then there is the concept of idempotent methods. To be idempotent simply means that multiple identical requests should have the same effect as a single request. A safe method is inherently idempotent because it does not change server state. You can't have a negative side effect if there are no side effects at all. Easy enough. Where it gets confusing is when we get into the unsafe methods. Let consider them.

If you have a PUT method, you are basically saying that you have something you want to upload to the server. If you do this once, the resource will exist on the server. If you do this ten times, the file will still exist on the server. No negative side effects, so therefore the method is idempotent.

If you use a DELETE method, you are removing a specified resource from a server. If you run it once, then the resource (if it existed at all) will no longer exist on the server. If you run it ten times... well, it still doesn't exist on the server. No negative side effects, therefore the method is idempotent.

If you have a POST method, then you are sending data to be processed. If you run it once, the data is processed on the server. The server state can be changed based on both the data supplied and the current state of the server. If you run it ten times, the way the data is processed can change each and every time, possible resulting in negative side effects. Therefore the method is idempotent.

I hope that helped. This was a pretty confusing area for me too. If you would like, I can post examples of all three to further explain.
[ December 19, 2006: Message edited by: Paul Bourdeaux ]

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Elan Ram
Ranch Hand

Joined: Dec 14, 2006
Posts: 40
Im clear now. Thanks.
Sayak Banerjee
Ranch Hand

Joined: Nov 28, 2006
Posts: 292
If you have a POST method, then you are sending data to be processed. If you run it once, the data is processed on the server. The server state can be changed based on both the data supplied and the current state of the server. If you run it ten times, the way the data is processed can change each and every time, possible resulting in negative side effects. Therefore the method is idempotent.


I think that's a mistake....that should be non-idempotent

But it's really well-explained
[ December 19, 2006: Message edited by: Sayak Banerjee ]
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
Paul Bourdeaux Saying,

No negative side effects, so therefore the method is idempotent.


If you run it ten times, the way the data is processed can change each and every time, possible resulting in negative side effects. Therefore the method is idempotent.


How is it possible No negative side effects and negative side effects are idempodent.


SCJP 5.0<br />SCWCD 1.4<br />Preparing for <b>SCEA</b>.<br /><b>"I prefer an interesting vice to a virtue that bores."</b>
Sayak Banerjee
Ranch Hand

Joined: Nov 28, 2006
Posts: 292
That's why I suggested the correction....if that's done, everything else is fine
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
Yes Sayak Banerjee, but i sow your reply only after i send my reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Idempotence