On 19/08/2011 14:37, Steffen Heil (Mailinglisten) wrote:
> Hi
> 
> Short question: How can I prevent tomcat to receive the complete post data?

Stop sending the data before it's all been sent.

> 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() )
>               return;
>       FileItemStream item = iterator.next();
>       if ( item.isFormField() || ! "file".equals( item.getFieldName() ) )
>               return;
>       inputStream = item.openStream();
>       use( inputStream )
> } finally {
>       try {
>               inputStream.close();
>       } 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
> data?

AFAIK Tomcat processes the request before the user code in a servlet is
active, so you can't do it from inside a servlet.

Someone will correct me if I'm wrong...


p


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to