本文整理了Java中io.airlift.http.client.HttpClient.execute()
方法的一些代码示例,展示了HttpClient.execute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.execute()
方法的具体详情如下:
包路径:io.airlift.http.client.HttpClient
类名称:HttpClient
方法名:execute
暂无
代码示例来源: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 long getTotalCpuTime()
{
long totalCpuTime = 0;
for (URI server : nodes) {
URI addressUri = uriBuilderFrom(server).replacePath("/v1/jmx/mbean/java.lang:type=OperatingSystem/ProcessCpuTime").build();
String data = httpClient.execute(prepareGet().setUri(addressUri).build(), createStringResponseHandler()).getBody();
totalCpuTime += parseLong(data.trim());
}
return TimeUnit.NANOSECONDS.toNanos(totalCpuTime);
}
代码示例来源: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
public Response cancel(String queryId)
{
requireNonNull(queryId, "queryId is null");
URI cancelUri = uriBuilderFrom(uri).appendPath("/v1/query").appendPath(queryId).build();
Request request = prepareDelete().setUri(cancelUri).build();
return httpClient.execute(request, new ResponseHandler<Response, RuntimeException>()
{
@Override
public Response handleException(Request request, Exception exception)
{
throw propagate(request, exception);
}
@Override
public Response handle(Request request, Response response)
{
return response;
}
});
}
代码示例来源: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: 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
@Test
public void testGetAllNodes()
{
List<Stats> nodes = client.execute(
prepareGet().setUri(server.resolve("/v1/node")).build(),
createJsonResponseHandler(listJsonCodec(Stats.class)));
// we only have one node and the list never contains the current node
assertTrue(nodes.isEmpty());
}
代码示例来源:origin: prestodb/presto
@Test
public void testGetQueryStateInfosForUserNoResult()
{
List<QueryStateInfo> infos = client.execute(
prepareGet().setUri(server.resolve("/v1/queryState?user=user3")).build(),
createJsonResponseHandler(listJsonCodec(QueryStateInfo.class)));
assertTrue(infos.isEmpty());
}
代码示例来源:origin: prestodb/presto
@Override
public Optional<QueryStats> getQueryStats(String queryId)
{
URI uri = uriBuilderFrom(baseUri).appendPath("/v1/query").appendPath(queryId).build();
Request request = prepareGet().setUri(uri).build();
return httpClient.execute(request, new GetQueryStatsResponseHandler());
}
代码示例来源:origin: prestodb/presto
@Test
public void testGetQueryStateInfosForUser()
{
List<QueryStateInfo> infos = client.execute(
prepareGet().setUri(server.resolve("/v1/queryState?user=user2")).build(),
createJsonResponseHandler(listJsonCodec(QueryStateInfo.class)));
assertEquals(infos.size(), 1);
}
代码示例来源: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 testGetAllQueryStateInfos()
{
List<QueryStateInfo> infos = client.execute(
prepareGet().setUri(server.resolve("/v1/queryState")).build(),
createJsonResponseHandler(listJsonCodec(QueryStateInfo.class)));
assertEquals(infos.size(), 2);
}
代码示例来源:origin: prestodb/presto
@Test(expectedExceptions = {UnexpectedResponseException.class}, expectedExceptionsMessageRegExp = ".*404: Not Found")
public void testGetQueryStateInfoNo()
{
client.execute(
prepareGet().setUri(server.resolve("/v1/queryState/123")).build(),
createJsonResponseHandler(jsonCodec(QueryStateInfo.class)));
}
}
代码示例来源: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
.build();
QueryResults queryResults = client.execute(request, createJsonResponseHandler(QUERY_RESULTS_CODEC));
queryResults = client.execute(prepareGet().setUri(queryResults.getNextUri()).build(), createJsonResponseHandler(QUERY_RESULTS_CODEC));
代码示例来源: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 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: prestodb/presto
private void runToCompletion(String sql)
{
URI uri = uriBuilderFrom(server.getBaseUrl().resolve("/v1/statement")).build();
Request request = preparePost()
.setHeader(PRESTO_USER, "user")
.setUri(uri)
.setBodyGenerator(createStaticBodyGenerator(sql, UTF_8))
.build();
QueryResults queryResults = client.execute(request, createJsonResponseHandler(jsonCodec(QueryResults.class)));
while (queryResults.getNextUri() != null) {
request = prepareGet()
.setHeader(PRESTO_USER, "user")
.setUri(queryResults.getNextUri())
.build();
queryResults = client.execute(request, createJsonResponseHandler(jsonCodec(QueryResults.class)));
}
}
代码示例来源: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
@Test
public void testInvalidSessionError()
{
String invalidTimeZone = "this_is_an_invalid_time_zone";
Request request = preparePost().setHeader(PRESTO_USER, "user")
.setUri(uriFor("/v1/statement"))
.setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8))
.setHeader(PRESTO_SOURCE, "source")
.setHeader(PRESTO_CATALOG, "catalog")
.setHeader(PRESTO_SCHEMA, "schema")
.setHeader(PRESTO_PATH, "path")
.setHeader(PRESTO_TIME_ZONE, invalidTimeZone)
.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));
}
QueryError queryError = queryResults.getError();
assertNotNull(queryError);
TimeZoneNotSupportedException expected = new TimeZoneNotSupportedException(invalidTimeZone);
assertEquals(queryError.getErrorCode(), expected.getErrorCode().getCode());
assertEquals(queryError.getErrorName(), expected.getErrorCode().getName());
assertEquals(queryError.getErrorType(), expected.getErrorCode().getType().name());
assertEquals(queryError.getMessage(), expected.getMessage());
}
内容来源于网络,如有侵权,请联系作者删除!