tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stewart, Daniel J" <>
Subject RE: Tomcat sucks at receiving large messages
Date Thu, 02 Oct 2003 16:37:36 GMT
This code will be running in a controlled environment, with known
clients, where the largest message size is known (~10M).  This code
takes the entire body and forwards it on to another messaging system, so
I have no choice but to deal with the entire message.  And I can't read
it a byte or line at a time, because it would take too long.

Take a look at my other response to this subject to see the code that
fixed my problem.  I am open to any other suggestions....


-----Original Message-----
From: Walker Chris [] 
Sent: Wednesday, October 01, 2003 1:21 AM
To: 'Tomcat Users List'
Subject: RE: Tomcat sucks at receiving large messages


I should have thought that as a general principle it's not a good idea
to try to store the response in a byte array.  I recently worked on a
piece of code that did just that (worse, actually, it then copied the
array into a String).  Sooner or later a really big upload will blow up
the application.

Reading and writing a byte at a time (with appropriate buffering)
requires a bit more ingenuity, especially when you're searching for
things like boundary strings in the response, but it's the only way to
remove any constraint on upload size.  

Chris Walker

-----Original Message-----
From: Shapira, Yoav []
Sent: 30 September 2003 19:30
To: Tomcat Users List
Subject: RE: Tomcat sucks at receiving large messages


>public void service(HttpServletRequest req, HttpServletResponse res) {
>  BufferedReader reader = req.getReader();
>  try {
>    char [] charArr = new char[req.getContentLength()];
>    String str = new String(charArr);
>    try {
>      File f = new File("servlet.out");
>      PrintWriter out = new PrintWriter(new FileWriter(f));
>      out.print(str);
>      out.flush();
>      out.close();
>    } catch(IOException err { System.err.println(err.toString()); }
>  } catch(IOException err) { System.err.println(err.toString()); } }

What happens if you ditch the req.getContentLength() approach (there are
times when it will be -1 anyways), and do something like: BufferedReader
reader = req.getReader(); StringBuffer contents = new StringBuffer();
String line = null; while((line = reader.readLine()) != null) {


(Later we'll worry about the writing -- first make sure you're reading
the entire contents).

Yoav Shapira

This e-mail, including any attachments, is a confidential business
communication, and may contain information that is confidential,
proprietary and/or privileged.  This e-mail is intended only for the
individual(s) to whom it is addressed, and may not be saved, copied,
printed, disclosed or used by anyone else.  If you are not the(an)
intended recipient, please immediately delete this e-mail from your
computer system and notify the sender.  Thank you.

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message