Search in sources :

Example 1 with InputStreamPart

use of org.asynchttpclient.request.body.multipart.InputStreamPart in project async-http-client by AsyncHttpClient.

the class InputStreamPartLargeFileTest method testPutLargeTextFileUnknownSize.

@Test
public void testPutLargeTextFileUnknownSize() throws Exception {
    File file = createTempFile(1024 * 1024);
    InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
    try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
        Response response = client.preparePut(getTargetUrl()).addBodyPart(new InputStreamPart("test", inputStream, file.getName(), -1, "application/octet-stream", UTF_8)).execute().get();
        assertEquals(response.getStatusCode(), 200);
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.asynchttpclient.Response) ServletInputStream(javax.servlet.ServletInputStream) InputStreamPart(org.asynchttpclient.request.body.multipart.InputStreamPart) TestUtils.createTempFile(org.asynchttpclient.test.TestUtils.createTempFile) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 2 with InputStreamPart

use of org.asynchttpclient.request.body.multipart.InputStreamPart in project async-http-client by AsyncHttpClient.

the class InputStreamPartLargeFileTest method testPutImageFileUnknownSize.

@Test
public void testPutImageFileUnknownSize() throws Exception {
    try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
        InputStream inputStream = new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE));
        Response response = client.preparePut(getTargetUrl()).addBodyPart(new InputStreamPart("test", inputStream, LARGE_IMAGE_FILE.getName(), -1, "application/octet-stream", UTF_8)).execute().get();
        assertEquals(response.getStatusCode(), 200);
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.asynchttpclient.Response) ServletInputStream(javax.servlet.ServletInputStream) InputStreamPart(org.asynchttpclient.request.body.multipart.InputStreamPart) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 3 with InputStreamPart

use of org.asynchttpclient.request.body.multipart.InputStreamPart in project async-http-client by AsyncHttpClient.

the class InputStreamPartLargeFileTest method testPutLargeTextFile.

@Test
public void testPutLargeTextFile() throws Exception {
    File file = createTempFile(1024 * 1024);
    InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
    try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
        Response response = client.preparePut(getTargetUrl()).addBodyPart(new InputStreamPart("test", inputStream, file.getName(), file.length(), "application/octet-stream", UTF_8)).execute().get();
        assertEquals(response.getStatusCode(), 200);
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.asynchttpclient.Response) ServletInputStream(javax.servlet.ServletInputStream) InputStreamPart(org.asynchttpclient.request.body.multipart.InputStreamPart) TestUtils.createTempFile(org.asynchttpclient.test.TestUtils.createTempFile) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 4 with InputStreamPart

use of org.asynchttpclient.request.body.multipart.InputStreamPart in project async-http-client by AsyncHttpClient.

the class InputStreamPartLargeFileTest method testPutImageFile.

@Test
public void testPutImageFile() throws Exception {
    try (AsyncHttpClient client = asyncHttpClient(config().setRequestTimeout(100 * 6000))) {
        InputStream inputStream = new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE));
        Response response = client.preparePut(getTargetUrl()).addBodyPart(new InputStreamPart("test", inputStream, LARGE_IMAGE_FILE.getName(), LARGE_IMAGE_FILE.length(), "application/octet-stream", UTF_8)).execute().get();
        assertEquals(response.getStatusCode(), 200);
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.asynchttpclient.Response) ServletInputStream(javax.servlet.ServletInputStream) InputStreamPart(org.asynchttpclient.request.body.multipart.InputStreamPart) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Aggregations

ServletInputStream (javax.servlet.ServletInputStream)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)4 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)4 Response (org.asynchttpclient.Response)4 InputStreamPart (org.asynchttpclient.request.body.multipart.InputStreamPart)4 Test (org.testng.annotations.Test)4 TestUtils.createTempFile (org.asynchttpclient.test.TestUtils.createTempFile)2