use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class AsyncHttpClientCallTest method responseWithBody.
private Response responseWithBody(String contentType, String content) {
Response response = aResponse();
when(response.hasResponseBody()).thenReturn(true);
when(response.getContentType()).thenReturn(contentType);
when(response.getResponseBodyAsBytes()).thenReturn(content.getBytes(StandardCharsets.UTF_8));
return response;
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class AsyncHttpObservableTest method testObserveMultiple.
@Test
public void testObserveMultiple() {
final TestSubscriber<Response> tester = new TestSubscriber<>();
try (AsyncHttpClient client = asyncHttpClient()) {
Observable<Response> o1 = AsyncHttpObservable.observe(() -> client.prepareGet("https://gatling.io"));
Observable<Response> o2 = AsyncHttpObservable.observe(() -> client.prepareGet("http://www.wisc.edu").setFollowRedirect(true));
Observable<Response> o3 = AsyncHttpObservable.observe(() -> client.prepareGet("http://www.umn.edu").setFollowRedirect(true));
Observable<Response> all = Observable.merge(o1, o2, o3);
all.subscribe(tester);
tester.awaitTerminalEvent();
tester.assertTerminalEvent();
tester.assertNoErrors();
tester.assertCompleted();
List<Response> responses = tester.getOnNextEvents();
assertNotNull(responses);
assertEquals(responses.size(), 3);
for (Response response : responses) {
assertEquals(response.getStatusCode(), 200);
}
} catch (Exception e) {
Thread.currentThread().interrupt();
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class MultipartUploadTest method sendFileInputStream.
private void sendFileInputStream(boolean useContentLength, boolean disableZeroCopy) throws Exception {
File file = getClasspathFile("textfile.txt");
try (AsyncHttpClient c = asyncHttpClient(config().setDisableZeroCopy(disableZeroCopy))) {
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
InputStreamPart part;
if (useContentLength) {
part = new InputStreamPart("file", inputStream, file.getName(), file.length());
} else {
part = new InputStreamPart("file", inputStream, file.getName());
}
Request r = post("http://localhost" + ":" + port1 + "/upload").addBodyPart(part).build();
Response res = c.executeRequest(r).get();
assertEquals(res.getStatusCode(), 200);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class MultipartUploadTest method sendEmptyFile0.
private void sendEmptyFile0(boolean disableZeroCopy) throws Exception {
File file = getClasspathFile("empty.txt");
try (AsyncHttpClient c = asyncHttpClient(config().setDisableZeroCopy(disableZeroCopy))) {
Request r = post("http://localhost" + ":" + port1 + "/upload").addBodyPart(new FilePart("file", file, "text/plain", UTF_8)).build();
Response res = c.executeRequest(r).get();
assertEquals(res.getStatusCode(), 200);
}
}
use of org.asynchttpclient.Response 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);
}
}
Aggregations