本文整理汇总了Java中org.asynchttpclient.RequestBuilder类的典型用法代码示例。如果您正苦于以下问题:Java RequestBuilder类的具体用法?Java RequestBuilder怎么用?Java RequestBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestBuilder类属于org.asynchttpclient包,在下文中一共展示了RequestBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exitAfterHandlingConnect
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
public boolean exitAfterHandlingConnect(//
final Channel channel,//
final NettyResponseFuture<?> future,//
final Request request,//
ProxyServer proxyServer,//
int statusCode,//
HttpRequest httpRequest) throws IOException {
if (future.isKeepAlive())
future.attachChannel(channel, true);
Uri requestUri = request.getUri();
LOGGER.debug("Connecting to proxy {} for scheme {}", proxyServer, requestUri.getScheme());
channelManager.upgradeProtocol(channel.pipeline(), requestUri);
future.setReuseChannel(true);
future.setConnectAllowed(false);
requestSender.drainChannelAndExecuteNextRequest(channel, future, new RequestBuilder(future.getTargetRequest()).build());
return true;
}
示例2: adjustRequestRange
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
/**
* Invoke this API if you want to set the Range header on your {@link Request} based on the last valid bytes
* position.
*
* @param request {@link Request}
* @return a {@link Request} with the Range header properly set.
*/
public Request adjustRequestRange(Request request) {
Long ri = resumableIndex.get(request.getUrl());
if (ri != null) {
byteTransferred.set(ri);
}
// The Resumable
if (resumableListener != null && resumableListener.length() > 0 && byteTransferred.get() != resumableListener.length()) {
byteTransferred.set(resumableListener.length());
}
RequestBuilder builder = new RequestBuilder(request);
if (request.getHeaders().get(HttpHeaders.Names.RANGE) == null && byteTransferred.get() != 0) {
builder.setHeader(HttpHeaders.Names.RANGE, "bytes=" + byteTransferred.get() + "-");
}
return builder.build();
}
示例3: testPooledEventsFired
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void testPooledEventsFired() throws Exception {
RequestBuilder request = get("http://localhost:" + port1 + "/Test");
try (AsyncHttpClient client = asyncHttpClient()) {
EventCollectingHandler firstHandler = new EventCollectingHandler();
client.executeRequest(request, firstHandler).get(3, TimeUnit.SECONDS);
firstHandler.waitForCompletion(3, TimeUnit.SECONDS);
EventCollectingHandler secondHandler = new EventCollectingHandler();
client.executeRequest(request, secondHandler).get(3, TimeUnit.SECONDS);
secondHandler.waitForCompletion(3, TimeUnit.SECONDS);
Object[] expectedEvents = new Object[] { CONNECTION_POOL_EVENT, CONNECTION_POOLED_EVENT, REQUEST_SEND_EVENT, HEADERS_WRITTEN_EVENT, STATUS_RECEIVED_EVENT,
HEADERS_RECEIVED_EVENT, CONNECTION_OFFER_EVENT, COMPLETED_EVENT };
assertEquals(secondHandler.firedEvents.toArray(), expectedEvents, "Got " + Arrays.toString(secondHandler.firedEvents.toArray()));
}
}
示例4: negativeContentTypeTest
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void negativeContentTypeTest() throws Exception {
AsyncHttpClientConfig config = config()//
.setConnectTimeout(100)//
.setMaxConnections(50)//
.setRequestTimeout(5 * 60 * 1000) // 5 minutes
.build();
try (AsyncHttpClient client = asyncHttpClient(config)) {
RequestBuilder requestBuilder = post(getTargetUrl())//
.setHeader("Content-Type", "message/rfc822")//
.setBody(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())));
Future<Response> future = client.executeRequest(requestBuilder.build());
System.out.println("waiting for response");
Response response = future.get();
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getResponseBody(), MY_MESSAGE);
}
}
示例5: propFindWebDavTest
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void propFindWebDavTest() throws InterruptedException, IOException, ExecutionException {
try (AsyncHttpClient c = asyncHttpClient()) {
Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl()).build();
Response response = c.executeRequest(mkcolRequest).get();
assertEquals(response.getStatusCode(), 201);
Request putRequest = put(String.format("http://localhost:%s/folder1/Test.txt", port1)).setBody("this is a test").build();
response = c.executeRequest(putRequest).get();
assertEquals(response.getStatusCode(), 201);
Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(String.format("http://localhost:%s/folder1/Test.txt", port1)).build();
response = c.executeRequest(propFindRequest).get();
assertEquals(response.getStatusCode(), 207);
assertTrue(response.getResponseBody().contains("<status>HTTP/1.1 200 OK</status>"));
}
}
示例6: replayResponseFilterTest
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void replayResponseFilterTest() throws Exception {
final AtomicBoolean replay = new AtomicBoolean(true);
ResponseFilter responseFilter = new ResponseFilter() {
public <T> FilterContext<T> filter(FilterContext<T> ctx) throws FilterException {
if (replay.getAndSet(false)) {
Request request = new RequestBuilder(ctx.getRequest()).addHeader("X-Replay", "true").build();
return new FilterContext.FilterContextBuilder<T>().asyncHandler(ctx.getAsyncHandler()).request(request).replayRequest(true).build();
}
return ctx;
}
};
try (AsyncHttpClient c = asyncHttpClient(config().addResponseFilter(responseFilter))) {
Response response = c.preparePost(getTargetUrl()).execute().get();
assertNotNull(response);
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getHeader("X-Replay"), "true");
}
}
示例7: replayStatusCodeResponseFilterTest
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void replayStatusCodeResponseFilterTest() throws Exception {
final AtomicBoolean replay = new AtomicBoolean(true);
ResponseFilter responseFilter = new ResponseFilter() {
public <T> FilterContext<T> filter(FilterContext<T> ctx) throws FilterException {
if (ctx.getResponseStatus() != null && ctx.getResponseStatus().getStatusCode() == 200 && replay.getAndSet(false)) {
Request request = new RequestBuilder(ctx.getRequest()).addHeader("X-Replay", "true").build();
return new FilterContext.FilterContextBuilder<T>().asyncHandler(ctx.getAsyncHandler()).request(request).replayRequest(true).build();
}
return ctx;
}
};
try (AsyncHttpClient c = asyncHttpClient(config().addResponseFilter(responseFilter))) {
Response response = c.preparePost(getTargetUrl()).execute().get();
assertNotNull(response);
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getHeader("X-Replay"), "true");
}
}
示例8: replayHeaderResponseFilterTest
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void replayHeaderResponseFilterTest() throws Exception {
final AtomicBoolean replay = new AtomicBoolean(true);
ResponseFilter responseFilter = new ResponseFilter() {
public <T> FilterContext<T> filter(FilterContext<T> ctx) throws FilterException {
if (ctx.getResponseHeaders() != null && ctx.getResponseHeaders().getHeaders().get("Ping").equals("Pong") && replay.getAndSet(false)) {
Request request = new RequestBuilder(ctx.getRequest()).addHeader("Ping", "Pong").build();
return new FilterContext.FilterContextBuilder<T>().asyncHandler(ctx.getAsyncHandler()).request(request).replayRequest(true).build();
}
return ctx;
}
};
try (AsyncHttpClient c = asyncHttpClient(config().addResponseFilter(responseFilter))) {
Response response = c.preparePost(getTargetUrl()).addHeader("Ping", "Pong").execute().get();
assertNotNull(response);
assertEquals(response.getStatusCode(), 200);
assertEquals(response.getHeader("Ping"), "Pong");
}
}
示例9: execute
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
public void execute(final AsyncHttpClient asyncHttpClient, long fixedDelay) throws InterruptedException {
if (requestsCanSaveCookies()) {
for (RequestBuilder requestBuilder : requestBuilders) {
asyncHttpClient.executeRequest(requestBuilder.setCookies(cookieStorage), new NoBodyCopyAsyncHandler());
TimeUnit.MILLISECONDS.sleep(fixedDelay);
}
} else {
for (Request request : requests) {
asyncHttpClient.executeRequest(request, new NoBodyCopyAsyncHandler());
TimeUnit.MILLISECONDS.sleep(fixedDelay);
}
}
}
示例10: preBuildRequests
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
private void preBuildRequests() {
int pos = 0;
requests = new Request[requestBuilders.length];
for (RequestBuilder requestBuilder: requestBuilders) {
requests[pos++] = requestBuilder.build();
}
requestBuilders = new RequestBuilder[0];
}
示例11: prepareRequests
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
private void prepareRequests(Map<String, Object> testProperties) {
HashMap<String, Object>[] allRequestProperties = PropertiesUtils.extractAllRequestPropertiesOrdered(testProperties);
requestBuilders = new RequestBuilder[allRequestProperties.length];
int pos = 0;
for (HashMap<String, Object> requestProperties: allRequestProperties) {
requestBuilders[pos++] = new ParameterizedRequest(requestProperties);
}
}
示例12: apply
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
public Request apply(SignableRequest<?> signableRequest) {
Multimap<String, String> headers = ArrayListMultimap.create(Multimaps.forMap(signableRequest.getHeaders()));
headers.put(HttpHeaders.Names.CONTENT_TYPE, HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED);
return new RequestBuilder()
.setMethod(signableRequest.getHttpMethod().name())
.setUrl(signableRequest.getEndpoint().resolve(signableRequest.getResourcePath()).toString())
.setHeaders(headers.asMap())
.setBody(SdkHttpUtils.encodeParameters(signableRequest))
.build();
}
示例13: nonPoolableConnectionReleaseSemaphoresTest
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void nonPoolableConnectionReleaseSemaphoresTest() throws Throwable {
RequestBuilder request = get(getTargetUrl()).setHeader("Connection", "close");
try (AsyncHttpClient client = asyncHttpClient(config().setMaxConnections(6).setMaxConnectionsPerHost(3))) {
client.executeRequest(request).get();
Thread.sleep(1000);
client.executeRequest(request).get();
Thread.sleep(1000);
client.executeRequest(request).get();
Thread.sleep(1000);
client.executeRequest(request).get();
}
}
示例14: doTestWithInputStreamBodyGenerator
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
public void doTestWithInputStreamBodyGenerator(InputStream is) throws Throwable {
try (AsyncHttpClient c = asyncHttpClient(httpClientBuilder())) {
RequestBuilder builder = post(getTargetUrl()).setBody(new InputStreamBodyGenerator(is));
Request r = builder.build();
final ListenableFuture<Response> responseFuture = c.executeRequest(r);
waitForAndAssertResponse(responseFuture);
}
}
示例15: testMethodRequest
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
private ListenableFuture<Response> testMethodRequest(AsyncHttpClient client, int requests, String action, String id) throws IOException {
RequestBuilder r = get(getTargetUrl())//
.addQueryParam(action, "1")//
.addQueryParam("maxRequests", "" + requests)//
.addQueryParam("id", id);
return client.executeRequest(r);
}