392959 - Review HttpClient.getConversation(long).
Modified to HttpClient.getConversation(long, boolean) in order to specify whether the conversation must be created or not.
This commit is contained in:
parent
1173916da1
commit
ebb76ecfb9
|
@ -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())
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue