• Post Reply Bookmark Topic Watch Topic
  • New Topic

Checksum file download?

 
Glenn Murray
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Glenn Murray
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!