Search in sources :

Example 66 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project gocd by gocd.

the class HttpService method execute.

public CloseableHttpResponse execute(HttpRequestBase httpMethod) throws IOException {
    GoAgentServerHttpClient client = httpClientFactory.httpClient();
    CloseableHttpResponse response = client.execute(httpMethod);
    LOGGER.info("Got back " + response.getStatusLine().getStatusCode() + " from server");
    return response;
}
Also used : CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) GoAgentServerHttpClient(com.thoughtworks.go.agent.common.ssl.GoAgentServerHttpClient)

Example 67 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project gocd by gocd.

the class HttpServiceTest method shouldSetTheAcceptHeaderWhilePostingProperties.

@Test
public void shouldSetTheAcceptHeaderWhilePostingProperties() throws Exception {
    HttpPost post = mock(HttpPost.class);
    when(httpClientFactory.createPost("url")).thenReturn(post);
    CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    when(response.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
    when(httpClient.execute(post)).thenReturn(response);
    ArgumentCaptor<UrlEncodedFormEntity> entityCaptor = ArgumentCaptor.forClass(UrlEncodedFormEntity.class);
    service.postProperty("url", "value");
    verify(post).setHeader("Confirm", "true");
    verify(post).setEntity(entityCaptor.capture());
    UrlEncodedFormEntity expected = new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("value", "value")));
    UrlEncodedFormEntity actual = entityCaptor.getValue();
    assertEquals(IOUtils.toString(expected.getContent()), IOUtils.toString(actual.getContent()));
    assertEquals(expected.getContentLength(), expected.getContentLength());
    assertEquals(expected.getContentType(), expected.getContentType());
    assertEquals(expected.getContentEncoding(), expected.getContentEncoding());
    assertEquals(expected.isChunked(), expected.isChunked());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 68 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project gradle by gradle.

the class HttpClientHelper method executeGetOrHead.

protected CloseableHttpResponse executeGetOrHead(HttpRequestBase method) throws IOException {
    final CloseableHttpResponse httpResponse = performHttpRequest(method);
    // Consume content for non-successful, responses. This avoids the connection being left open.
    if (!wasSuccessful(httpResponse)) {
        CloseableHttpResponse response = new AutoClosedHttpResponse(httpResponse);
        HttpClientUtils.closeQuietly(httpResponse);
        return response;
    }
    return httpResponse;
}
Also used : CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 69 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project gradle by gradle.

the class HttpResourceAccessor method getRawResource.

/**
     * Same as #getResource except that it always gives access to the response body,
     * irrespective of the returned HTTP status code. Never returns {@code null}.
     */
public HttpResponseResource getRawResource(final URI uri, boolean revalidate) {
    String location = uri.toString();
    LOGGER.debug("Constructing external resource: {}", location);
    CloseableHttpResponse response = http.performRawGet(location, revalidate);
    return wrapResponse(uri, response);
}
Also used : CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 70 with CloseableHttpResponse

use of org.apache.http.client.methods.CloseableHttpResponse in project goci by EBISPOT.

the class SolrQueryService method querySolr.

//    public HttpEntity querySolr(String searchString) throws IOException{
public List<PublishedStudy> querySolr(String searchString) throws IOException {
    System.out.println(searchString);
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet(searchString);
    if (System.getProperty("http.proxyHost") != null) {
        HttpHost proxy;
        if (System.getProperty("http.proxyPort") != null) {
            proxy = new HttpHost(System.getProperty("http.proxyHost"), Integer.parseInt(System.getProperty("http.proxyPort")));
        } else {
            proxy = new HttpHost(System.getProperty("http.proxyHost"));
        }
        httpGet.setConfig(RequestConfig.custom().setProxy(proxy).build());
    }
    //        HttpEntity entity = null;
    List<PublishedStudy> studies = new ArrayList<>();
    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        getLog().debug("Received HTTP response: " + response.getStatusLine().toString());
        HttpEntity entity = response.getEntity();
        BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
        String output;
        while ((output = br.readLine()) != null) {
            SolrDataProcessingService jsonProcessor = new SolrDataProcessingService(output);
            studies = jsonProcessor.processJson();
        }
        EntityUtils.consume(entity);
    }
    //        return entity;
    return studies;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) InputStreamReader(java.io.InputStreamReader) HttpHost(org.apache.http.HttpHost) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BufferedReader(java.io.BufferedReader) PublishedStudy(uk.ac.ebi.spot.goci.model.PublishedStudy)

Aggregations

CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)536 HttpGet (org.apache.http.client.methods.HttpGet)242 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)171 StringEntity (org.apache.http.entity.StringEntity)127 JsonNode (com.fasterxml.jackson.databind.JsonNode)125 Test (org.junit.Test)125 HttpPost (org.apache.http.client.methods.HttpPost)107 IOException (java.io.IOException)105 HttpEntity (org.apache.http.HttpEntity)103 Deployment (org.activiti.engine.test.Deployment)87 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)67 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)57 InputStream (java.io.InputStream)53 HttpPut (org.apache.http.client.methods.HttpPut)50 Task (org.activiti.engine.task.Task)41 URI (java.net.URI)36 StatusLine (org.apache.http.StatusLine)34 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)34 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)31 BufferedReader (java.io.BufferedReader)30