aspose file tools*
The moose likes JSP and the fly likes Forcibly closing an http connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Forcibly closing an http connection" Watch "Forcibly closing an http connection" New topic
Author

Forcibly closing an http connection

Tim Koop
Greenhorn

Joined: Jun 23, 2005
Posts: 8
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


Tim Koop
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The return; statement doesn't do it for you?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Tim Koop
Greenhorn

Joined: Jun 23, 2005
Posts: 8
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

Joined: Dec 11, 2004
Posts: 13410

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Forcibly closing an http connection