diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/util/InputStreamResponseListener.java b/jetty-client/src/main/java/org/eclipse/jetty/client/util/InputStreamResponseListener.java index 644326aae5c..6ac55e6f65e 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/util/InputStreamResponseListener.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/util/InputStreamResponseListener.java @@ -129,29 +129,24 @@ public class InputStreamResponseListener extends Response.Listener.Empty } } - @Override - public void onFailure(Response response, Throwable failure) - { - LOG.debug("Queuing failure {} {}", FAILURE, failure); - queue.offer(FAILURE); - responseLatch.countDown(); - resultLatch.countDown(); - this.failure = failure; - signal(); - } - - @Override - public void onSuccess(Response response) - { - LOG.debug("Queuing end of content {}{}", EOF, ""); - queue.offer(EOF); - } - @Override public void onComplete(Result result) { this.result = result; + if (result.isSucceeded()) + { + LOG.debug("Queuing end of content {}{}", EOF, ""); + queue.offer(EOF); + } + else + { + LOG.debug("Queuing failure {} {}", FAILURE, failure); + queue.offer(FAILURE); + this.failure = result.getFailure(); + responseLatch.countDown(); + } resultLatch.countDown(); + signal(); } protected boolean await() @@ -176,7 +171,7 @@ public class InputStreamResponseListener extends Response.Listener.Empty { synchronized (this) { - notify(); + notifyAll(); } } diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientStreamTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientStreamTest.java index 218f0e090aa..5a800af8549 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientStreamTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientStreamTest.java @@ -445,6 +445,20 @@ public class HttpClientStreamTest extends AbstractHttpClientServerTest Assert.assertNull(failure.get()); } + @Test + public void testInputStreamResponseListenerFailedBeforeResponse() throws Exception + { + start(new EmptyServerHandler()); + + InputStreamResponseListener listener = new InputStreamResponseListener(); + // Connect to the wrong port + client.newRequest("localhost", 0) + .scheme(scheme) + .send(listener); + Result result = listener.await(5, TimeUnit.SECONDS); + Assert.assertNotNull(result); + } + @Test(expected = ExecutionException.class) public void testInputStreamContentProviderThrowingWhileReading() throws Exception {