use of org.apache.http.HttpResponse in project azure-tools-for-java by Microsoft.
the class SparkRestUtil method getEntity.
// @Nullable
// public static List<Application> getApplications(@NotNull ClusterDetail clusterDetail) throws HDIException, IOException {
// HttpEntity entity = getEntity(clusterDetail, "applications");
// String entityType = entity.getContentType().getValue();
// if( entityType.equals("application/json")){
// String json = EntityUtils.toString(entity);
// List<Application> apps = objectMapper.readValue(json, TypeFactory.defaultInstance().constructType(List.class, Application.class));
// return apps;
// }
// return null;
// }
public static HttpEntity getEntity(@NotNull IClusterDetail clusterDetail, @NotNull String restUrl) throws HDIException, IOException {
provider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(clusterDetail.getHttpUserName(), clusterDetail.getHttpPassword()));
HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(provider).build();
String url = String.format(SPARK_REST_API_ENDPOINT, clusterDetail.getName(), restUrl);
HttpGet get = new HttpGet(url);
HttpResponse response = client.execute(get);
int code = response.getStatusLine().getStatusCode();
if (code == HttpStatus.SC_OK || code == HttpStatus.SC_CREATED) {
return response.getEntity();
} else {
throw new HDIException(response.getStatusLine().getReasonPhrase(), response.getStatusLine().getStatusCode());
}
}
use of org.apache.http.HttpResponse in project wildfly by wildfly.
the class WebSecurityExternalAuthTestCase method makeCall.
protected void makeCall(String user, int expectedStatusCode) throws Exception {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpget = new HttpGet(url.toExternalForm() + "secured/");
httpget.addHeader("User", user);
HttpResponse response = httpClient.execute(httpget);
HttpEntity entity = response.getEntity();
StatusLine statusLine = response.getStatusLine();
assertEquals(expectedStatusCode, statusLine.getStatusCode());
EntityUtils.consume(entity);
}
}
use of org.apache.http.HttpResponse in project undertow by undertow-io.
the class SimpleConfidentialRedirectTestCase method sendRequest.
private void sendRequest(TestHttpClient client, String uri) throws IOException {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + uri);
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals("https", result.getFirstHeader("scheme").getValue());
Assert.assertEquals(uri, result.getFirstHeader("uri").getValue());
HttpClientUtils.readResponse(result);
}
use of org.apache.http.HttpResponse in project wechat-mp-sdk by usc.
the class MediaUtil method getMedia.
public static File getMedia(License license, String mediaId, String path) {
if (StringUtils.isEmpty(mediaId) || StringUtils.isEmpty(path)) {
return null;
}
String accessToken = AccessTokenUtil.getAccessToken(license);
String url = WechatRequest.GET_MEDIA.getUrl();
try {
URI uri = new URIBuilder(url).setParameter("access_token", accessToken).setParameter("media_id", mediaId).build();
HttpResponse response = Request.Get(uri).connectTimeout(HttpUtil.CONNECT_TIMEOUT).socketTimeout(HttpUtil.SOCKET_TIMEOUT).execute().returnResponse();
return downloadFile(response, mediaId, path, uri);
} catch (Exception e) {
String msg = "get media failed:\n " + "url=" + url + "?access_token=" + accessToken + "&media_id=" + mediaId;
log.error(msg, e);
return null;
}
}
use of org.apache.http.HttpResponse in project undertow by undertow-io.
the class FormDataParserTestCase method runTest.
private void runTest(final NameValuePair... pairs) throws Exception {
DefaultServer.setRootHandler(rootHandler);
TestHttpClient client = new TestHttpClient();
try {
final List<NameValuePair> data = new ArrayList<>();
data.addAll(Arrays.asList(pairs));
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
post.setHeader(Headers.CONTENT_TYPE_STRING, FormEncodedDataDefinition.APPLICATION_X_WWW_FORM_URLENCODED);
post.setEntity(new UrlEncodedFormEntity(data));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
checkResult(data, result);
HttpClientUtils.readResponse(result);
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations