From 5235dc6ea18b10c96ed410f3bbc8284f823554c8 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 7 Sep 2012 15:21:17 +0200 Subject: [PATCH] jetty-9 - HTTP client: moved exchange failure state from the receiver to the exchange where it better belongs. --- .../java/org/eclipse/jetty/client/HttpExchange.java | 11 +++++++++++ .../java/org/eclipse/jetty/client/HttpReceiver.java | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java index 97cb642d5c7..9fe8ad1111b 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpExchange.java @@ -35,6 +35,7 @@ public class HttpExchange private final Request request; private final Response.Listener listener; private final HttpResponse response; + private volatile Throwable failure; public HttpExchange(HttpConversation conversation, HttpConnection connection, Request request, Response.Listener listener) { @@ -95,6 +96,16 @@ public class HttpExchange } } + public boolean failed() + { + return failure != null; + } + + public void failed(Throwable failure) + { + this.failure = failure; + } + @Override public String toString() { diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java index 52e83983bbd..8fcf4f992cc 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpReceiver.java @@ -44,7 +44,6 @@ public class HttpReceiver implements HttpParser.ResponseHandler private final AtomicBoolean complete = new AtomicBoolean(); private final HttpParser parser = new HttpParser(this); private final HttpConnection connection; - private volatile boolean failed; public HttpReceiver(HttpConnection connection) { @@ -171,7 +170,9 @@ public class HttpReceiver implements HttpParser.ResponseHandler @Override public boolean messageComplete(long contentLength) { - if (!failed) + HttpExchange exchange = connection.getExchange(); + // The exchange may be null if it was failed before + if (exchange != null && !exchange.failed()) success(); return true; } @@ -184,7 +185,6 @@ public class HttpReceiver implements HttpParser.ResponseHandler LOG.debug("Received {}", response); parser.reset(); - failed = false; boolean complete = this.complete.getAndSet(false); exchange.responseComplete(true); @@ -208,7 +208,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler LOG.debug("Failed {} {}", response, failure); parser.reset(); - failed = true; + exchange.failed(failure); complete.set(false); exchange.responseComplete(false);