Orion 1.2.9
Windows 2000
J2SE 1.3.0

Bug: Underlying InputStream from request.getInputStream() throws an
exception when the input stream should return more than 2048 bytes.

Example: The following error occurs when running the JSP and servlet below.
The underlying input stream seems to throw and exception during in.read(...)
when trying to upload a file that's greater than 2048 (actually when the
file + the extra multi encoding  > 2048).  I've tried this on Tomcat 3.2b
and it works fine.  I've used similar code on older servers (not orion) and
didn't have this problem.  I'm writing this to the users group as well in
case others are having problems with this.  If you work with file uploading
through forms, this will certainly hamper your progress.


500 Internal Server Error
java.lang.IndexOutOfBoundsException
        at com.evermind.server.http.ep.read(JAX)
        at InputStreamBug.doPost(InputStreamBug.java:21)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at com.evermind.server.http.du.rr(JAX)
        at com.evermind.server.http.du.forward(JAX)
        at com.evermind.server.http.d5.rx(JAX)
        at com.evermind.server.http.d5.rw(JAX)
        at com.evermind.util.f.run(JAX)

InputStreamBug.jsp--------------------------------
<%@page contentType="text/html"%>
<html>
<head><title>InputStreamBug</title></head>
<body>
<FORM action='servlet/InputStreamBug' enctype='multipart/form-data'
method='post'>
    <INPUT type='file' name='filename'><BR>
    <INPUT type='submit' name='submit' value='Upload'>
</FORM>
</body>
</html>


InputStreamBug.java-------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class InputStreamBug extends HttpServlet {
    /**
     * Reads the input stream and outputs the results to the output stream.
     */
    public void doPost(HttpServletRequest request, HttpServletResponse
response)
            throws IOException{
        response.setContentType("text/html");
        InputStream in     = request.getInputStream();
        OutputStream out   = response.getOutputStream();
        int contentLength  = request.getContentLength();
        byte[] bytes       = new byte[contentLength];
        int actualRead     = 0;
        int bytesRead      = 0;

        while (bytesRead < contentLength) {
            actualRead = in.read(bytes, bytesRead, contentLength);
            bytesRead += actualRead;
        }
        out.write(bytes);
    }
}


Reply via email to