Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forcibly closing an http connection

 
Tim Koop
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.

Does anybody know how, in a jsp or servlet, to forcibly close the http connection so the client (browser) shows some sort of page saying the server closed the connection?

For those of you who will want to know why I need to do this, I'll tell you. We have a file upload page and we want to set a maximum limit. I have already figured out how to do this with commons fileUpload, and that works fine, but after I detect the fact that the user is sending us way too much data, I want to close the connection. It just saves bandwidth charges this way.

I've tried request.getInputStream().close(), but that doesn't seem to do it.

Any other ideas?

Thanks in advance.

--
Tim
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return; statement doesn't do it for you?
 
Tim Koop
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
The return; statement doesn't do it for you?


No it doesn't. When I start uploading a large file, the code quickly detects that it has exceeded the maximum limit (if the maximum limit is small enough). I can even write a note to the log saying that the limit has been reached and we should close the connection, but the complete file still gets uploaded the whole way even long after we don't want to listen any more. I want to get a hold of the tcp socket and close that connection, or tell someone else to please close it for me because I'm not going to listen any more.

--
Tim
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set the maxSize property of the ServletFileUpload class?
http://jakarta.apache.org/commons/fileupload/apidocs/org/apache/commons/fileupload/FileUploadBase.html#setFileSizeMax(long)

I would think that it would throw an exception once the inputstream exceeds that setting.

http://jakarta.apache.org/commons/fileupload/apidocs/org/apache/commons/fileupload/FileUploadBase.FileSizeLimitExceededException.html

Are you, maybe, catching this exception and suppressing it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic