use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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();
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project intellij-community by JetBrains.
the class StatisticsHttpClientSender method send.
@Override
public void send(@NotNull String url, @NotNull String content) throws StatServiceException {
try {
HttpConfigurable.getInstance().prepareURL(url);
Response response = Request.Post(url).bodyForm(Form.form().add("content", content).add("uuid", PermanentInstallationID.get()).add("patch", String.valueOf(false)).add("ide", ApplicationNamesInfo.getInstance().getProductName()).build()).execute();
final HttpResponse httpResponse = response.returnResponse();
if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new StatServiceException("Error during data sending... Code: " + httpResponse.getStatusLine().getStatusCode());
}
final Header errors = httpResponse.getFirstHeader("errors");
if (errors != null) {
String value = errors.getValue();
throw new StatServiceException("Error during updating statistics " + (!StringUtil.isEmptyOrSpaces(value) ? " : " + value : ""));
}
} catch (StatServiceException e) {
throw e;
} catch (Exception e) {
throw new StatServiceException("Error during data sending...", e);
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.HttpResponse in project oxAuth by GluuFederation.
the class HttpService method executePost.
public HttpServiceResponse executePost(HttpClient httpClient, String uri, String authData, Map<String, String> headers, String postData, ContentType contentType) {
HttpPost httpPost = new HttpPost(uri);
if (StringHelper.isNotEmpty(authData)) {
httpPost.setHeader("Authorization", "Basic " + authData);
}
if (headers != null) {
for (Entry<String, String> headerEntry : headers.entrySet()) {
httpPost.setHeader(headerEntry.getKey(), headerEntry.getValue());
}
}
StringEntity stringEntity = new StringEntity(postData, contentType);
httpPost.setEntity(stringEntity);
try {
HttpResponse httpResponse = httpClient.execute(httpPost);
return new HttpServiceResponse(httpPost, httpResponse);
} catch (IOException ex) {
log.error("Failed to execute post request", ex);
}
return null;
}
Aggregations