use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class HttpsProxyTest method testRequestProxy.
@Test(groups = "standalone")
public void testRequestProxy() throws Exception {
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setFollowRedirect(true).setUseInsecureTrustManager(true))) {
RequestBuilder rb = get(getTargetUrl2()).setProxyServer(proxyServer("localhost", port1));
Response r = asyncHttpClient.executeRequest(rb.build()).get();
assertEquals(r.getStatusCode(), 200);
}
}
use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.
the class HttpsProxyTest method testPooledConnectionsWithProxy.
@Test(groups = "standalone")
public void testPooledConnectionsWithProxy() throws Exception {
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setFollowRedirect(true).setUseInsecureTrustManager(true).setKeepAlive(true))) {
RequestBuilder rb = get(getTargetUrl2()).setProxyServer(proxyServer("localhost", port1));
Response r1 = asyncHttpClient.executeRequest(rb.build()).get();
assertEquals(r1.getStatusCode(), 200);
Response r2 = asyncHttpClient.executeRequest(rb.build()).get();
assertEquals(r2.getStatusCode(), 200);
}
}
use of org.asynchttpclient.Response in project RestyPass by darren-fu.
the class RestyFuture method get.
@SuppressWarnings("NullableProblems")
@Override
public T get(long timeout, TimeUnit unit) throws RestyException {
Response response;
try {
response = future.get(timeout, unit);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
future.abort(e);
log.error("获取响应失败:{}", e.getMessage());
if (this.getRestyCommand().isAsyncArg() || this.getRestyCommand().isAsyncReturn()) {
throw new RestyException(e);
}
response = FailedResponse.create(new ConnectionException(e));
}
T resp = (T) ResponseConverterContext.DEFAULT.convertResponse(restyCommand, response);
if (restyCommand.isAsyncReturn() || restyCommand.isAsyncArg()) {
if (RestyCommandStatus.FAILED == restyCommand.getStatus() && restyCommand.getFailException() != null) {
throw restyCommand.getFailException();
}
}
return resp;
}
use of org.asynchttpclient.Response in project bullet-core by yahoo.
the class RESTPubSubTest method mockBuilderWith.
public static BoundRequestBuilder mockBuilderWith(CompletableFuture<Response> future) throws Exception {
ListenableFuture<Response> mockListenable = (ListenableFuture<Response>) mock(ListenableFuture.class);
doReturn(future.get()).when(mockListenable).get();
doReturn(future).when(mockListenable).toCompletableFuture();
BoundRequestBuilder mockBuilder = mock(BoundRequestBuilder.class);
doReturn(mockBuilder).when(mockBuilder).setHeader(any(), anyString());
doReturn(mockBuilder).when(mockBuilder).setBody(anyString());
doReturn(mockListenable).when(mockBuilder).execute();
return mockBuilder;
}
use of org.asynchttpclient.Response in project bullet-core by yahoo.
the class RESTQueryPublisherTest method testSendMetadataCreated.
@Test
public void testSendMetadataCreated() throws Exception {
CompletableFuture<Response> response = getOkFuture(getOkResponse(null));
BoundRequestBuilder mockBuilder = mockBuilderWith(response);
AsyncHttpClient mockClient = mockClientWith(mockBuilder);
RESTQueryPublisher publisher = new RESTQueryPublisher(mockClient, "my/custom/query/url", "my/custom/result/url");
publisher.send("foo", "bar");
verify(mockClient).preparePost("my/custom/query/url");
verify(mockBuilder).setBody("{\"id\":\"foo\",\"sequence\":-1,\"content\":\"bar\",\"metadata\":{\"signal\":null,\"content\":\"my/custom/result/url\"}}");
verify(mockBuilder).setHeader(RESTPublisher.CONTENT_TYPE, RESTPublisher.APPLICATION_JSON);
}
Aggregations