@Test(groups = {"standalone", "default_provider"}) public void basicByteBufferTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { File largeFile = createTempFile(1024 * 100 * 10); final AtomicInteger byteReceived = new AtomicInteger(); try { Response response = c.preparePut(getTargetUrl()) .setBody(largeFile) .execute( new AsyncCompletionHandlerAdapter() { @Override public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { byteReceived.addAndGet(content.getBodyByteBuffer().capacity()); return super.onBodyPartReceived(content); } }) .get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(byteReceived.get(), largeFile.length()); assertEquals(response.getResponseBody().length(), largeFile.length()); } catch (IOException ex) { fail("Should have timed out"); } } finally { c.close(); } }
@Test(groups = {"standalone", "default_provider"}) public void Expect100Continue() throws Exception { try (AsyncHttpClient client = getAsyncHttpClient(null)) { Future<Response> f = client .preparePut("http://127.0.0.1:" + port1 + "/") .setHeader("Expect", "100-continue") .setBody(SIMPLE_TEXT_FILE) .execute(); Response resp = f.get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); } }
@Test(groups = {"standalone", "default_provider"}) public void testOmitErrorBody() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder() .setProviderClass(getProviderClass()) .setUrl(getTargetUrl() + "/nonexistent") .setErrorDocumentBehaviour(ErrorDocumentBehaviour.OMIT) .build(); try { ByteArrayOutputStream o = new ByteArrayOutputStream(10); Future<Response> future = client.get(new OutputStreamBodyConsumer(o)); System.out.println("waiting for response"); Response response = future.get(); assertEquals(response.getStatusCode(), 404); assertEquals(o.toString(), ""); assertEquals(response.getResponseBody(), ""); } finally { client.close(); } }