本文整理汇总了Java中org.asynchttpclient.Request类的典型用法代码示例。如果您正苦于以下问题:Java Request类的具体用法?Java Request怎么用?Java Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Request类属于org.asynchttpclient包,在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendRequest
import org.asynchttpclient.Request; //导入依赖的package包/类
@Override
public <T> Single<T> sendRequest(SqsAction<T> action) {
Request asyncRequest = action.toHttpRequest(credentialsProvider.getCredentials());
SingleSubject<T> responseSubject = SingleSubject.create();
httpClient.executeRequest(asyncRequest, new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response httpResponse) {
Single.fromCallable(() -> action.parseHttpResponse(httpResponse))
.subscribeWith(responseSubject);
return httpResponse;
}
@Override
public void onThrowable(Throwable throwable) {
responseSubject.onError(throwable);
}
});
return responseSubject;
}
示例2: sendRequest
import org.asynchttpclient.Request; //导入依赖的package包/类
public <T> ListenableFuture<T> sendRequest(final Request request,//
final AsyncHandler<T> asyncHandler,//
NettyResponseFuture<T> future,//
boolean reclaimCache) {
if (isClosed())
throw new IllegalStateException("Closed");
validateWebSocketRequest(request, asyncHandler);
ProxyServer proxyServer = getProxyServer(config, request);
// websockets use connect tunnelling to work with proxies
if (proxyServer != null && (request.getUri().isSecured() || request.getUri().isWebSocket()) && !isConnectDone(request, future))
if (future != null && future.isConnectAllowed())
// SSL proxy or websocket: CONNECT for sure
return sendRequestWithCertainForceConnect(request, asyncHandler, future, reclaimCache, proxyServer, true);
else
// CONNECT will depend if we can pool or connection or if we have to open a new one
return sendRequestThroughSslProxy(request, asyncHandler, future, reclaimCache, proxyServer);
else
// no CONNECT for sure
return sendRequestWithCertainForceConnect(request, asyncHandler, future, reclaimCache, proxyServer, false);
}
示例3: sendRequestWithCertainForceConnect
import org.asynchttpclient.Request; //导入依赖的package包/类
/**
* We know for sure if we have to force to connect or not, so we can build the HttpRequest right away This reduces the probability of having a pooled channel closed by the
* server by the time we build the request
*/
private <T> ListenableFuture<T> sendRequestWithCertainForceConnect(//
Request request,//
AsyncHandler<T> asyncHandler,//
NettyResponseFuture<T> future,//
boolean reclaimCache,//
ProxyServer proxyServer,//
boolean forceConnect) {
NettyResponseFuture<T> newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, proxyServer, forceConnect);
Channel channel = getOpenChannel(future, request, proxyServer, asyncHandler);
if (Channels.isChannelValid(channel))
return sendRequestWithOpenChannel(request, proxyServer, newFuture, asyncHandler, channel);
else
return sendRequestWithNewChannel(request, proxyServer, newFuture, asyncHandler, reclaimCache);
}
示例4: sendRequestWithOpenChannel
import org.asynchttpclient.Request; //导入依赖的package包/类
private <T> ListenableFuture<T> sendRequestWithOpenChannel(Request request, ProxyServer proxy, NettyResponseFuture<T> future, AsyncHandler<T> asyncHandler, Channel channel) {
if (asyncHandler instanceof AsyncHandlerExtensions)
AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionPooled(channel);
scheduleRequestTimeout(future);
future.setChannelState(ChannelState.POOLED);
future.attachChannel(channel, false);
LOGGER.debug("Using open Channel {} for {} '{}'", channel, future.getNettyRequest().getHttpRequest().getMethod(), future.getNettyRequest().getHttpRequest().getUri());
if (Channels.isChannelValid(channel)) {
Channels.setAttribute(channel, future);
writeRequest(future, channel);
} else {
// bad luck, the channel was closed in-between
// there's a very good chance onClose was already notified but the
// future wasn't already registered
handleUnexpectedClosedChannel(channel, future);
}
return future;
}
示例5: exitAfterHandlingConnect
import org.asynchttpclient.Request; //导入依赖的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;
}
示例6: propagatedHeaders
import org.asynchttpclient.Request; //导入依赖的package包/类
private HttpHeaders propagatedHeaders(Request request, Realm realm, boolean keepBody) {
HttpHeaders headers = request.getHeaders()//
.remove(HttpHeaders.Names.HOST)//
.remove(HttpHeaders.Names.CONTENT_LENGTH);
if (!keepBody) {
headers.remove(HttpHeaders.Names.CONTENT_TYPE);
}
if (realm != null && realm.getScheme() == AuthScheme.NTLM) {
headers.remove(AUTHORIZATION)//
.remove(PROXY_AUTHORIZATION);
}
return headers;
}
示例7: adjustRequestRange
import org.asynchttpclient.Request; //导入依赖的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();
}
示例8: perConnectionProxyAuthorizationHeader
import org.asynchttpclient.Request; //导入依赖的package包/类
public static String perConnectionProxyAuthorizationHeader(Request request, Realm proxyRealm) {
String proxyAuthorization = null;
if (proxyRealm != null && proxyRealm.isUsePreemptiveAuth()) {
switch (proxyRealm.getScheme()) {
case NTLM:
case KERBEROS:
case SPNEGO:
List<String> auth = request.getHeaders().getAll(PROXY_AUTHORIZATION);
if (getHeaderWithPrefix(auth, "NTLM") == null) {
String msg = NtlmEngine.INSTANCE.generateType1Msg();
proxyAuthorization = "NTLM " + msg;
}
break;
default:
}
}
return proxyAuthorization;
}
示例9: testNonProxyHost
import org.asynchttpclient.Request; //导入依赖的package包/类
@Test(groups = "standalone")
public void testNonProxyHost() {
// // should avoid, it's in non-proxy hosts
Request req = get("http://somewhere.com/foo").build();
ProxyServer proxyServer = proxyServer("foo", 1234).setNonProxyHost("somewhere.com").build();
assertTrue(proxyServer.isIgnoredForHost(req.getUri().getHost()));
//
// // should avoid, it's in non-proxy hosts (with "*")
req = get("http://sub.somewhere.com/foo").build();
proxyServer = proxyServer("foo", 1234).setNonProxyHost("*.somewhere.com").build();
assertTrue(proxyServer.isIgnoredForHost(req.getUri().getHost()));
// should use it
req = get("http://sub.somewhere.com/foo").build();
proxyServer = proxyServer("foo", 1234).setNonProxyHost("*.somewhere.com").build();
assertTrue(proxyServer.isIgnoredForHost(req.getUri().getHost()));
}
示例10: testAdjustRange
import org.asynchttpclient.Request; //导入依赖的package包/类
@Test
public void testAdjustRange() {
MapResumableProcessor proc = new MapResumableProcessor();
ResumableAsyncHandler handler = new ResumableAsyncHandler(proc);
Request request = get("http://test/url").build();
Request newRequest = handler.adjustRequestRange(request);
assertEquals(newRequest.getUri(), request.getUri());
String rangeHeader = newRequest.getHeaders().get(HttpHeaders.Names.RANGE);
assertNull(rangeHeader);
proc.put("http://test/url", 5000);
newRequest = handler.adjustRequestRange(request);
assertEquals(newRequest.getUri(), request.getUri());
rangeHeader = newRequest.getHeaders().get(HttpHeaders.Names.RANGE);
assertEquals(rangeHeader, "bytes=5000-");
}
示例11: propFindWebDavTest
import org.asynchttpclient.Request; //导入依赖的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>"));
}
}
示例12: replayResponseFilterTest
import org.asynchttpclient.Request; //导入依赖的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");
}
}
示例13: replayStatusCodeResponseFilterTest
import org.asynchttpclient.Request; //导入依赖的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");
}
}
示例14: replayHeaderResponseFilterTest
import org.asynchttpclient.Request; //导入依赖的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");
}
}
示例15: recordCookie
import org.asynchttpclient.Request; //导入依赖的package包/类
protected void recordCookie(Request httpRequest, SpanEventRecorder recorder) {
if (cookieSampler.isSampling()) {
List<Cookie> cookies = httpRequest.getCookies();
if (cookies.isEmpty()) {
return;
}
StringBuilder sb = new StringBuilder(config.getCookieDumpSize() * 2);
Iterator<Cookie> iterator = cookies.iterator();
while (iterator.hasNext()) {
Cookie cookie = iterator.next();
sb.append(cookie.getName()).append('=').append(cookie.getValue());
if (iterator.hasNext()) {
sb.append(',');
}
}
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.abbreviate(sb.toString(), config.getCookieDumpSize()));
}
}