@Override public void parsedTrailer(HttpField trailer) { HttpExchange exchange = getHttpExchange(); if (exchange == null) return; exchange.getResponse().trailer(trailer); }
@Override public void onFailure(Response response, Throwable failure) { HttpConversation conversation = client.getConversation(response.getConversationID(), false); // Mark the 100 Continue response as handled conversation.setAttribute(ATTRIBUTE, Boolean.TRUE); // Reset the conversation listeners to allow the conversation to be completed conversation.updateResponseListeners(null); HttpExchange exchange = conversation.getExchanges().peekLast(); assert exchange.getResponse() == response; List<Response.ResponseListener> listeners = exchange.getResponseListeners(); HttpContentResponse contentResponse = new HttpContentResponse(response, getContent(), getEncoding()); notifier.forwardFailureComplete(listeners, exchange.getRequest(), exchange.getRequestFailure(), contentResponse, failure); }
public Result terminateRequest() { Result result = null; synchronized (this) { if (requestState == State.COMPLETED) requestState = State.TERMINATED; if (requestState == State.TERMINATED && responseState == State.TERMINATED) result = new Result(getRequest(), requestFailure, getResponse(), responseFailure); } if (LOG.isDebugEnabled()) LOG.debug("Terminated request for {}, result: {}", this, result); return result; }
@Override public void onFailure(Response response, Throwable failure) { HttpConversation conversation = client.getConversation(response.getConversationID(), false); // Mark the 100 Continue response as handled conversation.setAttribute(ATTRIBUTE, Boolean.TRUE); // Reset the conversation listeners to allow the conversation to be completed conversation.updateResponseListeners(null); HttpExchange exchange = conversation.getExchanges().peekLast(); assert exchange.getResponse() == response; List<Response.ResponseListener> listeners = exchange.getResponseListeners(); HttpContentResponse contentResponse = new HttpContentResponse(response, getContent(), getEncoding()); notifier.forwardFailureComplete(listeners, exchange.getRequest(), exchange.getRequestFailure(), contentResponse, failure); }
public Result terminateResponse() { Result result = null; synchronized (this) { if (responseState == State.COMPLETED) responseState = State.TERMINATED; if (requestState == State.TERMINATED && responseState == State.TERMINATED) result = new Result(getRequest(), requestFailure, getResponse(), responseFailure); } if (LOG.isDebugEnabled()) LOG.debug("Terminated response for {}, result: {}", this, result); return result; }
@Override public void onFailure(Response response, Throwable failure) { HttpConversation conversation = ((HttpRequest)response.getRequest()).getConversation(); // Mark the 100 Continue response as handled conversation.setAttribute(ATTRIBUTE, Boolean.TRUE); // Reset the conversation listeners to allow the conversation to be completed conversation.updateResponseListeners(null); HttpExchange exchange = conversation.getExchanges().peekLast(); assert exchange.getResponse() == response; List<Response.ResponseListener> listeners = exchange.getResponseListeners(); HttpContentResponse contentResponse = new HttpContentResponse(response, getContent(), getMediaType(), getEncoding()); notifier.forwardFailureComplete(listeners, exchange.getRequest(), exchange.getRequestFailure(), contentResponse, failure); }
@Override public void badMessage(int status, String reason) { HttpExchange exchange = connection.getExchange(); HttpResponse response = exchange.getResponse(); response.status(status).reason(reason); failAndClose(new HttpResponseException("HTTP protocol violation: bad response", response)); }
@Override public void badMessage(int status, String reason) { HttpExchange exchange = connection.getExchange(); HttpResponse response = exchange.getResponse(); response.status(status).reason(reason); failAndClose(new HttpResponseException("HTTP protocol violation: bad response", response)); }
@Override public boolean content(ByteBuffer buffer) { if (updateState(State.RECEIVE, State.RECEIVE)) { HttpExchange exchange = connection.getExchange(); // The exchange may be null if it failed concurrently if (exchange != null) { HttpConversation conversation = exchange.getConversation(); HttpResponse response = exchange.getResponse(); LOG.debug("Content {}: {} bytes", response, buffer.remaining()); ContentDecoder decoder = this.decoder; if (decoder != null) { buffer = decoder.decode(buffer); LOG.debug("{} {}: {} bytes", decoder, response, buffer.remaining()); } ResponseNotifier notifier = connection.getDestination().getResponseNotifier(); notifier.notifyContent(conversation.getResponseListeners(), response, buffer); } } return false; }
@Override public void badMessage(BadMessageException failure) { HttpExchange exchange = getHttpExchange(); if (exchange != null) { HttpResponse response = exchange.getResponse(); response.status(failure.getCode()).reason(failure.getReason()); failAndClose(new HttpResponseException("HTTP protocol violation: bad response on " + getHttpConnection(), response, failure)); } }
@Override public boolean messageComplete() { HttpExchange exchange = getHttpExchange(); if (exchange == null) return false; int status = exchange.getResponse().getStatus(); if (status != HttpStatus.CONTINUE_100) complete = true; boolean proceed = responseSuccess(exchange); if (!proceed) return true; if (status == HttpStatus.SWITCHING_PROTOCOLS_101) return true; if (HttpMethod.CONNECT.is(exchange.getRequest().getMethod()) && status == HttpStatus.OK_200) return true; return false; }
@Override public boolean content(ByteBuffer buffer) { if (updateState(State.RECEIVE, State.RECEIVE)) { HttpExchange exchange = connection.getExchange(); // The exchange may be null if it failed concurrently if (exchange != null) { HttpConversation conversation = exchange.getConversation(); HttpResponse response = exchange.getResponse(); LOG.debug("Content {}: {} bytes", response, buffer.remaining()); ContentDecoder decoder = this.decoder; if (decoder != null) { buffer = decoder.decode(buffer); LOG.debug("{} {}: {} bytes", decoder, response, buffer.remaining()); } ResponseNotifier notifier = connection.getDestination().getResponseNotifier(); notifier.notifyContent(conversation.getResponseListeners(), response, buffer); } } return false; }
return result; HttpResponse response = exchange.getResponse();
protected void abort(HttpExchange exchange, Throwable cause) { Request request = exchange.getRequest(); HttpResponse response = exchange.getResponse(); getRequestNotifier().notifyFailure(request, cause); List<Response.ResponseListener> listeners = exchange.getConversation().getResponseListeners(); getResponseNotifier().notifyFailure(listeners, response, cause); getResponseNotifier().notifyComplete(listeners, new Result(request, cause, response, cause)); }
protected void abort(HttpExchange exchange, Throwable cause) { Request request = exchange.getRequest(); HttpResponse response = exchange.getResponse(); getRequestNotifier().notifyFailure(request, cause); List<Response.ResponseListener> listeners = exchange.getConversation().getResponseListeners(); getResponseNotifier().notifyFailure(listeners, response, cause); getResponseNotifier().notifyComplete(listeners, new Result(request, cause, response, cause)); }
@Override public boolean startResponse(HttpVersion version, int status, String reason) { HttpExchange exchange = getHttpExchange(); if (exchange == null) return false; String method = exchange.getRequest().getMethod(); parser.setHeadResponse(HttpMethod.HEAD.is(method) || (HttpMethod.CONNECT.is(method) && status == HttpStatus.OK_200)); exchange.getResponse().version(version).status(status).reason(reason); return !responseBegin(exchange); }
protected boolean success() { HttpExchange exchange = connection.getExchange(); if (exchange == null) return false; AtomicMarkableReference<Result> completion = exchange.responseComplete(null); if (!completion.isMarked()) return false; parser.reset(); decoder = null; if (!updateState(State.RECEIVE, State.IDLE)) throw new IllegalStateException(); exchange.terminateResponse(); HttpResponse response = exchange.getResponse(); List<Response.ResponseListener> listeners = exchange.getConversation().getResponseListeners(); ResponseNotifier notifier = connection.getDestination().getResponseNotifier(); notifier.notifySuccess(listeners, response); LOG.debug("Received {}", response); Result result = completion.getReference(); if (result != null) { connection.complete(exchange, !result.isFailed()); notifier.notifyComplete(listeners, result); } return true; }
protected boolean success() { HttpExchange exchange = connection.getExchange(); if (exchange == null) return false; AtomicMarkableReference<Result> completion = exchange.responseComplete(null); if (!completion.isMarked()) return false; parser.reset(); decoder = null; if (!updateState(State.RECEIVE, State.IDLE)) throw new IllegalStateException(); exchange.terminateResponse(); HttpResponse response = exchange.getResponse(); List<Response.ResponseListener> listeners = exchange.getConversation().getResponseListeners(); ResponseNotifier notifier = connection.getDestination().getResponseNotifier(); notifier.notifySuccess(listeners, response); LOG.debug("Received {}", response); Result result = completion.getReference(); if (result != null) { connection.complete(exchange, !result.isFailed()); notifier.notifyComplete(listeners, result); } return true; }
private void terminateResponse(HttpExchange exchange, Result result) { HttpResponse response = exchange.getResponse(); if (LOG.isDebugEnabled()) LOG.debug("Response complete {}", response); if (result != null) { result = channel.exchangeTerminating(exchange, result); boolean ordered = getHttpDestination().getHttpClient().isStrictEventOrdering(); if (!ordered) channel.exchangeTerminated(exchange, result); if (LOG.isDebugEnabled()) LOG.debug("Request/Response {}: {}", failure == null ? "succeeded" : "failed", result); List<Response.ResponseListener> listeners = exchange.getConversation().getResponseListeners(); ResponseNotifier notifier = getHttpDestination().getResponseNotifier(); notifier.notifyComplete(listeners, result); if (ordered) channel.exchangeTerminated(exchange, result); } }
@Override public boolean startResponse(HttpVersion version, int status, String reason) { if (updateState(State.IDLE, State.RECEIVE)) { HttpExchange exchange = connection.getExchange(); // The exchange may be null if it failed concurrently if (exchange != null) { HttpConversation conversation = exchange.getConversation(); HttpResponse response = exchange.getResponse(); parser.setHeadResponse(exchange.getRequest().getMethod() == HttpMethod.HEAD); response.version(version).status(status).reason(reason); // Probe the protocol handlers HttpClient client = connection.getHttpClient(); ProtocolHandler protocolHandler = client.findProtocolHandler(exchange.getRequest(), response); Response.Listener handlerListener = null; if (protocolHandler != null) { handlerListener = protocolHandler.getResponseListener(); LOG.debug("Found protocol handler {}", protocolHandler); } exchange.getConversation().updateResponseListeners(handlerListener); LOG.debug("Receiving {}", response); ResponseNotifier notifier = connection.getDestination().getResponseNotifier(); notifier.notifyBegin(conversation.getResponseListeners(), response); } } return false; }