diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java b/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java index eaeff4bfb45..97599f6f8c3 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java @@ -79,7 +79,7 @@ public class AuthenticationProtocolHandler implements ProtocolHandler public void onComplete(Result result) { Request request = result.getRequest(); - HttpConversation conversation = client.getConversation(request.getConversationID()); + HttpConversation conversation = client.getConversation(request.getConversationID(), false); Response.Listener listener = conversation.getExchanges().peekFirst().getResponseListener(); ContentResponse response = new HttpContentResponse(result.getResponse(), getContent(), getEncoding()); if (result.isFailed()) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/ContinueProtocolHandler.java b/jetty-client/src/main/java/org/eclipse/jetty/client/ContinueProtocolHandler.java index 0e530d049c0..a9dec3af342 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/ContinueProtocolHandler.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/ContinueProtocolHandler.java @@ -41,7 +41,8 @@ public class ContinueProtocolHandler implements ProtocolHandler public boolean accept(Request request, Response response) { boolean expect100 = request.getHeaders().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString()); - boolean handled100 = client.getConversation(request.getConversationID()).getAttribute(ATTRIBUTE) != null; + HttpConversation conversation = client.getConversation(request.getConversationID(), false); + boolean handled100 = conversation != null && conversation.getAttribute(ATTRIBUTE) != null; return expect100 && !handled100; } @@ -60,7 +61,7 @@ public class ContinueProtocolHandler implements ProtocolHandler // Handling of success must be done here and not from onComplete(), // since the onComplete() is not invoked because the request is not completed yet. - HttpConversation conversation = client.getConversation(response.getConversationID()); + HttpConversation conversation = client.getConversation(response.getConversationID(), false); // Mark the 100 Continue response as handled conversation.setAttribute(ATTRIBUTE, Boolean.TRUE); @@ -92,7 +93,7 @@ public class ContinueProtocolHandler implements ProtocolHandler @Override public void onFailure(Response response, Throwable failure) { - HttpConversation conversation = client.getConversation(response.getConversationID()); + HttpConversation conversation = client.getConversation(response.getConversationID(), false); // Mark the 100 Continue response as handled conversation.setAttribute(ATTRIBUTE, Boolean.TRUE); diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java index 0af29158253..a13d4238c7e 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java @@ -365,10 +365,10 @@ public class HttpClient extends ContainerLifeCycle } } - protected HttpConversation getConversation(long id) + protected HttpConversation getConversation(long id, boolean create) { HttpConversation conversation = conversations.get(id); - if (conversation == null) + if (conversation == null && create) { conversation = new HttpConversation(this, id); HttpConversation existing = conversations.putIfAbsent(id, conversation); @@ -395,7 +395,7 @@ public class HttpClient extends ContainerLifeCycle { for (ProtocolHandler handler : getProtocolHandlers()) { - if (handler.accept(request, response)) + if (handler.accept(request, response)) return handler; } return null; diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java index 3a76303db95..ee58c05f9de 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java @@ -111,7 +111,7 @@ public class HttpConnection extends AbstractConnection implements Connection idleTimeout = endPoint.getIdleTimeout(); endPoint.setIdleTimeout(request.getIdleTimeout()); - HttpConversation conversation = client.getConversation(request.getConversationID()); + HttpConversation conversation = client.getConversation(request.getConversationID(), true); HttpExchange exchange = new HttpExchange(conversation, this, request, listener); setExchange(exchange); conversation.getExchanges().offer(exchange); diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java index d6baccf9b20..7b1b4ce78bf 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java @@ -331,8 +331,8 @@ public class HttpRequest implements Request aborted = true; if (client.provideDestination(getScheme(), getHost(), getPort()).abort(this, reason)) return true; - HttpConversation conversation = client.getConversation(getConversationID()); - return conversation.abort(reason); + HttpConversation conversation = client.getConversation(getConversationID(), false); + return conversation != null && conversation.abort(reason); } @Override diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java index a301bc053da..2966cc6aeda 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java @@ -123,7 +123,7 @@ public class HttpSender return; final Request request = exchange.getRequest(); - HttpConversation conversation = client.getConversation(request.getConversationID()); + HttpConversation conversation = exchange.getConversation(); HttpGenerator.RequestInfo requestInfo = null; boolean expect100 = request.getHeaders().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString()); diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/RedirectProtocolHandler.java b/jetty-client/src/main/java/org/eclipse/jetty/client/RedirectProtocolHandler.java index a19f428ea1d..dab9a58c969 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/RedirectProtocolHandler.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/RedirectProtocolHandler.java @@ -105,7 +105,7 @@ public class RedirectProtocolHandler extends Response.Listener.Empty implements private void redirect(Result result, HttpMethod method, String location) { final Request request = result.getRequest(); - HttpConversation conversation = client.getConversation(request.getConversationID()); + HttpConversation conversation = client.getConversation(request.getConversationID(), false); Integer redirects = (Integer)conversation.getAttribute(ATTRIBUTE); if (redirects == null) redirects = 0; @@ -151,7 +151,7 @@ public class RedirectProtocolHandler extends Response.Listener.Empty implements { Request request = result.getRequest(); Response response = result.getResponse(); - HttpConversation conversation = client.getConversation(request.getConversationID()); + HttpConversation conversation = client.getConversation(request.getConversationID(), false); Response.Listener listener = conversation.getExchanges().peekFirst().getResponseListener(); // TODO: should we replay all events, or just the failure ? notifier.notifyFailure(listener, response, failure); diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/ResponseNotifier.java b/jetty-client/src/main/java/org/eclipse/jetty/client/ResponseNotifier.java index 7c7d3304b7f..d56a5b36693 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/ResponseNotifier.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/ResponseNotifier.java @@ -126,7 +126,7 @@ public class ResponseNotifier public void forwardSuccessComplete(Response.Listener listener, Request request, Response response) { - HttpConversation conversation = client.getConversation(request.getConversationID()); + HttpConversation conversation = client.getConversation(request.getConversationID(), false); forwardSuccess(listener, response); conversation.complete(); notifyComplete(listener, new Result(request, response)); @@ -143,7 +143,7 @@ public class ResponseNotifier public void forwardFailureComplete(Response.Listener listener, Request request, Throwable requestFailure, Response response, Throwable responseFailure) { - HttpConversation conversation = client.getConversation(request.getConversationID()); + HttpConversation conversation = client.getConversation(request.getConversationID(), false); forwardFailure(listener, response, responseFailure); conversation.complete(); notifyComplete(listener, new Result(request, requestFailure, response, responseFailure));