@Test(expectedExceptions = IOException.class) public void testConnectionRefused() throws IOException, InterruptedException { int newPortWithoutAnyoneListening = findFreePort(); try (AsyncHttpClient client = asyncHttpClient(getAsyncHttpClientConfig())) { BoundRequestBuilder r = client.prepareGet("http: CountingOutputStream cos = new CountingOutputStream(); BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(cos); r.execute(bdah); bdah.getResponse(); } }
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();  }