本文整理了Java中org.apache.druid.java.util.http.client.HttpClient
类的一些代码示例,展示了HttpClient
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient
类的具体详情如下:
包路径:org.apache.druid.java.util.http.client.HttpClient
类名称:HttpClient
[英]Interface for Async HTTP client libraries.
[中]异步HTTP客户端库的接口。
代码示例来源:origin: apache/incubator-druid
/**
* Executes the request object aimed at the leader and process the response with given handler
* Note: this method doesn't do retrying on errors or handle leader changes occurred during communication
*/
public <Intermediate, Final> ListenableFuture<Final> goAsync(
final Request request,
final HttpResponseHandler<Intermediate, Final> handler
)
{
return httpClient.go(request, handler);
}
代码示例来源:origin: apache/incubator-druid
@Override
public <Intermediate, Final> ListenableFuture<Final> go(
Request request,
HttpResponseHandler<Intermediate, Final> handler,
Duration requestReadTimeout
)
{
return delegate.go(creds.addCredentials(request), handler, requestReadTimeout);
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public InputStream openStream() throws IOException
{
try {
return httpClient.go(
new Request(HttpMethod.GET, url),
new InputStreamResponseHandler()
).get();
}
catch (InterruptedException e) {
throw Throwables.propagate(e);
}
catch (ExecutionException e) {
// Unwrap if possible
Throwables.propagateIfPossible(e.getCause(), IOException.class);
throw Throwables.propagate(e);
}
}
}
代码示例来源:origin: apache/incubator-druid
private FullResponseHolder submitRequest(Request request) throws IOException, ChannelException
{
try {
log.debug("HTTP %s: %s", request.getMethod().getName(), request.getUrl().toString());
return httpClient.go(request, new FullResponseHandler(StandardCharsets.UTF_8), httpTimeout).get();
}
catch (Exception e) {
throw throwIfPossible(e);
}
}
代码示例来源:origin: apache/incubator-druid
private StatusResponseHolder makeRequest(HttpMethod method, String url)
{
try {
StatusResponseHolder response = this.httpClient
.go(new Request(method, new URL(url)), responseHandler).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while making request to indexer [%s %s]", response.getStatus(), response.getContent());
}
return response;
}
catch (Exception e) {
LOG.error(e, "Exception while sending request");
throw Throwables.propagate(e);
}
}
代码示例来源:origin: apache/incubator-druid
private StatusResponseHolder makeRequest(HttpMethod method, String url)
{
try {
StatusResponseHolder response = httpClient.go(
new Request(method, new URL(url)),
responseHandler
).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE(
"Error while making request to url[%s] status[%s] content[%s]",
url,
response.getStatus(),
response.getContent()
);
}
return response;
}
catch (Exception e) {
throw Throwables.propagate(e);
}
}
}
代码示例来源:origin: apache/incubator-druid
public List<Map<String, Object>> query(String url, QueryType query)
{
try {
StatusResponseHolder response = httpClient.go(
new Request(HttpMethod.POST, new URL(url)).setContent(
"application/json",
jsonMapper.writeValueAsBytes(query)
), responseHandler
).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE(
"Error while querying[%s] status[%s] content[%s]",
getBrokerURL(),
response.getStatus(),
response.getContent()
);
}
return jsonMapper.readValue(
response.getContent(), new TypeReference<List<Map<String, Object>>>()
{
}
);
}
catch (Exception e) {
throw Throwables.propagate(e);
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public void run()
{
try {
ListenableFuture<InputStream> go = client.go(
new Request(HttpMethod.GET, new URL("http://localhost:" + port + "/exception/exception")),
new InputStreamResponseHandler()
);
StringWriter writer = new StringWriter();
IOUtils.copy(go.get(), writer, "utf-8");
}
catch (IOException e) {
// Expected.
}
catch (Throwable t) {
Throwables.propagate(t);
}
latch.countDown();
}
}
代码示例来源:origin: apache/incubator-druid
try (final InputStream result = httpClient.go(
new Request(HttpMethod.GET, url)
.addHeader(HttpHeaders.Names.ACCEPT, SmileMediaTypes.APPLICATION_JACKSON_SMILE),
代码示例来源:origin: apache/incubator-druid
StatusResponseHolder response = httpClient.go(
new Request(HttpMethod.POST, new URL(getURL()))
.setContent(mediaType, objectMapper.writeValueAsBytes(events)),
代码示例来源:origin: apache/incubator-druid
public void shutdownSupervisor(String id)
{
try {
StatusResponseHolder response = httpClient.go(
new Request(HttpMethod.POST, new URL(StringUtils.format("%ssupervisor/%s/shutdown", getIndexerURL(), StringUtils.urlEncode(id)))),
responseHandler
).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE(
"Error while shutting down supervisor, response [%s %s]",
response.getStatus(),
response.getContent()
);
}
LOG.info("Shutdown supervisor with id[%s]", id);
}
catch (Exception e) {
throw Throwables.propagate(e);
}
}
代码示例来源:origin: apache/incubator-druid
public String submitSupervisor(String spec)
{
try {
StatusResponseHolder response = httpClient.go(
new Request(HttpMethod.POST, new URL(getIndexerURL() + "supervisor"))
.setContent(
"application/json",
StringUtils.toUtf8(spec)
),
responseHandler
).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE(
"Error while submitting supervisor to overlord, response [%s %s]",
response.getStatus(),
response.getContent()
);
}
Map<String, String> responseData = jsonMapper.readValue(
response.getContent(), JacksonUtils.TYPE_REFERENCE_MAP_STRING_STRING
);
String id = responseData.get("id");
LOG.info("Submitted supervisor with id[%s]", id);
return id;
}
catch (Exception e) {
throw Throwables.propagate(e);
}
}
代码示例来源:origin: apache/incubator-druid
return RetryUtils.retry(
() -> {
StatusResponseHolder response = httpClient.go(
new Request(HttpMethod.POST, new URL(getIndexerURL() + "task"))
.setContent(
代码示例来源:origin: apache/incubator-druid
private List<ListenableFuture<StatusResponseHolder>> sendUpdate(String updatedAuthorizerPrefix, byte[] serializedUserMap)
{
List<ListenableFuture<StatusResponseHolder>> futures = new ArrayList<>();
for (NodeType nodeType : NODE_TYPES) {
DruidNodeDiscovery nodeDiscovery = discoveryProvider.getForNodeType(nodeType);
Collection<DiscoveryDruidNode> nodes = nodeDiscovery.getAllNodes();
for (DiscoveryDruidNode node : nodes) {
URL listenerURL = getListenerURL(node.getDruidNode(), baseUrl, updatedAuthorizerPrefix);
// best effort, if this fails, remote node will poll and pick up the update eventually
Request req = new Request(HttpMethod.POST, listenerURL);
req.setContent(MediaType.APPLICATION_JSON, serializedUserMap);
BasicAuthDBConfig itemConfig = itemConfigMap.get(updatedAuthorizerPrefix);
ListenableFuture<StatusResponseHolder> future = httpClient.go(
req,
new ResponseHandler(),
Duration.millis(itemConfig.getCacheNotificationTimeout())
);
futures.add(future);
}
}
return futures;
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testGzipRequestDecompression() throws Exception
{
String text = "hello";
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(out)) {
gzipOutputStream.write(text.getBytes(Charset.defaultCharset()));
}
Request request = new Request(HttpMethod.POST, new URL("http://localhost:" + port + "/return"));
request.setHeader("Content-Encoding", "gzip");
request.setContent(MediaType.TEXT_PLAIN, out.toByteArray());
Assert.assertEquals(text, new String(IOUtils.toByteArray(client.go(
request,
new InputStreamResponseHandler()
).get()), Charset.defaultCharset()));
}
}
代码示例来源:origin: apache/incubator-druid
public List<String> getDimensions(String dataSource, String interval)
StatusResponseHolder response = httpClient.go(
new Request(
HttpMethod.GET,
代码示例来源:origin: apache/incubator-druid
public void waitUntilInstanceReady(final HttpClient client, final String host)
{
final StatusResponseHandler handler = new StatusResponseHandler(StandardCharsets.UTF_8);
RetryUtil.retryUntilTrue(
() -> {
try {
StatusResponseHolder response = client.go(
new Request(HttpMethod.GET, new URL(StringUtils.format("%s/status/health", host))),
handler
).get();
LOG.info("%s %s", response.getStatus(), response.getContent());
return response.getStatus().equals(HttpResponseStatus.OK);
}
catch (Throwable e) {
LOG.error(e, "");
return false;
}
},
"Waiting for instance to be ready: [" + host + "]"
);
}
}
代码示例来源:origin: apache/incubator-druid
StatusResponseHolder res = httpClient.go(
new Request(
HttpMethod.DELETE,
代码示例来源:origin: apache/incubator-druid
@Test
@Ignore
// above bug is not fixed in jetty for gzip encoding, and the chunk is still finalized instead of throwing exception.
public void testChunkNotFinalized() throws Exception
{
ListenableFuture<InputStream> go =
client.go(
new Request(HttpMethod.GET, new URL("http://localhost:" + port + "/exception/exception")),
new InputStreamResponseHandler()
);
try {
StringWriter writer = new StringWriter();
IOUtils.copy(go.get(), writer, "utf-8");
Assert.fail("Should have thrown Exception");
}
catch (IOException e) {
// Expected.
}
}
代码示例来源:origin: apache/incubator-druid
EasyMock.expect(client.go(
EasyMock.anyObject(),
EasyMock.<SequenceInputStreamResponseHandler>anyObject(),
内容来源于网络,如有侵权,请联系作者删除!