本文整理了Java中io.airlift.http.client.HttpClient
类的一些代码示例,展示了HttpClient
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient
类的具体详情如下:
包路径:io.airlift.http.client.HttpClient
类名称:HttpClient
暂无
代码示例来源:origin: prestodb/presto
@Test
public void testServerStarts()
{
StatusResponseHandler.StatusResponse response = client.execute(
prepareGet().setUri(server.resolve("/v1/query")).build(),
createStatusResponseHandler());
assertEquals(response.getStatusCode(), OK.getStatusCode());
}
代码示例来源:origin: prestodb/presto
private synchronized void sendDelete()
HttpResponseFuture<StatusResponse> resultFuture = httpClient.executeAsync(prepareDelete().setUri(location).build(), createStatusResponseHandler());
future = resultFuture;
Futures.addCallback(resultFuture, new FutureCallback<StatusResponse>()
代码示例来源:origin: prestodb/presto
@Override
public void close()
{
httpClient.close();
}
}
代码示例来源:origin: prestodb/presto
@Test
public void testGetFailedNodes()
{
List<Stats> nodes = client.execute(
prepareGet().setUri(server.resolve("/v1/node/failed")).build(),
createJsonResponseHandler(listJsonCodec(Stats.class)));
assertTrue(nodes.isEmpty());
}
}
代码示例来源:origin: airlift/airlift
@Test
public void testDeleteViaQueryParam()
throws Exception
{
client.execute(buildRequestWithQueryParam(POST, DELETE), createStatusResponseHandler());
assertFalse(resource.postCalled(), "POST");
assertTrue(resource.deleteCalled(), "DELETE");
assertFalse(resource.putCalled(), "PUT");
assertFalse(resource.getCalled(), "GET");
}
代码示例来源:origin: prestodb/presto
@Test
public void testGetQueryStateInfo()
{
QueryStateInfo info = client.execute(
prepareGet().setUri(server.resolve("/v1/queryState/" + queryResults.getId())).build(),
createJsonResponseHandler(jsonCodec(QueryStateInfo.class)));
assertNotNull(info);
}
代码示例来源:origin: prestodb/presto
@Test
public void testNoTransactionSupport()
{
Request request = preparePost()
.setUri(uriFor("/v1/statement"))
.setBodyGenerator(createStaticBodyGenerator("start transaction", UTF_8))
.setHeader(PRESTO_USER, "user")
.setHeader(PRESTO_SOURCE, "source")
.build();
QueryResults queryResults = client.execute(request, createJsonResponseHandler(QUERY_RESULTS_CODEC));
while (queryResults.getNextUri() != null) {
queryResults = client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_CODEC));
}
assertNotNull(queryResults.getError());
assertEquals(queryResults.getError().getErrorCode(), INCOMPATIBLE_CLIENT.toErrorCode().getCode());
}
代码示例来源:origin: prestodb/presto
@Test
public void testQuery()
Request request = preparePost()
.setUri(uriFor("/v1/statement"))
.setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8))
.setHeader(PRESTO_USER, "user")
.setHeader(PRESTO_SOURCE, "source")
.build();
QueryResults queryResults = client.execute(request, createJsonResponseHandler(QUERY_RESULTS_CODEC));
queryResults = client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_CODEC));
assertNull(queryResults.getError());
assertEquals(queryInfo.getSession().getSystemProperties(), ImmutableMap.builder()
.put(QUERY_MAX_MEMORY, "1GB")
.put(JOIN_DISTRIBUTION_TYPE, "partitioned")
assertEquals(queryInfo.getSession().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
代码示例来源:origin: prestodb/presto
@Test
public void testTransactionSupport()
{
Request request = preparePost()
.setUri(uriFor("/v1/statement"))
.setBodyGenerator(createStaticBodyGenerator("start transaction", UTF_8))
.setHeader(PRESTO_USER, "user")
.setHeader(PRESTO_SOURCE, "source")
.setHeader(PRESTO_TRANSACTION_ID, "none")
.build();
JsonResponse<QueryResults> queryResults = client.execute(request, createFullJsonResponseHandler(QUERY_RESULTS_CODEC));
ImmutableList.Builder<List<Object>> data = ImmutableList.builder();
while (true) {
if (queryResults.getValue().getData() != null) {
data.addAll(queryResults.getValue().getData());
}
if (queryResults.getValue().getNextUri() == null) {
break;
}
queryResults = client.execute(prepareGet().setUri(queryResults.getValue().getNextUri()).build(), createFullJsonResponseHandler(QUERY_RESULTS_CODEC));
}
assertNull(queryResults.getValue().getError());
assertNotNull(queryResults.getHeader(PRESTO_STARTED_TRANSACTION_ID));
}
代码示例来源:origin: com.teradata.airlift/http-server
@Test(timeOut = 60000)
public void testStop()
throws Exception
{
createAndStartServer();
try (HttpClient client = new JettyHttpClient()) {
URI uri = URI.create(httpServerInfo.getHttpUri().toASCIIString() + "/?sleep=50000");
Request request = prepareGet().setUri(uri).build();
HttpResponseFuture<?> future = client.executeAsync(request, createStatusResponseHandler());
server.stop();
try {
future.get(1, TimeUnit.SECONDS);
fail("expected exception");
}
catch (ExecutionException e) {
assertInstanceOf(e.getCause(), RuntimeIOException.class);
}
}
}
代码示例来源:origin: airlift/airlift
@Test
public void testGetSingle()
throws IOException, ExecutionException, InterruptedException
{
store.put("foo", new Person("foo@example.com", "Mr Foo"));
URI requestUri = uriFor("/v1/person/foo");
Map<String, Object> expected = mapCodec.fromJson(Resources.toString(Resources.getResource("single.json"), UTF_8));
expected.put("self", requestUri.toString());
Map<String, Object> actual = client.execute(
prepareGet().setUri(requestUri).build(),
createJsonResponseHandler(mapCodec));
assertEquals(actual, expected);
}
代码示例来源:origin: io.airlift/rack-experimental
@Test
public void testBasicGet()
throws Throwable
{
Map<String, Object> response = client.execute(
prepareGet().setUri(server.getBaseUrl().resolve("/foo")).build(),
createJsonResponseHandler(mapJsonCodec(String.class, Object.class)));
assertEquals(response.get("REQUEST_METHOD"), "GET");
assertEquals(response.get("SCRIPT_NAME"), "");
assertEquals(response.get("PATH_INFO"), "/foo");
assertEquals(response.get("QUERY_STRING"), "");
}
代码示例来源:origin: airlift/airlift
private void assertNonOverridableMethod(Request request)
throws IOException, ExecutionException, InterruptedException
{
StatusResponse response = client.execute(request, createStatusResponseHandler());
assertEquals(response.getStatusCode(), Status.BAD_REQUEST.getStatusCode());
assertFalse(resource.postCalled(), "POST");
assertFalse(resource.deleteCalled(), "DELETE");
assertFalse(resource.putCalled(), "PUT");
assertFalse(resource.getCalled(), "GET");
}
代码示例来源:origin: prestodb/presto
private List<URI> getAllNodes(URI server)
{
Request request = prepareGet().setUri(uriBuilderFrom(server).replacePath("/v1/service/presto").build()).build();
JsonResponseHandler<ServiceDescriptorsRepresentation> responseHandler = createJsonResponseHandler(jsonCodec(ServiceDescriptorsRepresentation.class));
ServiceDescriptorsRepresentation serviceDescriptors = httpClient.execute(request, responseHandler);
ImmutableList.Builder<URI> addresses = ImmutableList.builder();
for (ServiceDescriptor serviceDescriptor : serviceDescriptors.getServiceDescriptors()) {
String httpUri = serviceDescriptor.getProperties().get("http");
if (httpUri != null) {
addresses.add(URI.create(httpUri));
}
}
return addresses.build();
}
}
代码示例来源:origin: prestodb/presto
@BeforeClass
public void setup()
{
Request request1 = preparePost()
.setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build())
.setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8))
.setHeader(PRESTO_USER, "user1")
.build();
queryResults = client.execute(request1, createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
Request request2 = preparePost()
.setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/statement").build())
.setBodyGenerator(createStaticBodyGenerator(LONG_LASTING_QUERY, UTF_8))
.setHeader(PRESTO_USER, "user2")
.build();
QueryResults queryResults2 = client.execute(request2, createJsonResponseHandler(jsonCodec(QueryResults.class)));
client.execute(prepareGet().setUri(queryResults2.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_JSON_CODEC));
// queries are started in the background, so they may not all be immediately visible
while (true) {
List<BasicQueryInfo> queryInfos = client.execute(
prepareGet().setUri(uriBuilderFrom(server.getBaseUrl()).replacePath("/v1/query").build()).build(),
createJsonResponseHandler(listJsonCodec(BasicQueryInfo.class)));
if ((queryInfos.size() == 2) && queryInfos.stream().allMatch(info -> info.getState() == RUNNING)) {
break;
}
}
}
代码示例来源:origin: prestodb/presto
private List<BasicQueryInfo> getQueryInfos(String path)
{
Request request = prepareGet().setUri(server.resolve(path)).build();
return client.execute(request, createJsonResponseHandler(listJsonCodec(BasicQueryInfo.class)));
}
代码示例来源:origin: prestodb/presto
private Response proxyJsonResponse(String nodeId, String workerPath)
{
Set<Node> nodes = nodeManager.getNodes(NodeState.ACTIVE);
Node node = nodes.stream()
.filter(n -> n.getNodeIdentifier().equals(nodeId))
.findFirst()
.orElseThrow(() -> new WebApplicationException(NOT_FOUND));
Request request = prepareGet()
.setUri(uriBuilderFrom(node.getHttpUri())
.appendPath(workerPath)
.build())
.build();
InputStream responseStream = httpClient.execute(request, new StreamingJsonResponseHandler());
return Response.ok(responseStream, APPLICATION_JSON_TYPE).build();
}
代码示例来源:origin: prestodb/presto
private FluentFuture<ProxyResponse> executeHttp(Request request)
{
return FluentFuture.from(httpClient.executeAsync(request, new ProxyResponseHandler()));
}
代码示例来源:origin: prestodb/presto
outputBuffers.get(),
totalPartitions);
byte[] taskUpdateRequestJson = taskUpdateRequestCodec.toJsonBytes(updateRequest);
if (fragment.isPresent()) {
stats.updateWithPlanBytes(taskUpdateRequestJson.length);
Request request = preparePost()
.setUri(uriBuilder.build())
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString())
.setBodyGenerator(createStaticBodyGenerator(taskUpdateRequestJson))
.build();
ListenableFuture<JsonResponse<TaskInfo>> future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskInfoCodec));
currentRequest = future;
currentRequestStartNanos = System.nanoTime();
代码示例来源:origin: com.teradata.airlift/event
@Flatten
@Managed
public RequestStats getStats()
{
return httpClient.getStats();
}
内容来源于网络,如有侵权,请联系作者删除!