Search in sources :

Example 96 with HttpResponse

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);
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse)

Example 97 with HttpResponse

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;
    }
}
Also used : HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 98 with HttpResponse

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();
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpPost(org.apache.http.client.methods.HttpPost) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) TestHttpClient(io.undertow.testutils.TestHttpClient)

Example 99 with HttpResponse

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);
    }
}
Also used : HttpResponse(org.apache.http.HttpResponse) Response(org.apache.http.client.fluent.Response) Header(org.apache.http.Header) HttpResponse(org.apache.http.HttpResponse)

Example 100 with HttpResponse

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse) HttpServiceResponse(org.xdi.oxauth.model.net.HttpServiceResponse) IOException(java.io.IOException)

Aggregations

HttpResponse (org.apache.http.HttpResponse)4366 Test (org.junit.Test)2158 HttpGet (org.apache.http.client.methods.HttpGet)1833 IOException (java.io.IOException)1110 URI (java.net.URI)834 HttpPost (org.apache.http.client.methods.HttpPost)759 HttpClient (org.apache.http.client.HttpClient)600 HttpEntity (org.apache.http.HttpEntity)541 TestHttpClient (io.undertow.testutils.TestHttpClient)403 InputStream (java.io.InputStream)398 Header (org.apache.http.Header)385 StringEntity (org.apache.http.entity.StringEntity)363 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)344 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)338 HttpPut (org.apache.http.client.methods.HttpPut)320 ArrayList (java.util.ArrayList)316 Identity (org.olat.core.id.Identity)262 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)253 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)209 File (java.io.File)196