Darryl Miles wrote:
> 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]
> 
> 

Hi, thank's for your answer first.

I want to detect if a terminal gets all of the file he wanted to download 
through the HTTP connection.
I agree with you that i don't use a specific tomcat api for that but I think 
that would help to get a global view of the problem.

I thought that the fact that no exception is thrown maybe comes from the way 
tomcat is configured.

To explain this completely, here is a part the main java on the other side:
HttpURLConnection c=(HttpURLConnection)u.openConnection();
InputStream is=c.getInputStream();
FileOutputStream fos=new FileOutputStream(new File("/home/XXX/lbd.3gp"));
for(int i=is.read();i!=-1;i=is.read()){
        fos.write(i);
        fos.flush();
        c.disconnect();//same problem if no disconnect before exit
        System.exit(0);
}

So I get only the first byte.
--
On the server side,

I tried what you told but still no exception is thrown.
I was flushing after every bytes written to the outputStream but that seams to 
make no difference.
In the apache logs, I see more than the byte received (16376) :(

--

So I thought maybe there is some sort of cache between apache and tomcat and 
this came from tomcat configuration ?

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

Reply via email to