use of org.apache.http.client.methods.HttpGet in project hive by apache.
the class TestHS2HttpServer method testConfStrippedFromWebUI.
@Test
public void testConfStrippedFromWebUI() throws Exception {
String pwdValFound = null;
String pwdKeyFound = null;
CloseableHttpClient httpclient = null;
try {
httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("http://localhost:" + webUIPort + "/conf");
CloseableHttpResponse response1 = httpclient.execute(httpGet);
try {
HttpEntity entity1 = response1.getEntity();
BufferedReader br = new BufferedReader(new InputStreamReader(entity1.getContent()));
String line;
while ((line = br.readLine()) != null) {
if (line.contains(metastorePasswd)) {
pwdValFound = line;
}
if (line.contains(ConfVars.METASTOREPWD.varname)) {
pwdKeyFound = line;
}
}
EntityUtils.consume(entity1);
} finally {
response1.close();
}
} finally {
if (httpclient != null) {
httpclient.close();
}
}
assertNotNull(pwdKeyFound);
assertNull(pwdValFound);
}
use of org.apache.http.client.methods.HttpGet in project hive by apache.
the class PTestClient method downloadTestResults.
private void downloadTestResults(String testHandle, String testOutputDir) throws Exception {
HttpGet request = new HttpGet(mLogsEndpoint + testHandle + "/test-results.tar.gz");
FileOutputStream output = null;
try {
HttpResponse httpResponse = mHttpClient.execute(request);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine.getStatusCode() != 200) {
throw new RuntimeException(statusLine.getStatusCode() + " " + statusLine.getReasonPhrase());
}
output = new FileOutputStream(new File(testOutputDir, "test-results.tar.gz"));
IOUtils.copyLarge(httpResponse.getEntity().getContent(), output);
output.flush();
} finally {
request.abort();
if (output != null) {
output.close();
}
}
}
use of org.apache.http.client.methods.HttpGet in project cas by apereo.
the class SimpleHttpClient method sendMessageToEndPoint.
@Override
public HttpMessage sendMessageToEndPoint(final URL url) {
Assert.notNull(this.httpClient);
HttpEntity entity = null;
try (CloseableHttpResponse response = this.httpClient.execute(new HttpGet(url.toURI()))) {
final int responseCode = response.getStatusLine().getStatusCode();
for (final int acceptableCode : this.acceptableCodes) {
if (responseCode == acceptableCode) {
LOGGER.debug("Response code received from server matched [{}].", responseCode);
entity = response.getEntity();
final HttpMessage msg = new HttpMessage(url, IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8));
msg.setContentType(entity.getContentType().getValue());
msg.setResponseCode(responseCode);
return msg;
}
}
LOGGER.warn("Response code [{}] from [{}] did not match any of the acceptable response codes.", responseCode, url);
if (responseCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
final String value = response.getStatusLine().getReasonPhrase();
LOGGER.error("There was an error contacting the endpoint: [{}]; The error:\n[{}]", url.toExternalForm(), value);
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
EntityUtils.consumeQuietly(entity);
}
return null;
}
use of org.apache.http.client.methods.HttpGet in project cas by apereo.
the class SimpleHttpClient method isValidEndPoint.
@Override
public boolean isValidEndPoint(final URL url) {
Assert.notNull(this.httpClient);
HttpEntity entity = null;
try (CloseableHttpResponse response = this.httpClient.execute(new HttpGet(url.toURI()))) {
final int responseCode = response.getStatusLine().getStatusCode();
final int idx = Collections.binarySearch(this.acceptableCodes, responseCode);
if (idx >= 0) {
LOGGER.debug("Response code from server matched [{}].", responseCode);
return true;
}
LOGGER.debug("Response code did not match any of the acceptable response codes. Code returned was [{}]", responseCode);
if (responseCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
final String value = response.getStatusLine().getReasonPhrase();
LOGGER.error("There was an error contacting the endpoint: [{}]; The error was:\n[{}]", url.toExternalForm(), value);
}
entity = response.getEntity();
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
EntityUtils.consumeQuietly(entity);
}
return false;
}
use of org.apache.http.client.methods.HttpGet in project weixin-java-tools by chanjarster.
the class SimpleGetRequestExecutor method execute.
@Override
public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String queryParam) throws WxErrorException, ClientProtocolException, IOException {
if (queryParam != null) {
if (uri.indexOf('?') == -1) {
uri += '?';
}
uri += uri.endsWith("?") ? queryParam : '&' + queryParam;
}
HttpGet httpGet = new HttpGet(uri);
if (httpProxy != null) {
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
httpGet.setConfig(config);
}
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
WxError error = WxError.fromJson(responseContent);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return responseContent;
}
}
Aggregations