本文整理汇总了Java中org.asynchttpclient.RequestBuilder类的典型用法代码示例。如果您正苦于以下问题:Java RequestBuilder类的具体用法?Java RequestBuilder怎么用?Java RequestBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestBuilder类属于org.asynchttpclient包,在下文中一共展示了RequestBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:22,代码来源:ConnectSuccessInterceptor.java
示例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();
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:26,代码来源:ResumableAsyncHandler.java
示例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()));
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:20,代码来源:ConnectionPoolTest.java
示例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);
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:23,代码来源:BodyChunkTest.java
示例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>"));
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:19,代码来源:WebDavBasicTest.java
示例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");
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:22,代码来源:FilterTest.java
示例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");
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:22,代码来源:FilterTest.java
示例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");
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:22,代码来源:FilterTest.java
示例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);
}
}
}
开发者ID:globocom,项目名称:groot,代码行数:14,代码来源:RequestExecutorService.java
示例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];
}
开发者ID:globocom,项目名称:groot,代码行数:9,代码来源:RequestExecutorService.java
示例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);
}
}
开发者ID:globocom,项目名称:groot,代码行数:9,代码来源:RequestExecutorService.java
示例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();
}
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:11,代码来源:AsyncRequestConverter.java
示例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();
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:16,代码来源:ConnectionPoolTest.java
示例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);
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:12,代码来源:ChunkingTest.java
示例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);
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:8,代码来源:RetryNonBlockingIssue.java
示例16: testRequestProxy
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void testRequestProxy() throws Exception {
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setFollowRedirect(true).setAcceptAnyCertificate(true))) {
RequestBuilder rb = get(getTargetUrl2()).setProxyServer(proxyServer("localhost", port1));
Response r = asyncHttpClient.executeRequest(rb.build()).get();
assertEquals(r.getStatusCode(), 200);
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:10,代码来源:HttpsProxyTest.java
示例17: testPooledConnectionsWithProxy
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void testPooledConnectionsWithProxy() throws Exception {
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setFollowRedirect(true).setAcceptAnyCertificate(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);
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:14,代码来源:HttpsProxyTest.java
示例18: mkcolWebDavTest1
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void mkcolWebDavTest1() 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);
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:9,代码来源:WebDavBasicTest.java
示例19: mkcolWebDavTest2
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void mkcolWebDavTest2() throws InterruptedException, IOException, ExecutionException {
try (AsyncHttpClient c = asyncHttpClient()) {
Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl() + "/folder2").build();
Response response = c.executeRequest(mkcolRequest).get();
assertEquals(response.getStatusCode(), 409);
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:9,代码来源:WebDavBasicTest.java
示例20: basicPropFindWebDavTest
import org.asynchttpclient.RequestBuilder; //导入依赖的package包/类
@Test(groups = "standalone")
public void basicPropFindWebDavTest() throws InterruptedException, IOException, ExecutionException {
try (AsyncHttpClient c = asyncHttpClient()) {
Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(getTargetUrl()).build();
Response response = c.executeRequest(propFindRequest).get();
assertEquals(response.getStatusCode(), 404);
}
}
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:10,代码来源:WebDavBasicTest.java
注:本文中的org.asynchttpclient.RequestBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论