本文整理了Java中io.airlift.http.client.Request
类的一些代码示例,展示了Request
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request
类的具体详情如下:
包路径:io.airlift.http.client.Request
类名称:Request
暂无
代码示例来源:origin: prestodb/presto
@Override
public Response handle(Request request)
ImmutableList<String> parts = ImmutableList.copyOf(Splitter.on("/").omitEmptyStrings().split(request.getUri().getPath()));
if (request.getMethod().equals("DELETE")) {
assertEquals(parts.size(), 1);
return new TestingResponse(HttpStatus.OK, ImmutableListMultimap.of(), new byte[0]);
代码示例来源:origin: prestodb/presto
@Override
public Response handle(Request request)
if (request.getMethod().equalsIgnoreCase("DELETE")) {
return new TestingResponse(HttpStatus.NO_CONTENT, ImmutableListMultimap.of(), new byte[0]);
assertTrue(!request.getHeaders().get(PrestoHeaders.PRESTO_MAX_SIZE).isEmpty());
DataSize maxSize = DataSize.valueOf(request.getHeader(PrestoHeaders.PRESTO_MAX_SIZE));
assertEquals(maxSize, expectedMaxSize);
RequestLocation requestLocation = new RequestLocation(request.getUri());
URI location = requestLocation.getLocation();
代码示例来源:origin: prestodb/presto
private static <T> T handleProxyException(Request request, ProxyException e)
{
log.warn(e, "Proxy request failed: %s %s", request.getMethod(), request.getUri());
throw badRequest(BAD_GATEWAY, e.getMessage());
}
代码示例来源:origin: io.airlift/http-client
@Test
public void testRequestBuilder()
{
Request request = createRequest();
assertEquals(request.getMethod(), "GET");
assertEquals(request.getBodyGenerator(), NULL_BODY_GENERATOR);
assertEquals(request.getUri(), URI.create("http://example.com"));
assertEquals(request.getHeaders(), ImmutableListMultimap.of(
"newheader", "withvalue", "anotherheader", "anothervalue"));
assertFalse(request.isFollowRedirects());
}
代码示例来源:origin: io.airlift/http-client
@Test
public void testBasic()
{
TraceTokenManager manager = new TraceTokenManager();
manager.registerRequestToken("testBasic");
TraceTokenRequestFilter filter = new TraceTokenRequestFilter(manager);
Request original = prepareGet().setUri(URI.create("http://example.com")).build();
Request filtered = filter.filterRequest(original);
assertNotSame(filter, original);
assertEquals(filtered.getUri(), original.getUri());
assertEquals(original.getHeaders().size(), 0);
assertEquals(filtered.getHeaders().size(), 1);
assertEquals(filtered.getHeaders().get(TRACETOKEN_HEADER), ImmutableList.of("testBasic"));
}
代码示例来源:origin: io.airlift/http-client
@Test
public void testFollowRedirects()
throws Exception
{
Request request = prepareGet()
.setUri(URI.create(baseURI.toASCIIString() + "/test?redirect=/redirect"))
.build();
StatusResponse response = executeRequest(request, createStatusResponseHandler());
assertEquals(response.getStatusCode(), 200);
assertNull(response.getHeader(LOCATION));
assertEquals(servlet.getRequestUri(), URI.create(baseURI.toASCIIString() + "/redirect"));
request = Request.Builder.fromRequest(request)
.setFollowRedirects(false)
.build();
response = executeRequest(request, createStatusResponseHandler());
assertEquals(response.getStatusCode(), 302);
assertEquals(response.getHeader(LOCATION), baseURI.toASCIIString() + "/redirect");
assertEquals(servlet.getRequestUri(), request.getUri());
}
代码示例来源:origin: io.airlift/http-client-experimental
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Cannot make requests to HTTP port 0")
public void testCannotMakeRequestToIllegalPort()
throws Exception
{
new Request(URI.create("http://example.com:0/"), "GET", createHeaders1(), createBodyGenerator());
}
代码示例来源:origin: io.airlift/http-client
@Test
public void testBasicAuthentication()
throws Exception
{
Predicate<Request> predicate = request -> request.getUri().getPath().startsWith("/private");
HttpRequestFilter filter = new BasicAuthRequestFilter(predicate, "Aladdin", "open sesame");
Request publicResourceRequest = createTestRequest("/public");
assertNull(filter.filterRequest(publicResourceRequest).getHeader(AUTHORIZATION));
Request privateResourceRequest = createTestRequest("/private");
assertEquals(filter.filterRequest(privateResourceRequest).getHeader(AUTHORIZATION), "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
}
代码示例来源:origin: prestodb/presto
throw new PageTransportErrorException(format("Error fetching %s: %s", request.getUri().toASCIIString(), e.getMessage()), e);
代码示例来源:origin: com.teradata.airlift/http-client
@Test
public void testEquivalence()
new Request(createUri1(), "GET", createHeaders1(), null),
new Request(createUri1(), "GET", createHeaders1(), null))
.addEquivalentGroup(
new Request(createUri1(), "GET", createHeaders1(), bodyGenerator),
new Request(createUri1(), "GET", createHeaders1(), bodyGenerator))
.addEquivalentGroup(
new Request(createUri1(), "GET", createHeaders2(), bodyGenerator))
.addEquivalentGroup(
new Request(createUri2(), "GET", createHeaders1(), bodyGenerator))
.addEquivalentGroup(
new Request(createUri1(), "PUT", createHeaders1(), null),
new Request(createUri1(), "PUT", createHeaders1(), null))
.addEquivalentGroup(
new Request(createUri2(), "PUT", createHeaders1(), null))
.addEquivalentGroup(
new Request(createUri1(), "PUT", createHeaders2(), null))
.addEquivalentGroup(
new Request(createUri1(), "PUT", createHeaders1(), bodyGenerator),
new Request(createUri1(), "PUT", createHeaders1(), bodyGenerator))
.addEquivalentGroup(
new Request(createUri1(), "GET", createHeaders1(), createBodyGenerator()))
.addEquivalentGroup(
new Request(createUri1(), "PUT", createHeaders1(), createBodyGenerator()))
.check();
代码示例来源:origin: prestodb/presto
@Override
public void onFailure(Throwable t)
{
if (t instanceof RejectedExecutionException && httpClient.isClosed()) {
logError(t, "Unable to %s task at %s. HTTP client is closed.", action, request.getUri());
cleanUpLocally();
return;
}
// record failure
if (cleanupBackoff.failure()) {
logError(t, "Unable to %s task at %s. Back off depleted.", action, request.getUri());
cleanUpLocally();
return;
}
// reschedule
long delayNanos = cleanupBackoff.getBackoffDelayNanos();
if (delayNanos == 0) {
doScheduleAsyncCleanupRequest(cleanupBackoff, request, action);
}
else {
errorScheduledExecutor.schedule(() -> doScheduleAsyncCleanupRequest(cleanupBackoff, request, action), delayNanos, NANOSECONDS);
}
}
代码示例来源:origin: airlift/airlift
public static Builder fromRequest(Request request)
{
return new Builder()
.setUri(request.getUri())
.setMethod(request.getMethod())
.addHeaders(request.getHeaders())
.setBodyGenerator(request.getBodyGenerator())
.setFollowRedirects(request.isFollowRedirects())
.setPreserveAuthorizationOnRedirect(request.isPreserveAuthorizationOnRedirect());
}
代码示例来源:origin: airlift/airlift
for (Map.Entry<String, String> entry : request.getHeaders().entries()) {
requestHeaders.add(entry.getKey(), entry.getValue());
Invocation.Builder invocationBuilder = client.target(request.getUri()).request().headers(requestHeaders);
Invocation invocation;
if (request.getBodyGenerator() == null) {
invocation = invocationBuilder.build(request.getMethod());
request.getBodyGenerator().write(byteArrayOutputStream);
byteArrayOutputStream.close();
byte[] bytes = byteArrayOutputStream.toByteArray();
Entity<byte[]> entity = Entity.entity(bytes, (String) getOnlyElement(requestHeaders.get("Content-Type")));
invocation = invocationBuilder.build(request.getMethod(), entity);
log.warn(exception.getCause(), "%-8s %s -> Exception", request.getMethod(), request.getUri());
log.warn(throwable, "%-8s %s -> Fail", request.getMethod(), request.getUri());
log.warn("%-8s %s -> OK", request.getMethod(), request.getUri());
代码示例来源:origin: airlift/airlift
stats.recordResponseReceived(request.getMethod(),
0,
0,
stats.recordResponseReceived(request.getMethod(),
0,
0,
stats.recordResponseReceived(request.getMethod(),
response.getStatusCode(),
response.getBytesRead(),
代码示例来源:origin: airlift/airlift
public Request build()
{
return new Request(
uri,
method,
headers,
bodyGenerator,
followRedirects,
preserveAuthorizationOnRedirect);
}
}
代码示例来源:origin: airlift/airlift
@Test
public void testRequestBuilder()
{
Request request = createRequest();
assertEquals(request.getMethod(), "GET");
assertEquals(request.getBodyGenerator(), NULL_BODY_GENERATOR);
assertEquals(request.getUri(), URI.create("http://example.com"));
assertEquals(request.getHeaders(), ImmutableListMultimap.of(
"newheader", "withvalue", "anotherheader", "anothervalue"));
assertFalse(request.isFollowRedirects());
}
代码示例来源:origin: io.airlift/http-client-experimental
@Test
public void testBasic()
{
TraceTokenManager manager = new TraceTokenManager();
manager.registerRequestToken("testBasic");
TraceTokenRequestFilter filter = new TraceTokenRequestFilter(manager);
Request original = prepareGet().setUri(URI.create("http://example.com")).build();
Request filtered = filter.filterRequest(original);
assertNotSame(filter, original);
assertEquals(filtered.getUri(), original.getUri());
assertEquals(original.getHeaders().size(), 0);
assertEquals(filtered.getHeaders().size(), 1);
assertEquals(filtered.getHeaders().get(TRACETOKEN_HEADER), ImmutableList.of("testBasic"));
}
代码示例来源:origin: airlift/airlift
@Test
public void testFollowRedirects()
throws Exception
{
Request request = prepareGet()
.setUri(URI.create(baseURI.toASCIIString() + "/test?redirect=/redirect"))
.build();
StatusResponse response = executeRequest(request, createStatusResponseHandler());
assertEquals(response.getStatusCode(), 200);
assertNull(response.getHeader(LOCATION));
assertEquals(servlet.getRequestUri(), URI.create(baseURI.toASCIIString() + "/redirect"));
request = Request.Builder.fromRequest(request)
.setFollowRedirects(false)
.build();
response = executeRequest(request, createStatusResponseHandler());
assertEquals(response.getStatusCode(), 302);
assertEquals(response.getHeader(LOCATION), baseURI.toASCIIString() + "/redirect");
assertEquals(servlet.getRequestUri(), request.getUri());
}
代码示例来源:origin: com.teradata.airlift/http-client
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Cannot make requests to HTTP port 0")
public void testCannotMakeRequestToIllegalPort()
throws Exception
{
new Request(URI.create("http://example.com:0/"), "GET", createHeaders1(), createBodyGenerator());
}
代码示例来源:origin: airlift/airlift
@Test
public void testBasicAuthentication()
throws Exception
{
Predicate<Request> predicate = request -> request.getUri().getPath().startsWith("/private");
HttpRequestFilter filter = new BasicAuthRequestFilter(predicate, "Aladdin", "open sesame");
Request publicResourceRequest = createTestRequest("/public");
assertNull(filter.filterRequest(publicResourceRequest).getHeader(AUTHORIZATION));
Request privateResourceRequest = createTestRequest("/private");
assertEquals(filter.filterRequest(privateResourceRequest).getHeader(AUTHORIZATION), "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
}
内容来源于网络,如有侵权,请联系作者删除!