diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/internal/HttpReceiverOverHTTP.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/internal/HttpReceiverOverHTTP.java index c89b0331a8d6..575a1d2d1f45 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/internal/HttpReceiverOverHTTP.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/internal/HttpReceiverOverHTTP.java @@ -361,12 +361,13 @@ private boolean parse(boolean notifyContentAvailable) if (LOG.isDebugEnabled()) LOG.debug("Discarding unexpected content after response {}: {} in {}", status, BufferUtil.toDetailString(byteBuffer), this); BufferUtil.clear(byteBuffer); - return false; + return true; } } - // Continue to read from the network. - return false; + // Reading the next response will + // be performed by receivedNext(). + return true; } default -> throw new IllegalStateException("Invalid state " + state); } diff --git a/jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTLSTest.java b/jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTLSTest.java index 527e76443cd9..cf6bff3d416c 100644 --- a/jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTLSTest.java +++ b/jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTLSTest.java @@ -1401,9 +1401,12 @@ public void onClosed(Connection connection) assertTrue(latch.await(5, TimeUnit.SECONDS)); + // Client sent and server received (and viceversa) bytes may not be equal + // because upon closing the connection the TLS alert may not be read due + // to the fact that the EndPoint is closed. assertThat(clientStats.getSentBytes(), Matchers.greaterThan(0L)); - assertEquals(clientStats.getSentBytes(), serverStats.getReceivedBytes()); + assertThat(serverStats.getReceivedBytes(), Matchers.greaterThan(0L)); assertThat(clientStats.getReceivedBytes(), Matchers.greaterThan(0L)); - assertEquals(clientStats.getReceivedBytes(), serverStats.getSentBytes()); + assertThat(serverStats.getSentBytes(), Matchers.greaterThan(0L)); } } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-client-transports/src/test/java/org/eclipse/jetty/ee10/test/client/transport/AsyncIOServletTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-client-transports/src/test/java/org/eclipse/jetty/ee10/test/client/transport/AsyncIOServletTest.java index dcc6e359626f..d4ebe705f8f3 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-client-transports/src/test/java/org/eclipse/jetty/ee10/test/client/transport/AsyncIOServletTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-client-transports/src/test/java/org/eclipse/jetty/ee10/test/client/transport/AsyncIOServletTest.java @@ -285,7 +285,7 @@ public void onClosed(Connection connection) client.newRequest(newURI(transportType)) .method(HttpMethod.POST) .body(content) - .onResponseSuccess(r -> responseLatch.countDown()) + .onResponseHeaders(r -> responseLatch.countDown()) .timeout(5, TimeUnit.SECONDS) .send(result -> { @@ -1377,12 +1377,11 @@ public long getLength() client.newRequest(newURI(transportType)) .method(HttpMethod.POST) .body(content) - .onResponseSuccess(response -> + .send(result -> { - Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, response.getStatus()); + Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, result.getResponse().getStatus()); latch.countDown(); - }) - .send(null); + }); // Wait for the server to idle timeout. Thread.sleep(2 * idleTimeout); diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-client-transports/src/test/java/org/eclipse/jetty/ee10/test/client/transport/ServerTimeoutsTest.java b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-client-transports/src/test/java/org/eclipse/jetty/ee10/test/client/transport/ServerTimeoutsTest.java index bc13f35a6759..5e43248dbfd3 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-client-transports/src/test/java/org/eclipse/jetty/ee10/test/client/transport/ServerTimeoutsTest.java +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-client-transports/src/test/java/org/eclipse/jetty/ee10/test/client/transport/ServerTimeoutsTest.java @@ -158,17 +158,21 @@ protected void service(HttpServletRequest request, HttpServletResponse response) long idleTimeout = 1000; setStreamIdleTimeout(idleTimeout); - CountDownLatch resultLatch = new CountDownLatch(2); + CountDownLatch resultLatch = new CountDownLatch(1); AsyncRequestContent content = new AsyncRequestContent(); client.POST(newURI(transportType)) .body(content) - .onResponseSuccess(response -> + .onResponseHeaders(r -> { - if (response.getStatus() == HttpStatus.INTERNAL_SERVER_ERROR_500) - resultLatch.countDown(); + // For the cases where the response is not failed, + // complete the request to complete the exchange. content.close(); }) - .send(result -> resultLatch.countDown()); + .send(result -> + { + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, result.getResponse().getStatus()); + resultLatch.countDown(); + }); // The client did not send the content, the request was // dispatched, the server should have idle timed it out. @@ -339,7 +343,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response) CountDownLatch resultLatch = new CountDownLatch(1); client.newRequest(newURI(transportType)) .body(content) - .onResponseSuccess(response -> + .onResponseHeaders(response -> { responseRef.set(response); responseLatch.countDown(); diff --git a/jetty-ee11/jetty-ee11-tests/jetty-ee11-test-client-transports/src/test/java/org/eclipse/jetty/ee11/test/client/transport/AsyncIOServletTest.java b/jetty-ee11/jetty-ee11-tests/jetty-ee11-test-client-transports/src/test/java/org/eclipse/jetty/ee11/test/client/transport/AsyncIOServletTest.java index 976aa090f6f4..f1f1d7f6b0a3 100644 --- a/jetty-ee11/jetty-ee11-tests/jetty-ee11-test-client-transports/src/test/java/org/eclipse/jetty/ee11/test/client/transport/AsyncIOServletTest.java +++ b/jetty-ee11/jetty-ee11-tests/jetty-ee11-test-client-transports/src/test/java/org/eclipse/jetty/ee11/test/client/transport/AsyncIOServletTest.java @@ -285,7 +285,7 @@ public void onClosed(Connection connection) client.newRequest(newURI(transportType)) .method(HttpMethod.POST) .body(content) - .onResponseSuccess(r -> responseLatch.countDown()) + .onResponseHeaders(r -> responseLatch.countDown()) .timeout(5, TimeUnit.SECONDS) .send(result -> { @@ -1377,12 +1377,11 @@ public long getLength() client.newRequest(newURI(transportType)) .method(HttpMethod.POST) .body(content) - .onResponseSuccess(response -> + .send(result -> { - Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, response.getStatus()); + Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, result.getResponse().getStatus()); latch.countDown(); - }) - .send(null); + }); // Wait for the server to idle timeout. Thread.sleep(2 * idleTimeout); diff --git a/jetty-ee11/jetty-ee11-tests/jetty-ee11-test-client-transports/src/test/java/org/eclipse/jetty/ee11/test/client/transport/ServerTimeoutsTest.java b/jetty-ee11/jetty-ee11-tests/jetty-ee11-test-client-transports/src/test/java/org/eclipse/jetty/ee11/test/client/transport/ServerTimeoutsTest.java index 0e909e9c3db5..7502bea57a9d 100644 --- a/jetty-ee11/jetty-ee11-tests/jetty-ee11-test-client-transports/src/test/java/org/eclipse/jetty/ee11/test/client/transport/ServerTimeoutsTest.java +++ b/jetty-ee11/jetty-ee11-tests/jetty-ee11-test-client-transports/src/test/java/org/eclipse/jetty/ee11/test/client/transport/ServerTimeoutsTest.java @@ -158,17 +158,21 @@ protected void service(HttpServletRequest request, HttpServletResponse response) long idleTimeout = 1000; setStreamIdleTimeout(idleTimeout); - CountDownLatch resultLatch = new CountDownLatch(2); + CountDownLatch resultLatch = new CountDownLatch(1); AsyncRequestContent content = new AsyncRequestContent(); client.POST(newURI(transportType)) .body(content) - .onResponseSuccess(response -> + .onResponseHeaders(r -> { - if (response.getStatus() == HttpStatus.INTERNAL_SERVER_ERROR_500) - resultLatch.countDown(); + // For the cases where the response is not failed, + // complete the request to complete the exchange. content.close(); }) - .send(result -> resultLatch.countDown()); + .send(result -> + { + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, result.getResponse().getStatus()); + resultLatch.countDown(); + }); // The client did not send the content, the request was // dispatched, the server should have idle timed it out. @@ -339,7 +343,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response) CountDownLatch resultLatch = new CountDownLatch(1); client.newRequest(newURI(transportType)) .body(content) - .onResponseSuccess(response -> + .onResponseHeaders(response -> { responseRef.set(response); responseLatch.countDown(); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/java/org/eclipse/jetty/ee9/test/client/transport/AsyncIOServletTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/java/org/eclipse/jetty/ee9/test/client/transport/AsyncIOServletTest.java index 1023f3d134f4..6d1c4462aa90 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/java/org/eclipse/jetty/ee9/test/client/transport/AsyncIOServletTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/java/org/eclipse/jetty/ee9/test/client/transport/AsyncIOServletTest.java @@ -287,7 +287,7 @@ public void onClosed(Connection connection) client.newRequest(newURI(transportType)) .method(HttpMethod.POST) .body(content) - .onResponseSuccess(r -> responseLatch.countDown()) + .onResponseHeaders(r -> responseLatch.countDown()) .timeout(5, TimeUnit.SECONDS) .send(result -> { @@ -1782,12 +1782,11 @@ public long getLength() client.newRequest(newURI(transportType)) .method(HttpMethod.POST) .body(content) - .onResponseSuccess(response -> + .send(result -> { - Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, response.getStatus()); + Assertions.assertEquals(HttpStatus.REQUEST_TIMEOUT_408, result.getResponse().getStatus()); latch.countDown(); - }) - .send(null); + }); // Wait for the server to idle timeout. Thread.sleep(2 * idleTimeout); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/java/org/eclipse/jetty/ee9/test/client/transport/ServerTimeoutsTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/java/org/eclipse/jetty/ee9/test/client/transport/ServerTimeoutsTest.java index 02a74a1968ca..43e70dd6366d 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/java/org/eclipse/jetty/ee9/test/client/transport/ServerTimeoutsTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/java/org/eclipse/jetty/ee9/test/client/transport/ServerTimeoutsTest.java @@ -161,17 +161,21 @@ protected void service(HttpServletRequest request, HttpServletResponse response) long idleTimeout = 1000; setStreamIdleTimeout(idleTimeout); - CountDownLatch resultLatch = new CountDownLatch(2); + CountDownLatch resultLatch = new CountDownLatch(1); AsyncRequestContent content = new AsyncRequestContent(); client.POST(newURI(transportType)) .body(content) - .onResponseSuccess(response -> + .onResponseHeaders(r -> { - if (response.getStatus() == HttpStatus.INTERNAL_SERVER_ERROR_500) - resultLatch.countDown(); + // For the cases where the response is not failed, + // complete the request to complete the exchange. content.close(); }) - .send(result -> resultLatch.countDown()); + .send(result -> + { + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR_500, result.getResponse().getStatus()); + resultLatch.countDown(); + }); // The client did not send the content, the request was // dispatched, the server should have idle timed it out. @@ -340,7 +344,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response) CountDownLatch resultLatch = new CountDownLatch(1); client.newRequest(newURI(transportType)) .body(content) - .onResponseSuccess(response -> + .onResponseHeaders(response -> { responseRef.set(response); responseLatch.countDown(); diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/resources/jetty-logging.properties b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/resources/jetty-logging.properties index 4fdadbafe69a..7ae8c2aa5d4a 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/resources/jetty-logging.properties +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-client-transports/src/test/resources/jetty-logging.properties @@ -1,4 +1,4 @@ -#org.eclipse.jetty.LEVEL=DEBUG +org.eclipse.jetty.LEVEL=DEBUG org.eclipse.jetty.jmx.LEVEL=INFO #org.eclipse.jetty.client.LEVEL=DEBUG #org.eclipse.jetty.fcgi.LEVEL=DEBUG