tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steffen Heil (Mailinglisten)" <>
Subject How to cancel upload?
Date Fri, 19 Aug 2011 13:37:19 GMT

Short question: How can I prevent tomcat to receive the complete post data?

Long question:

I have a servlet that uses apache commons fileupload to process incoming
uploads using the streaming api.
Short version of the code:

InputStream inputStream;
try {
	ServletFileUpload upload = new ServletFileUpload();
	iterator = upload.getItemIterator( request );
	if ( ! iterator.hasNext() )
	FileItemStream item =;
	if ( item.isFormField() || ! "file".equals( item.getFieldName() ) )
	inputStream = item.openStream();
	use( inputStream )
} finally {
	try {
	} catch ( Throwable ignored ) {
		// just ignore

Now, the method use(InputStream) may decide that this file is not wanted and
may NOT read the inputstream fully. Or there may be more field, that I am
not interested in. I want to abort reading the request, as there may be
several hundred megabytes of data coming.

However inputStream.close() in FileItemStream seams to read everything that
follows. So I tried not to close that steam. Still some component read
everything, I suspect tomcat did so - to allow keepalive connections. Then I
tried to throw an IOException, but no change.

So my question is: How can I prevent tomcat to receive the complete post


View raw message