private final Response.ResponseBuilder builder = new Response.ResponseBuilder();
@Override public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { if (accumulateBody) { responseBuilder.accumulate(bodyPart); } State state = State.CONTINUE; try { resumableListener.onBytesReceived(bodyPart.getBodyByteBuffer()); } catch (IOException ex) { return AsyncHandler.State.ABORT; } if (decoratedAsyncHandler != null) { state = decoratedAsyncHandler.onBodyPartReceived(bodyPart); } byteTransferred.addAndGet(bodyPart.getBodyPartBytes().length); resumableProcessor.put(url, byteTransferred.get()); return state; }
@Override public Response onCompleted() throws IOException { if (!responseSet) { response = responseBuilder.build(); responseSet = true; } // Counting down to handle error cases too. // In "normal" cases, latch is already at 0 here // But in other cases, for example when because of some error // onBodyPartReceived() is never called, the caller // of getResponse() would remain blocked infinitely. // By contract, onCompleted() is always invoked, even in case of errors headersArrived.countDown(); closeOut(); try { semaphore.acquire(); if (throwable != null) { throw new IOException(throwable); } else { // sending out current response return responseBuilder.build(); } } catch (InterruptedException e) { return null; } finally { semaphore.release(); } }
private final Response.ResponseBuilder builder = new Response.ResponseBuilder();
private final Response.ResponseBuilder builder = new Response.ResponseBuilder(); private volatile AtomicLong bytesReceived = new AtomicLong(0);
private final Response.ResponseBuilder builder = new Response.ResponseBuilder();
public Response onCompleted() throws IOException { if (!responseSet) { response = responseBuilder.build(); responseSet = true; } // Counting down to handle error cases too. // In "normal" cases, latch is already at 0 here // But in other cases, for example when because of some error // onBodyPartReceived() is never called, the caller // of getResponse() would remain blocked infinitely. // By contract, onCompleted() is always invoked, even in case of errors headersArrived.countDown(); closeOut(); try { semaphore.acquire(); if (throwable != null) { IOException ioe = new IOException(throwable.getMessage()); ioe.initCause(throwable); throw ioe; } else { // sending out current response return responseBuilder.build(); } } catch (InterruptedException e) { return null; } finally { semaphore.release(); } }
/** * {@inheritDoc} */ @Override public AsyncHandler.State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { if (accumulateBody) { responseBuilder.accumulate(bodyPart); } State state = State.CONTINUE; try { resumableListener.onBytesReceived(bodyPart.getBodyByteBuffer()); } catch (IOException ex) { return AsyncHandler.State.ABORT; } if (decoratedAsyncHandler != null) { state = decoratedAsyncHandler.onBodyPartReceived(bodyPart); } byteTransferred.addAndGet(bodyPart.getBodyPartBytes().length); resumableProcessor.put(url, byteTransferred.get()); return state; }
/** * {@inheritDoc} */ @Override public AsyncHandler.State onHeadersReceived(HttpResponseHeaders headers) throws Exception { responseBuilder.accumulate(headers); String contentLengthHeader = headers.getHeaders().getFirstValue("Content-Length"); if (contentLengthHeader != null) { if (Long.parseLong(contentLengthHeader) == -1L) { return AsyncHandler.State.ABORT; } } if (decoratedAsyncHandler != null) { return decoratedAsyncHandler.onHeadersReceived(headers); } return AsyncHandler.State.CONTINUE; }
/** * {@inheritDoc} */ @Override public AsyncHandler.State onStatusReceived(final HttpResponseStatus status) throws Exception { responseBuilder.accumulate(status); if (status.getStatusCode() == 200 || status.getStatusCode() == 206) { url = status.getUri().toUrl(); } else { return AsyncHandler.State.ABORT; } if (decoratedAsyncHandler != null) { return decoratedAsyncHandler.onStatusReceived(status); } return AsyncHandler.State.CONTINUE; }
/** * {@inheritDoc} */ public State onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { if (bytesReceived.addAndGet(content.length()) > MAX_BUFFERED_RESPONSE_SIZE) { // //trash response // for (byte b : content.getBodyPartBytes()) { // b = 0; // } // builder.accumulate(content); return State.ABORT;// TODO we might need to trash the response somehow. } builder.accumulate(content); return State.CONTINUE; }
/** * {@inheritDoc} */ @Override public Response onCompleted() throws Exception { resumableProcessor.remove(url); resumableListener.onAllBytesReceived(); if (decoratedAsyncHandler != null) { decoratedAsyncHandler.onCompleted(); } // Not sure return responseBuilder.build(); }
public State onHeadersReceived(HttpResponseHeaders headers) throws Exception { responseBuilder.accumulate(headers); return State.CONTINUE; }
private static Response.ResponseBuilder responseBuilder(HttpVersion version, HttpResponseStatus status) { return new Response.ResponseBuilder() .accumulate( new NettyResponseStatus( Uri.create(TARGET_URL), new DefaultAsyncHttpClientConfig.Builder().build(), new DefaultHttpResponse(version, status), null ) ); }
/** * {@inheritDoc} */ public State onHeadersReceived(final HttpResponseHeaders headers) throws Exception { builder.accumulate(headers); return State.CONTINUE; }
/** * {@inheritDoc} */ public final T onCompleted() throws Exception { return onCompleted(builder.build()); }
@Override protected ListenableFuture<Response> go(Request request) { Response response = responseBuilder(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST).build(); return GoHandlers.immediateFuture(response); } }
public State onStatusReceived(HttpResponseStatus responseStatus) throws Exception { responseBuilder.reset(); responseBuilder.accumulate(responseStatus); return State.CONTINUE; }
/** * {@inheritDoc} */ public State onHeadersReceived(final HttpResponseHeaders headers) throws Exception { builder.accumulate(headers); return State.CONTINUE; }
/** * {@inheritDoc} */ public final T onCompleted() throws Exception { return onCompleted(builder.build()); }