You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Gareth Williams <GW...@voxgen.com> on 2005/04/15 14:41:41 UTC

Can't multipart post large(ish) files via Tomcat 5.0.28

Hi, I am attempting to add file uploading to an app running under Jboss
3.2.6 + Tomcat 5.0.28.  
Started off using com.oreilly.servlet.MultipartRequest, and found
problems uploading large >8KB files

Decided to investigate by writing my own class that does nothing except
read any available bytes from the HttpServletRequest's input stream
(i.e. for now, I don't actually care about any the content uploaded,
just the quantity)... 

public class MyStreamReader {

    private static final Logger log =
Logger.getLogger(MyStreamReader.class);

    private InputStream inputStream;

    private byte[] buf = new byte[1024];
    
    public MyStreamReader(HttpServletRequest request) throws IOException
{
        log.debug("REQUEST CLASS: " + request.getClass().getName());
        this.inputStream = request.getInputStream();
        log.debug("INPUT STREAM CLASS: " +
inputStream.getClass().getName());
    }
    
    public void parse() throws IOException {
        int totalBytesRead = 0;
        
        boolean isEndOfStream = false;
        while (!isEndOfStream) {
            
            /* Do not use available() as it always returns 0!
             * int available = inputStream.available(); 
             * log.debug("available: " + available);
             */
            
            // Try reading 1 byte at a time (yawn)
		int bytesRead = readSingleByte();
            // Inconsistent behaviour also results from >>> int
bytesRead = readIntoByteArray();

            if (bytesRead > 0) {
                totalBytesRead += bytesRead;
            }
            else {
                isEndOfStream = (bytesRead == -1);
            }
        }
        log.debug("Reached END OF STREAM.");
        log.debug("TOTAL BYTES READ: " + totalBytesRead);
    }
    
    int readIntoByteArray() throws IOException {
        return inputStream.read(buf);
    }
    
    int readSingleByte() throws IOException {
        int byteValue = inputStream.read();
        return (byteValue == -1) ? -1 : 1;
    }
}

I then attempted to repeatedly upload a 961KB text file...the log output
is as follows:

2005-04-15 12:02:36,072 DEBUG
[com.voxgeneration.campaign.gui.VoxServlet]  - processing multi-part
request...
2005-04-15 12:02:36,072 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] REQUEST CLASS:
org.apache.coyote.tomcat5.CoyoteRequestFacade
2005-04-15 12:02:36,072 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] INPUT STREAM CLASS:
org.apache.coyote.tomcat5.CoyoteInputStream
2005-04-15 12:02:36,072 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] Reached END OF STREAM.
2005-04-15 12:02:36,072 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] TOTAL BYTES READ:
36172
2005-04-15 12:02:36,072 ERROR
[com.voxgeneration.campaign.gui.CampaignServlet]  - hmmm...upload
failed.

2005-04-15 12:02:42,948 DEBUG
[com.voxgeneration.campaign.gui.VoxServlet]  - processing multi-part
request...
2005-04-15 12:02:42,948 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] REQUEST CLASS:
org.apache.coyote.tomcat5.CoyoteRequestFacade
2005-04-15 12:02:42,948 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] INPUT STREAM CLASS:
org.apache.coyote.tomcat5.CoyoteInputStream
2005-04-15 12:02:42,963 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] Reached END OF STREAM.
2005-04-15 12:02:42,963 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] TOTAL BYTES READ:
37104
2005-04-15 12:02:42,963 ERROR
[com.voxgeneration.campaign.gui.CampaignServlet]  - hmmm...upload
failed.

2005-04-15 12:15:31,084 DEBUG
[com.voxgeneration.campaign.gui.VoxServlet]  - processing multi-part
request...
2005-04-15 12:15:31,084 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] REQUEST CLASS:
org.apache.coyote.tomcat5.CoyoteRequestFacade
2005-04-15 12:15:31,084 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] INPUT STREAM CLASS:
org.apache.coyote.tomcat5.CoyoteInputStream
2005-04-15 12:15:31,084 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] Reached END OF STREAM.
2005-04-15 12:15:31,084 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] TOTAL BYTES READ:
37006
2005-04-15 12:15:31,084 ERROR
[com.voxgeneration.campaign.gui.CampaignServlet]  - hmmm...upload
failed.

2005-04-15 12:15:36,490 DEBUG
[com.voxgeneration.campaign.gui.VoxServlet]  - processing multi-part
request...
2005-04-15 12:15:36,490 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] REQUEST CLASS:
org.apache.coyote.tomcat5.CoyoteRequestFacade
2005-04-15 12:15:36,490 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] INPUT STREAM CLASS:
org.apache.coyote.tomcat5.CoyoteInputStream
2005-04-15 12:15:36,506 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] Reached END OF STREAM.
2005-04-15 12:15:36,506 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] TOTAL BYTES READ:
37007
2005-04-15 12:15:36,506 ERROR
[com.voxgeneration.campaign.gui.CampaignServlet]  - hmmm...upload
failed.

2005-04-15 12:15:41,256 DEBUG
[com.voxgeneration.campaign.gui.VoxServlet]  - processing multi-part
request...
2005-04-15 12:15:41,256 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] REQUEST CLASS:
org.apache.coyote.tomcat5.CoyoteRequestFacade
2005-04-15 12:15:41,256 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] INPUT STREAM CLASS:
org.apache.coyote.tomcat5.CoyoteInputStream
2005-04-15 12:15:41,256 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] Reached END OF STREAM.
2005-04-15 12:15:41,256 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] TOTAL BYTES READ:
36174
2005-04-15 12:15:41,256 ERROR
[com.voxgeneration.campaign.gui.CampaignServlet]  - hmmm...upload
failed.

2005-04-15 12:15:45,428 DEBUG
[com.voxgeneration.campaign.gui.VoxServlet]  - processing multi-part
request...
2005-04-15 12:15:45,428 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] REQUEST CLASS:
org.apache.coyote.tomcat5.CoyoteRequestFacade
2005-04-15 12:15:45,428 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] INPUT STREAM CLASS:
org.apache.coyote.tomcat5.CoyoteInputStream
2005-04-15 12:15:45,428 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] Reached END OF STREAM.
2005-04-15 12:15:45,428 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] TOTAL BYTES READ:
32905
2005-04-15 12:15:45,428 ERROR
[com.voxgeneration.campaign.gui.CampaignServlet]  - hmmm...upload
failed.

So, each time tomcat seems to think the stream ends (and not always at
the same point), also this after only 30KB have been read.  Browser:
Firefox 1.0.2

Then thought I'd resort to IE6 and see what happended...

2005-04-15 13:29:35,006 DEBUG
[com.voxgeneration.campaign.gui.VoxServlet]  - processing multi-part
request...
2005-04-15 13:29:35,006 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] REQUEST CLASS:
org.apache.coyote.tomcat5.CoyoteRequestFacade
2005-04-15 13:29:35,006 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] INPUT STREAM CLASS:
org.apache.coyote.tomcat5.CoyoteInputStream
2005-04-15 13:29:35,006 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] Reached END OF STREAM.
2005-04-15 13:29:35,006 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] TOTAL BYTES READ: 0
2005-04-15 13:29:35,006 ERROR
[com.voxgeneration.campaign.gui.CampaignServlet]  - hmmm...upload
failed.
... ...
2005-04-15 13:29:40,819 DEBUG
[com.voxgeneration.campaign.gui.VoxServlet]  - processing multi-part
request...
2005-04-15 13:29:40,819 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] REQUEST CLASS:
org.apache.coyote.tomcat5.CoyoteRequestFacade
2005-04-15 13:29:40,819 DEBUG
[com.voxgeneration.utilities.http.MyStreamReader] INPUT STREAM CLASS:
org.apache.coyote.tomcat5.CoyoteInputStream
2005-04-15 13:29:40,819 WARN
[com.voxgeneration.campaign.gui.VoxServlet]  - upload failed.
java.net.SocketException: Connection reset
	at java.net.SocketInputStream.read(SocketInputStream.java:168)
	at
org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.ja
va:747)
	at
org.apache.coyote.http11.InternalInputBuffer$InputStreamInputBuffer.doRe
ad(InternalInputBuffer.java:777)
	at
org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInpu
tFilter.java:115)
	at
org.apache.coyote.http11.InternalInputBuffer.doRead(InternalInputBuffer.
java:712)
	at org.apache.coyote.Request.doRead(Request.java:429)
	at
org.apache.coyote.tomcat5.InputBuffer.realReadBytes(InputBuffer.java:290
)
	at
org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:341)
	at
org.apache.coyote.tomcat5.InputBuffer.readByte(InputBuffer.java:299)
	at
org.apache.coyote.tomcat5.CoyoteInputStream.read(CoyoteInputStream.java:
91)
	at
com.voxgeneration.utilities.http.MyStreamReader.readSingleByte(MyStreamR
eader.java:57)
	at
com.voxgeneration.utilities.http.MyStreamReader.parse(MyStreamReader.jav
a:40)
	at
com.voxgeneration.campaign.gui.VoxServlet.processMultipartPost(VoxServle
t.java:127)
	at
com.voxgeneration.campaign.gui.CampaignServlet.uploadFile(CampaignServle
t.java:224)
	at
com.voxgeneration.campaign.gui.CampaignServlet.execute(CampaignServlet.j
ava:68)
	at
com.voxgeneration.campaign.gui.VoxServlet.doPost(VoxServlet.java:54)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:237)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:157)
	at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilte
r.java:75)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:186)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:157)
	at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:214)
	at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
ntext.java:104)
	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
20)
	at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCon
textValve.java:198)
	at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:152)
	at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
ntext.java:104)
	at
org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipa
lValve.java:66)
	at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
ntext.java:102)
	at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAs
sociationValve.java:158)
	at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
ntext.java:102)
	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
20)
	at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:137)
	at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
ntext.java:104)
	at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:118)
	at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
ntext.java:102)
	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
20)
	at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:109)
	at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo
ntext.java:104)
	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
20)
	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
	at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
	at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:79
9)
	at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processC
onnection(Http11Protocol.java:705)
	at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:57
7)
	at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool
.java:683)
	at java.lang.Thread.run(Thread.java:534)

So with IE, after the first upload I got zero bytes, after the 2nd
upload I got the exception & stack trace shown above.  Different
behaviour but it's still not gonna help me write my file uploader :)

Any advice/assistance very much appreciated, i do not really have time
to poke around in the tomcat source at the moment also we are tied to
Jboss 3.2.6 so I do not think we can upgrade to a more recent tomcat
release (at least not quickly without much testing).

Anyone here experienced the same issues?

TIA

Gareth

#####################################################################################
Winner - e-Government excellence 2004. 
Runner up - European Information Management awards 2004:
- The Premier Project Award. 
- B2C Commerce Project Award. 
- CRM Project Award. 

For more information visit us at www.voxgen.com

#####################################################################################
Note:
This message is for the named person's use only.  It may contain confidential,
proprietary or legally privileged information.  No confidentiality or privilege
is waived or lost by any mistransmission.  If you receive this message in error,
please immediately delete it and all copies of it from your system, destroy any
hard copies of it and notify the sender.  You must not, directly or indirectly,
use, disclose, distribute, print, or copy any part of this message if you are not
the intended recipient. Vox Generation Limited and any of its subsidiaries each 
reserve the right to monitor all e-mail communications through its networks.

Any views expressed in this message are those of the individual sender, except where
the message states otherwise and the sender is authorised to state them to be the
views of any such entity.

Thank You.
#####################################################################################

#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared 
by NetIQ MailMarshal
#####################################################################################

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org