use of org.apache.hc.client5.http.classic.methods.HttpGet in project OpenRefine by OpenRefine.
the class HttpClient method getResponse.
public String getResponse(String urlString, Header[] headers, HttpClientResponseHandler<String> responseHandler) throws IOException {
try {
// Use of URL constructor below is purely to get additional error checking to mimic
// previous behavior for the tests.
new URL(urlString).toURI();
} catch (IllegalArgumentException | MalformedURLException | URISyntaxException e) {
return null;
}
HttpGet httpGet = new HttpGet(urlString);
if (headers != null && headers.length > 0) {
httpGet.setHeaders(headers);
}
// FIXME: Redundant? already includes in client builder
httpGet.setConfig(defaultRequestConfig);
return httpClient.execute(httpGet, responseHandler);
}
use of org.apache.hc.client5.http.classic.methods.HttpGet in project metrics by dropwizard.
the class InstrumentedHttpClientsTest method registersExpectedExceptionMetrics.
@Test
public void registersExpectedExceptionMetrics() throws Exception {
HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
final HttpGet get = new HttpGet("http://localhost:" + httpServer.getAddress().getPort() + "/");
final String requestMetricName = "request";
final String exceptionMetricName = "exception";
httpServer.createContext("/", HttpExchange::close);
httpServer.start();
when(metricNameStrategy.getNameFor(any(), any(HttpRequest.class))).thenReturn(requestMetricName);
when(metricNameStrategy.getNameFor(any(), any(Exception.class))).thenReturn(exceptionMetricName);
try {
client.execute(get);
fail();
} catch (NoHttpResponseException expected) {
assertThat(metricRegistry.getMeters()).containsKey("exception");
} finally {
httpServer.stop(0);
}
}
use of org.apache.hc.client5.http.classic.methods.HttpGet in project metrics by dropwizard.
the class InstrumentedHttpClientsTest method registersExpectedMetricsGivenNameStrategy.
@Test
public void registersExpectedMetricsGivenNameStrategy() throws Exception {
final HttpGet get = new HttpGet("http://example.com?q=anything");
final String metricName = "some.made.up.metric.name";
when(metricNameStrategy.getNameFor(any(), any(HttpRequest.class))).thenReturn(metricName);
client.execute(get);
verify(registryListener).onTimerAdded(eq(metricName), any(Timer.class));
}
use of org.apache.hc.client5.http.classic.methods.HttpGet in project weicoder by wdcode.
the class HttpClient method download.
/**
* 下载文件
*
* @param url get提交地址
* @return 返回流
*/
public static byte[] download(String url) {
// 声明HttpGet对象
HttpGet get = null;
try {
LOG.debug("HttpClient get url={}", url);
// 获得HttpGet对象
get = new HttpGet(url);
// 获得HttpResponse 返回字节流
return IOUtil.read(CLIENT.execute(get).getEntity().getContent());
} catch (Exception e) {
LOG.error(e);
} finally {
// 销毁get
if (get != null) {
get.abort();
}
}
return ArrayConstants.BYTES_EMPTY;
}
use of org.apache.hc.client5.http.classic.methods.HttpGet in project weicoder by wdcode.
the class HttpClient5 method download.
@Override
public byte[] download(String url, Map<String, Object> header) {
// 声明HttpGet对象
HttpGet get = null;
try {
Logs.debug("HttpClient5 get url={}", url);
// 获得HttpGet对象
get = new HttpGet(url);
// 获得HttpResponse 返回字节流
return IOUtil.read(CLIENT.execute(get).getEntity().getContent());
} catch (Exception e) {
Logs.error(e);
} finally {
// 销毁get
if (get != null) {
get.abort();
}
}
return C.A.BYTES_EMPTY;
}
Aggregations