Nicolas Schwartz wrote:
I'm trying to get the information of sending the last byte of a file through 
Tomcat.
I've done many tests, I've looked in the archives and nothing came up.
So I'm thinking that maybe I'm not posting where I should, if it is so, please 
tell me so and tell me where I could find the info.

I know this mailing list is about configuration but here is what I do and the 
configuration:
I'm doing a loop with a FileInputStream and writing each byte to the 
OutputStream I got from my HttpServletResponse.

No Exception or whatever is thrown when I kill the connection once the url has 
been requested.

I use apache and tomcat. They're connected with the ajp13 connector.
I've looked in the connector configuration (workers.properties) options but 
found nothing.

Any help, hint , ... would be greatly appreciated :)


I read this to mean you want to emit a file in a HTTP response and the APIs are you using are not Tomcat specific.

Check out the InputStream interface at http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html


byte[] b = new byte[4096];
for(;;) {
        int l;
        if((l = fileInputStream.read(b, 0, b.length)) == -1) {
                break;  // No more data from file
        }
        response.getOutputStream().write(b, 0, l);
}
response.getOutputStream().flush(); // So we see exception in our Servlet code



The "kill the connection" bit is a bit confusing, you mean you are testing the premature killing of a client connection of a partically downloaded file.

It depends how the connection is killed on when you will see the exception, for example if a network socket level reset is performed then some form of IOException should be thrown during the getOutputStream.print("") or during a flush() or close().

If your servlet does not explicitly do the flush() or close() on the data it wrote but terminates the HttpServlet.doGet() method then you leave it upto the container to complete the flushing. Then you may not see any exception as the container may just deal with it and eat it up.

If you are not killing the connection off at the network level then it may take Tomcat sometime to automatically kill it off through normal network level dead socket detection (max retry / keepalive failure).


HTH

Darryl

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to