This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Forcibly closing an http connection

 
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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 VI Editor Redhat
  • 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?
 
I think I'll just lie down here for a second. And ponder this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!