fix HttpAsyncMethods.createPost/createPut(URI,byte[],ContentType): set entity to request Contributed by Dmitry Potapov <dpotapov at yandex-team.ru> git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/trunk@1758104 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java b/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java index 6efbb14..7fe5f56 100644 --- a/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java +++ b/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java
@@ -233,6 +233,7 @@ final ContentType contentType) { final HttpPost httppost = new HttpPost(requestURI); final NByteArrayEntity entity = new NByteArrayEntity(content, contentType); + httppost.setEntity(entity); final HttpHost target = URIUtils.extractHost(requestURI); return new RequestProducerImpl(target, httppost, entity); } @@ -300,6 +301,7 @@ final ContentType contentType) { final HttpPut httpput = new HttpPut(requestURI); final NByteArrayEntity entity = new NByteArrayEntity(content, contentType); + httpput.setEntity(entity); final HttpHost target = URIUtils.extractHost(requestURI); return new RequestProducerImpl(target, httpput, entity); }
diff --git a/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsync.java b/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsync.java index dc02c06..8a9a5d7 100644 --- a/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsync.java +++ b/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsync.java
@@ -113,6 +113,26 @@ } @Test + public void testHttpAsyncMethods() throws Exception { + final HttpHost target = start(); + final byte[] b1 = new byte[1024]; + final Random rnd = new Random(System.currentTimeMillis()); + rnd.nextBytes(b1); + + final Future<HttpResponse> future = this.httpclient.execute( + HttpAsyncMethods.createPost(target + "/echo/post", b1, null), + new BasicAsyncResponseConsumer(), + null); + final HttpResponse response = future.get(); + Assert.assertNotNull(response); + Assert.assertEquals(200, response.getStatusLine().getStatusCode()); + final HttpEntity entity = response.getEntity(); + Assert.assertNotNull(entity); + final byte[] b2 = EntityUtils.toByteArray(entity); + Assert.assertArrayEquals(b1, b2); + } + + @Test public void testMultiplePostsOverMultipleConnections() throws Exception { final HttpHost target = start(); final byte[] b1 = new byte[1024];