| Author |
Checksum file download?
|
Glenn Murray
Ranch Hand
Joined: Dec 07, 2001
Posts: 74
|
|
Hi, I have a servlet newbie question. I have a servlet which gets a file name from a client and sends it the file. I would like to add a checksum feature so that the servlet can delete the file if it is sure that the client has received the file correctly. The client can compute a checksum when it writes the file. What is the best way to inform the servlet? A "java.net.ProtocolException: Cannot write output after reading input" occurred in the client when I tried to send the checksum after reading the file. Do I have to use an entire different servlet to do this? Many thanks, Glenn
|
Glenn Murray
Author of Yo Soy Una Vaca De Hoy
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12267
|
|
If I understand what you are after - it will take a second cycle of request - response to have the client inform the servlet. With a keep-alive connection this should be quite fast. Bill
|
 |
Glenn Murray
Ranch Hand
Joined: Dec 07, 2001
Posts: 74
|
|
If I understand what you are after - it will take a second cycle of request - response to have the client inform the servlet. With a keep-alive connection this should be quite fast. Bill Hi Bill, Thanks for the reponse. I'm a little confused about the keep-alive business. I looked up keep-alive connections and learned that I can keep the connection alive from the servlet by using ServletResponse.setContentLength(int) in the header. But it seems that I need to do this from the client: the client gets the file, computes a checksum, and now wants to inform the sending servlet of this checksum. What exactly do you mean by a "second cycle of request-response"? Do you mean something different than a keep-alive connection? Thanks much, Glenn
|
 |
D Rog
Ranch Hand
Joined: Feb 07, 2004
Posts: 471
|
|
|
In my understanding http is stateless protocol in form of request-response, so you can't do it in a way like request-response-request as one transaction. I'd create something like transaction id for every file download. So, if a client consider download Ok, then a client issues another request to a servlet with a given transaction id, so a servlet can get it and delete a corresponding file. Of course you have a small risk that some file won't be deleted even in case when a client successfully got them.
|
Get power of your iPod with MediaChest | Minimal J2EE container is here | Light weight full J2EE stack | My blog | Co-author of "Windows programming in Turbo Pascal"
|
 |
Glenn Murray
Ranch Hand
Joined: Dec 07, 2001
Posts: 74
|
|
Originally posted by D Rog: ... I'd create something like transaction id for every file download. So, if a client consider download Ok, then a client issues another request to a servlet with a given transaction id, so a servlet can get it and delete a corresponding file...
Hi D, Thanks for the response. Yes, I think the "stateless" part of http is the problem, here. I've decided to implement the deletion in a separate servlet. Note that the file name and a checksum together are already a transaction id, more or less. I'll have the server create a checksum file when the download happens, using CheckedOutputStream. The delete servlet can find files by name easily, and then use the checksum value to verify which file to delete. Cheers, Glenn
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Checksum file download?
|
|
|