本文整理汇总了Java中org.asynchttpclient.BoundRequestBuilder.execute方法的典型用法代码示例。如果您正苦于以下问题:Java BoundRequestBuilder.execute方法的具体用法?Java BoundRequestBuilder.execute怎么用?Java BoundRequestBuilder.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.asynchttpclient.BoundRequestBuilder
的用法示例。
在下文中一共展示了BoundRequestBuilder.execute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deferredSimple
import org.asynchttpclient.BoundRequestBuilder; //导入方法依赖的package包/类
@Test(groups = "standalone")
public void deferredSimple() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = asyncHttpClient(getAsyncHttpClientConfig())) {
BoundRequestBuilder r = client.prepareGet("http://localhost:" + port1 + "/deferredSimple");
CountingOutputStream cos = new CountingOutputStream();
BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(cos);
Future<Response> f = r.execute(bdah);
Response resp = bdah.getResponse();
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("content-length"), String.valueOf(HALF_GIG));
// we got headers only, it's probably not all yet here (we have BIG file
// downloading)
assertTrue(cos.getByteCount() <= HALF_GIG);
// now be polite and wait for body arrival too (otherwise we would be
// dropping the "line" on server)
f.get();
// it all should be here now
assertEquals(cos.getByteCount(), HALF_GIG);
}
}
示例2: markDimensionCacheHealthy
import org.asynchttpclient.BoundRequestBuilder; //导入方法依赖的package包/类
/**
* Makes the dimensions passthrough.
* <p>
* This method sends a lastUpdated date to each dimension in the dimension cache, allowing the health checks
* to pass without having to set up a proper dimension loader. For each dimension, d, the following query is
* sent to the /v1/cache/dimensions/d endpoint:
* {
* "name": "d",
* "lastUpdated": "2016-01-01"
* }
*
* @param port The port through which we access the webservice
*
* @throws IOException If something goes terribly wrong when building the JSON or sending it
*/
private static void markDimensionCacheHealthy(int port) throws IOException {
AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient();
for (DimensionConfig dimensionConfig : new WikiDimensions().getAllDimensionConfigurations()) {
String dimension = dimensionConfig.getApiName();
BoundRequestBuilder boundRequestBuilder = asyncHttpClient.preparePost("http://localhost:" + port +
"/v1/cache/dimensions/" + dimension)
.addHeader("Content-type", "application/json")
.setBody(
String.format("{\n \"name\":\"%s\",\n \"lastUpdated\":\"2016-01-01\"\n}", dimension)
);
ListenableFuture<Response> responseFuture = boundRequestBuilder.execute();
try {
Response response = responseFuture.get();
LOG.debug("Mark Dimension Cache Updated Response: ", response);
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Failed while marking dimensions healthy", e);
}
}
}
示例3: deferredSimpleWithFailure
import org.asynchttpclient.BoundRequestBuilder; //导入方法依赖的package包/类
@Test(groups = "standalone", enabled = false)
public void deferredSimpleWithFailure() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = asyncHttpClient(getAsyncHttpClientConfig())) {
BoundRequestBuilder r = client.prepareGet("http://localhost:" + port1 + "/deferredSimpleWithFailure").addHeader("X-FAIL-TRANSFER",
Boolean.TRUE.toString());
CountingOutputStream cos = new CountingOutputStream();
BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(cos);
Future<Response> f = r.execute(bdah);
Response resp = bdah.getResponse();
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("content-length"), String.valueOf(HALF_GIG));
// we got headers only, it's probably not all yet here (we have BIG file
// downloading)
assertTrue(cos.getByteCount() <= HALF_GIG);
// now be polite and wait for body arrival too (otherwise we would be
// dropping the "line" on server)
try {
f.get();
fail("get() should fail with IOException!");
} catch (Exception e) {
// good
}
// it's incomplete, there was an error
assertNotEquals(cos.getByteCount(), HALF_GIG);
}
}
示例4: deferredInputStreamTrick
import org.asynchttpclient.BoundRequestBuilder; //导入方法依赖的package包/类
@Test(groups = "standalone")
public void deferredInputStreamTrick() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = asyncHttpClient(getAsyncHttpClientConfig())) {
BoundRequestBuilder r = client.prepareGet("http://localhost:" + port1 + "/deferredInputStreamTrick");
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(pos);
Future<Response> f = r.execute(bdah);
BodyDeferringInputStream is = new BodyDeferringInputStream(f, bdah, pis);
Response resp = is.getAsapResponse();
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("content-length"), String.valueOf(HALF_GIG));
// "consume" the body, but our code needs input stream
CountingOutputStream cos = new CountingOutputStream();
try {
copy(is, cos);
} finally {
is.close();
cos.close();
}
// now we don't need to be polite, since consuming and closing
// BodyDeferringInputStream does all.
// it all should be here now
assertEquals(cos.getByteCount(), HALF_GIG);
}
}
示例5: deferredInputStreamTrickWithFailure
import org.asynchttpclient.BoundRequestBuilder; //导入方法依赖的package包/类
@Test(groups = "standalone")
public void deferredInputStreamTrickWithFailure() throws IOException, ExecutionException, TimeoutException, InterruptedException {
try (AsyncHttpClient client = asyncHttpClient(getAsyncHttpClientConfig())) {
BoundRequestBuilder r = client.prepareGet("http://localhost:" + port1 + "/deferredInputStreamTrickWithFailure").addHeader("X-FAIL-TRANSFER",
Boolean.TRUE.toString());
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pos);
BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(pos);
Future<Response> f = r.execute(bdah);
BodyDeferringInputStream is = new BodyDeferringInputStream(f, bdah, pis);
Response resp = is.getAsapResponse();
assertNotNull(resp);
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
assertEquals(resp.getHeader("content-length"), String.valueOf(HALF_GIG));
// "consume" the body, but our code needs input stream
CountingOutputStream cos = new CountingOutputStream();
try {
try {
copy(is, cos);
} finally {
is.close();
cos.close();
}
fail("InputStream consumption should fail with IOException!");
} catch (IOException e) {
// good!
}
}
}
示例6: testConnectionRefused
import org.asynchttpclient.BoundRequestBuilder; //导入方法依赖的package包/类
@Test(groups = "standalone", expectedExceptions = IOException.class)
public void testConnectionRefused() throws IOException, ExecutionException, TimeoutException, InterruptedException {
int newPortWithoutAnyoneListening = findFreePort();
try (AsyncHttpClient client = asyncHttpClient(getAsyncHttpClientConfig())) {
BoundRequestBuilder r = client.prepareGet("http://localhost:" + newPortWithoutAnyoneListening + "/testConnectionRefused");
CountingOutputStream cos = new CountingOutputStream();
BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(cos);
r.execute(bdah);
bdah.getResponse();
}
}
示例7: call
import org.asynchttpclient.BoundRequestBuilder; //导入方法依赖的package包/类
public CompletableFuture<WebSocket> call(String url, String origin, WebSocketListener listener) throws ExecutionException, InterruptedException {
final BoundRequestBuilder requestBuilder = client.prepareGet(url).addHeader("Origin", origin);
final WebSocketUpgradeHandler handler = new WebSocketUpgradeHandler.Builder().addWebSocketListener(listener).build();
final ListenableFuture<WebSocket> future = requestBuilder.execute(handler);
final CompletableFuture<WebSocket> completableFuture = future.toCompletableFuture();
return completableFuture;
}
示例8: call
import org.asynchttpclient.BoundRequestBuilder; //导入方法依赖的package包/类
public CompletableFuture<WebSocket> call(String url, WebSocketListener listener) throws ExecutionException, InterruptedException {
BoundRequestBuilder requestBuilder = client.prepareGet(url);
final WebSocketUpgradeHandler handler = new WebSocketUpgradeHandler.Builder().addWebSocketListener(listener).build();
final ListenableFuture<WebSocket> future = requestBuilder.execute(handler);
final CompletableFuture<WebSocket> completableFuture = future.toCompletableFuture();
return completableFuture;
}