Hi Mark,

  I’m uploading some test files

Attachment: GetPayloadServlet.java
Description: Binary data

Attachment: HttpPostTest.java
Description: Binary data

Attachment: web.xml
Description: XML document

  Below are the steps:
1. compile GetPayloadServlet.java and put it to webapps/test/WEB-INF/classes/test/
2. put web.xml to webapps/test/WEB-INF/
3. start tomcat (9.0.19), I tried with 9.0.53, I got the same result
4. use HttpPostTest(I’m using Apache httpclient-4.5.1.jar, httpcore-4.4.4.jar)the test is sending data with chunked transfer-encoding, one step here 
4.1. put a debug point before streamWrite at flushBuffer method in org.apache.http.impl.io.SessionOutputBufferImpl, the purpose is to pause flushing to the socket
    private void flushBuffer() throws IOException {
        final int len = this.buffer.length();
        if (len > 0) {
            streamWrite(this.buffer.buffer(), 0, len);


     5. put a debug point on GetPayloadServlet

public void onDataAvailable() throws IOException {
byte buffer[] = new byte[BUFFER_SIZE];
while(inputStream.isReady()) { // when isReady returns true, inputStream.read(buffer) is actually blocked with chunked encoding
int read = inputStream.read(buffer);
if (read < 0) {
bos.write(buffer, 0, read);

6. we can see once SessionOutputBufferImpl.flushBuffer flushes the data, inputStream.read(buffer) inside GetPayloadServlet will be un-blocked with read

  Or am I doing something wrong? this is a basic use case.


On Sep 22, 2021, at 1:14 AM, Mark Thomas <ma...@apache.org> wrote:

On 22/09/2021 08:22, Goldengate liu wrote:
Hi Chris,
Servlet 3.1 spec defines that ServletInputStream can be used to read as non-blocking way as long as there is data ready locally by calling isReady method and check the ready condition before calling read, and read should throw IllegalStateException if called by caller when data is not ready

The above only applies if the servlet is in async mode. Is it?
correct, when it’s running as async mode

OK. You are going to need to provide the simplest complete example that demonstrates this then. Something like the source for a single Servlet and a curl command to send a request to it.


To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to