Fixed bug 91: web connection was closed when the request

was encoded multipart/form-data (file upload). This bug was
caused by the recent unification of Servlets under the common
AbstractServletClient base class, since closing the input
stream worked ok on Apache JServ/Tomcat, but not with the
embedded Acme web server.
This commit is contained in:
hns 2002-06-05 13:52:20 +00:00
parent 8f52328591
commit c900b69482

View file

@ -252,7 +252,9 @@ public abstract class AbstractServletClient extends HttpServlet {
OutputStream out = res.getOutputStream (); OutputStream out = res.getOutputStream ();
out.write (trans.getContent ()); out.write (trans.getContent ());
out.close (); out.close ();
} catch(Exception io_e) {} } catch(Exception io_e) {
System.err.println ("Exception in writeResponse: "+io_e);
}
} }
} }
@ -268,24 +270,17 @@ public abstract class AbstractServletClient extends HttpServlet {
public FileUpload getUpload (HttpServletRequest request) throws Exception { public FileUpload getUpload (HttpServletRequest request) throws Exception {
int contentLength = request.getContentLength (); int contentLength = request.getContentLength ();
BufferedInputStream in = new BufferedInputStream (request.getInputStream ()); BufferedInputStream in = new BufferedInputStream (request.getInputStream ());
FileUpload upload = null; if (contentLength > uploadLimit*1024) {
try { // consume all input to make Apache happy
if (contentLength > uploadLimit*1024) { byte b[] = new byte[1024];
// consume all input to make Apache happy int read = 0;
byte b[] = new byte[1024]; while (read > -1)
int read = 0; read = in.read (b, 0, 1024);
while (read > -1) throw new RuntimeException ("Upload exceeds limit of "+uploadLimit+" kb.");
read = in.read (b, 0, 1024);
throw new RuntimeException ("Upload exceeds limit of "+uploadLimit+" kb.");
}
String contentType = request.getContentType ();
upload = new FileUpload(uploadLimit);
upload.load (in, contentType, contentLength);
} finally {
try {
in.close ();
} catch (Exception ignore) {}
} }
String contentType = request.getContentType ();
FileUpload upload = new FileUpload(uploadLimit);
upload.load (in, contentType, contentLength);
return upload; return upload;
} }