You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by William Claxton <wi...@openasia.net> on 2003/05/11 13:40:04 UTC
RE: flushing output to the browser fails
Hi again, folks -
Flushing data to the browser still doesn't work. Tried moving back to
Tomcat 4.0.6, and then up to 4.1.24. Tried also moving from JK to JK2.
It simply does not work.
Our current environment is RH Linux 8, Apache 2.0, and Tomcat 4.1.24.
Apache and Tomcat are connected via the mod_JK2 connector with AJP13 protocol.
I am including the code for a test servlet. Perhaps someone could try this
and let me know if it works in their environment. It was developed and
tested on an IIS / Websphere platform. A minor browser dependency was
observed - works fine with IE 5.x and NS 4.x, but in the latter output
appears line-by-line rather than chunk-by-chunk.
******** code begins here ***********
/*
name: FlushTest.java
dir: scripts/java
by: OpenAsia Solutions Pte Ltd
func: ouputs numeric series, one value at a time to the browser
rev: 20030511, wmc, created this demonstration class
*/
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class FlushTest extends HttpServlet {
static protected String VERSION = "0.1";
static protected String REVISION = "20030511";
static protected int COUNT_MIN = 0;
static protected int COUNT_MAX = 500;
static protected int MILLISECOND_DELAY = 20;
public String getServletInfo () {
return ("FlushTest v" + VERSION + ", rev: " + REVISION);
}
public void init () throws ServletException {
}
public void service (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
OutputStream fout = res.getOutputStream();
try {
fout.write(("<html><body><b>" + getServletInfo() + "</b><br>").getBytes());
fout.write(("Counting to: " + COUNT_MAX + ", which should appear in " +
"chunks, rather than all at once.<br>").getBytes());
for (int i = COUNT_MIN; i <= COUNT_MAX; i++) {
fout.write((i + ", ").getBytes());
fout.flush();
Thread.sleep(MILLISECOND_DELAY);
}
fout.write(("done!<br><br></body></html>").getBytes());
fout.flush();
} catch (Exception e) {
e.printStackTrace();
}
finally {
if (fout != null) fout.close();
}
}
}
******** code ends here ***********
Thanks in advance.
At 12:25 PM 4/14/03 +1000, you wrote:
>
>I think it might be the 4.1.18 connector, I had a simillar problem with it.
>
>you might want to check and see if it works with the 4.0.x connector
>
>rgds
>Jason
>
>> -----Original Message-----
>> From: William Claxton [SMTP:williamc@openasia.net]
>> Sent: Monday,14 April 2003 12:05
>> To: tomcat-user@jakarta.apache.org
>> Subject: flushing output to the browser fails
>>
>> We have a servlet that flushes output to the browser, and it works fine on
>> Websphere & IIS, but it doesn't work with our Tomcat environment. Our
>> environment is RH Linux 8, Apache 2.0, and Tomcat 4.1.18. We have
>> connected Apache and Tomcat, using AJP13.
>>
>> The servlet is doing a lot of backend processing, and needs to keep the
>> browser connection alive by flushing a status line at the end of each loop.
>> The code that handles the output flush is very simple:
>>
>> try {
>> String str = getString("status_message");
>> OutputStream fout = (OutputStream) vars.get("_output");
>> fout.write(str.getBytes());
>> fout.flush();
>> } catch (Exception err) {}
>>
>> Is this perhaps a configuration issue with Tomcat or the connector?
>>
>>
Regards, Bill Claxton [williamc@openasia.net]
OpenAsia Solutions provides streaming media & payment solutions.
Check out http://www.openasia.net
........:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: flushing output to the browser fails
Posted by Tim Funk <fu...@joedog.org>.
If that is the case then you probably need to set the content length
yourself. This should disable the chunked encoding (or whatever) apache is
trying to do.
Apache is probably(WAG) waiting for the entire response to come back from
tomcat before sending anything to the client so apache can inform the client
of the content length. (With a Content-Length: header)
-Tim
William Claxton wrote:
> Folks, hi -
>
> I have noticed that calling the servlet using Tomcat's built-in webserver
> works fine. That is, the following URL flushes the output in chunks,
> rather than to display the result all at once, after backend processing has
> completed.
>
> - http://www.openasia.net:8080/servlet/FlushTest
>
> Try it yourself and see! This is different from calling via Apache and the
> JK2 connector, which does display the result only after backend processing
> is complete.
>
> - http://www.openasia.net:80/servlet/FlushTest
>
> This leads me to infer that it is Apache that is causing the problem, and
> not Tomcat. Any suggestions are welcome.
>
>
> At 07:40 PM 5/11/03 +0800, you wrote:
>
>>Hi again, folks -
>>
>>Flushing data to the browser still doesn't work. Tried moving back to
>>Tomcat 4.0.6, and then up to 4.1.24. Tried also moving from JK to JK2.
>>It simply does not work.
>>
>>Our current environment is RH Linux 8, Apache 2.0, and Tomcat 4.1.24.
>>Apache and Tomcat are connected via the mod_JK2 connector with AJP13
>
> protocol.
>
>>I am including the code for a test servlet. Perhaps someone could try this
>>and let me know if it works in their environment. It was developed and
>>tested on an IIS / Websphere platform. A minor browser dependency was
>>observed - works fine with IE 5.x and NS 4.x, but in the latter output
>>appears line-by-line rather than chunk-by-chunk.
>>
>>******** code begins here ***********
>>
>> /*
>> name: FlushTest.java
>> dir: scripts/java
>> by: OpenAsia Solutions Pte Ltd
>> func: ouputs numeric series, one value at a time to the browser
>> rev: 20030511, wmc, created this demonstration class
>> */
>>
>>import java.io.*;
>>import javax.servlet.*;
>>import javax.servlet.http.*;
>>
>>public class FlushTest extends HttpServlet {
>> static protected String VERSION = "0.1";
>> static protected String REVISION = "20030511";
>> static protected int COUNT_MIN = 0;
>> static protected int COUNT_MAX = 500;
>> static protected int MILLISECOND_DELAY = 20;
>>
>> public String getServletInfo () {
>> return ("FlushTest v" + VERSION + ", rev: " + REVISION);
>> }
>>
>> public void init () throws ServletException {
>> }
>>
>> public void service (HttpServletRequest req, HttpServletResponse res)
>> throws ServletException, IOException {
>> OutputStream fout = res.getOutputStream();
>>
>> try {
>> fout.write(("<html><body><b>" + getServletInfo() +
>
> "</b><br>").getBytes());
>
>> fout.write(("Counting to: " + COUNT_MAX + ", which should appear in " +
>> "chunks, rather than all at once.<br>").getBytes());
>> for (int i = COUNT_MIN; i <= COUNT_MAX; i++) {
>> fout.write((i + ", ").getBytes());
>> fout.flush();
>> Thread.sleep(MILLISECOND_DELAY);
>> }
>> fout.write(("done!<br><br></body></html>").getBytes());
>> fout.flush();
>>
>> } catch (Exception e) {
>> e.printStackTrace();
>> }
>> finally {
>> if (fout != null) fout.close();
>> }
>> }
>>}
>>
>>******** code ends here ***********
>>
>>Thanks in advance.
>>
>>
>>
>>At 12:25 PM 4/14/03 +1000, you wrote:
>>
>>>I think it might be the 4.1.18 connector, I had a simillar problem with it.
>>>
>>>you might want to check and see if it works with the 4.0.x connector
>>>
>>>rgds
>>>Jason
>>>
>>>
>>>>-----Original Message-----
>>>>From: William Claxton [SMTP:williamc@openasia.net]
>>>>Sent: Monday,14 April 2003 12:05
>>>>To: tomcat-user@jakarta.apache.org
>>>>Subject: flushing output to the browser fails
>>>>
>>>>We have a servlet that flushes output to the browser, and it works fine on
>>>>Websphere & IIS, but it doesn't work with our Tomcat environment. Our
>>>>environment is RH Linux 8, Apache 2.0, and Tomcat 4.1.18. We have
>>>>connected Apache and Tomcat, using AJP13.
>>>>
>>>>The servlet is doing a lot of backend processing, and needs to keep the
>>>>browser connection alive by flushing a status line at the end of each
>
> loop.
>
>>>> The code that handles the output flush is very simple:
>>>>
>>>>try {
>>>> String str = getString("status_message");
>>>> OutputStream fout = (OutputStream) vars.get("_output");
>>>> fout.write(str.getBytes());
>>>> fout.flush();
>>>>} catch (Exception err) {}
>>>>
>>>>Is this perhaps a configuration issue with Tomcat or the connector?
>>>>
>>>>
>>
>> Regards, Bill Claxton [williamc@openasia.net]
>> OpenAsia Solutions provides streaming media & payment solutions.
>> Check out http://www.openasia.net
>>........:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>
>
> Regards, Bill Claxton [williamc@openasia.net]
> OpenAsia Solutions provides streaming media & payment solutions.
> Check out http://www.openasia.net
> ........:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
RE: flushing output to the browser fails
Posted by William Claxton <wi...@openasia.net>.
Folks, hi -
I have noticed that calling the servlet using Tomcat's built-in webserver
works fine. That is, the following URL flushes the output in chunks,
rather than to display the result all at once, after backend processing has
completed.
- http://www.openasia.net:8080/servlet/FlushTest
Try it yourself and see! This is different from calling via Apache and the
JK2 connector, which does display the result only after backend processing
is complete.
- http://www.openasia.net:80/servlet/FlushTest
This leads me to infer that it is Apache that is causing the problem, and
not Tomcat. Any suggestions are welcome.
At 07:40 PM 5/11/03 +0800, you wrote:
>Hi again, folks -
>
>Flushing data to the browser still doesn't work. Tried moving back to
>Tomcat 4.0.6, and then up to 4.1.24. Tried also moving from JK to JK2.
>It simply does not work.
>
>Our current environment is RH Linux 8, Apache 2.0, and Tomcat 4.1.24.
>Apache and Tomcat are connected via the mod_JK2 connector with AJP13
protocol.
>
>I am including the code for a test servlet. Perhaps someone could try this
>and let me know if it works in their environment. It was developed and
>tested on an IIS / Websphere platform. A minor browser dependency was
>observed - works fine with IE 5.x and NS 4.x, but in the latter output
>appears line-by-line rather than chunk-by-chunk.
>
>******** code begins here ***********
>
> /*
> name: FlushTest.java
> dir: scripts/java
> by: OpenAsia Solutions Pte Ltd
> func: ouputs numeric series, one value at a time to the browser
> rev: 20030511, wmc, created this demonstration class
> */
>
>import java.io.*;
>import javax.servlet.*;
>import javax.servlet.http.*;
>
>public class FlushTest extends HttpServlet {
> static protected String VERSION = "0.1";
> static protected String REVISION = "20030511";
> static protected int COUNT_MIN = 0;
> static protected int COUNT_MAX = 500;
> static protected int MILLISECOND_DELAY = 20;
>
> public String getServletInfo () {
> return ("FlushTest v" + VERSION + ", rev: " + REVISION);
> }
>
> public void init () throws ServletException {
> }
>
> public void service (HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException {
> OutputStream fout = res.getOutputStream();
>
> try {
> fout.write(("<html><body><b>" + getServletInfo() +
"</b><br>").getBytes());
> fout.write(("Counting to: " + COUNT_MAX + ", which should appear in " +
> "chunks, rather than all at once.<br>").getBytes());
> for (int i = COUNT_MIN; i <= COUNT_MAX; i++) {
> fout.write((i + ", ").getBytes());
> fout.flush();
> Thread.sleep(MILLISECOND_DELAY);
> }
> fout.write(("done!<br><br></body></html>").getBytes());
> fout.flush();
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> finally {
> if (fout != null) fout.close();
> }
> }
>}
>
>******** code ends here ***********
>
>Thanks in advance.
>
>
>
>At 12:25 PM 4/14/03 +1000, you wrote:
>>
>>I think it might be the 4.1.18 connector, I had a simillar problem with it.
>>
>>you might want to check and see if it works with the 4.0.x connector
>>
>>rgds
>>Jason
>>
>>> -----Original Message-----
>>> From: William Claxton [SMTP:williamc@openasia.net]
>>> Sent: Monday,14 April 2003 12:05
>>> To: tomcat-user@jakarta.apache.org
>>> Subject: flushing output to the browser fails
>>>
>>> We have a servlet that flushes output to the browser, and it works fine on
>>> Websphere & IIS, but it doesn't work with our Tomcat environment. Our
>>> environment is RH Linux 8, Apache 2.0, and Tomcat 4.1.18. We have
>>> connected Apache and Tomcat, using AJP13.
>>>
>>> The servlet is doing a lot of backend processing, and needs to keep the
>>> browser connection alive by flushing a status line at the end of each
loop.
>>> The code that handles the output flush is very simple:
>>>
>>> try {
>>> String str = getString("status_message");
>>> OutputStream fout = (OutputStream) vars.get("_output");
>>> fout.write(str.getBytes());
>>> fout.flush();
>>> } catch (Exception err) {}
>>>
>>> Is this perhaps a configuration issue with Tomcat or the connector?
>>>
>>>
>
> Regards, Bill Claxton [williamc@openasia.net]
> OpenAsia Solutions provides streaming media & payment solutions.
> Check out http://www.openasia.net
>........:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
Regards, Bill Claxton [williamc@openasia.net]
OpenAsia Solutions provides streaming media & payment solutions.
Check out http://www.openasia.net
........:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org