@Test(expectedExceptions = RemotelyClosedException.class, enabled = false) public void deferredSimpleWithFailure() throws Throwable { try (AsyncHttpClient client = asyncHttpClient(getAsyncHttpClientConfig())) { BoundRequestBuilder r = client.prepareGet(getTargetUrl()).addHeader("X-FAIL-TRANSFER", Boolean.TRUE.toString()); CountingOutputStream cos = new CountingOutputStream(); BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(cos); Future<Response> f = r.execute(bdah); Response resp = bdah.getResponse(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getHeader(CONTENT_LENGTH), String.valueOf(CONTENT_LENGTH_VALUE)); assertTrue(cos.getByteCount() <= CONTENT_LENGTH_VALUE); try { f.get(); } catch (ExecutionException e) { assertNotEquals(cos.getByteCount(), CONTENT_LENGTH_VALUE); throw e.getCause(); } } }
public Response getResponse() throws InterruptedException, IOException { headersArrived.await(); try { semaphore.acquire(); if (throwable != null) { throw new IOException(throwable.getMessage(), throwable); } else { return response; } } finally { semaphore.release(); } }
BodyDeferringAsyncHandler implements AsyncHandler<Response> { public Response getResponse() throws InterruptedException, IOException { headersArrived.await(); try { semaphore.acquire(); if (throwable != null) { throw new IOException(throwable.getMessage(), throwable); } else { return response; } } finally { semaphore.release(); } } }
BodyDeferringAsyncHandler implements AsyncHandler<Response> { public Response getResponse() throws InterruptedException, IOException { headersArrived.await(); try { semaphore.acquire(); if (throwable != null) { throw new IOException(throwable.getMessage(), throwable); } else { return response; } } finally { semaphore.release(); } } BodyDeferringAsyncHandler(final OutputStream os); }
BodyDeferringAsyncHandler implements AsyncHandler<Response> { public Response getResponse() throws InterruptedException, IOException { headersArrived.await(); try { semaphore.acquire(); if (throwable != null) { throw new IOException(throwable.getMessage(), throwable); } else { return response; } } finally { semaphore.release(); } } BodyDeferringAsyncHandler(final OutputStream os); @Override void onThrowable(Throwable t); @Override State onStatusReceived(HttpResponseStatus responseStatus); @Override State onHeadersReceived(HttpHeaders headers); @Override State onTrailingHeadersReceived(HttpHeaders headers); @Override void onRetry(); @Override State onBodyPartReceived(HttpResponseBodyPart bodyPart); @Override Response onCompleted(); Response getResponse(); }
BodyDeferringAsyncHandler implements AsyncHandler<Response> { public Response getResponse() throws InterruptedException, IOException { headersArrived.await(); try { semaphore.acquire(); if (throwable != null) { throw new IOException(throwable.getMessage(), throwable); } else { return response; } } finally { semaphore.release(); } } BodyDeferringAsyncHandler(final OutputStream os); @Override void onThrowable(Throwable t); @Override State onStatusReceived(HttpResponseStatus responseStatus); @Override State onHeadersReceived(HttpHeaders headers); @Override State onTrailingHeadersReceived(HttpHeaders headers); @Override void onRetry(); @Override State onBodyPartReceived(HttpResponseBodyPart bodyPart); @Override Response onCompleted(); Response getResponse();  }