Search in sources :

Example 1 with Response

use of com.atlassian.httpclient.api.Response in project jira-plugin by jenkinsci.

the class ApacheAsyncHttpClientTest method simple_post.

@Test
public void simple_post() throws Exception {
    TestHandler testHandler = new TestHandler();
    prepare(testHandler);
    ApacheAsyncHttpClient httpClient = new ApacheAsyncHttpClient(null, buildApplicationProperties(), new NoOpThreadLocalContextManager(), new HttpClientOptions());
    Response response = // 
    httpClient.newRequest("http://localhost:" + connector.getLocalPort() + "/foo").setEntity(// 
    "FOO").setContentType(// 
    "text").post().get(10, TimeUnit.SECONDS);
    Assert.assertEquals(200, response.getStatusCode());
    Assert.assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
    Assert.assertEquals("FOO", testHandler.postReceived);
}
Also used : Response(com.atlassian.httpclient.api.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpClientOptions(com.atlassian.httpclient.api.factory.HttpClientOptions) Test(org.junit.Test)

Example 2 with Response

use of com.atlassian.httpclient.api.Response in project jira-plugin by jenkinsci.

the class ApacheAsyncHttpClient method translate.

private Response translate(HttpResponse httpResponse) throws IOException {
    StatusLine status = httpResponse.getStatusLine();
    Response.Builder responseBuilder = DefaultResponse.builder().setMaxEntitySize(httpClientOptions.getMaxEntitySize()).setStatusCode(status.getStatusCode()).setStatusText(status.getReasonPhrase());
    Header[] httpHeaders = httpResponse.getAllHeaders();
    for (Header httpHeader : httpHeaders) {
        responseBuilder.setHeader(httpHeader.getName(), httpHeader.getValue());
    }
    final HttpEntity entity = httpResponse.getEntity();
    if (entity != null) {
        responseBuilder.setEntityStream(entity.getContent());
    }
    return responseBuilder.build();
}
Also used : StatusLine(org.apache.http.StatusLine) Response(com.atlassian.httpclient.api.Response) HttpResponse(org.apache.http.HttpResponse) Header(org.apache.http.Header) HttpEntity(org.apache.http.HttpEntity)

Example 3 with Response

use of com.atlassian.httpclient.api.Response in project jira-plugin by jenkinsci.

the class ApacheAsyncHttpClientTest method simple_get_with_proxy.

@Test
public void simple_get_with_proxy() throws Exception {
    ProxyTestHandler testHandler = new ProxyTestHandler();
    prepare(testHandler);
    Jenkins.get().proxy = new ProxyConfiguration("localhost", connector.getLocalPort(), "foo", "bar");
    ApacheAsyncHttpClient httpClient = new ApacheAsyncHttpClient(null, buildApplicationProperties(), new NoOpThreadLocalContextManager(), new HttpClientOptions());
    Response response = // 
    httpClient.newRequest("http://jenkins.io").get().get(30, TimeUnit.SECONDS);
    Assert.assertEquals(200, response.getStatusCode());
    Assert.assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
}
Also used : Response(com.atlassian.httpclient.api.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ProxyConfiguration(hudson.ProxyConfiguration) HttpClientOptions(com.atlassian.httpclient.api.factory.HttpClientOptions) Test(org.junit.Test)

Example 4 with Response

use of com.atlassian.httpclient.api.Response in project jira-plugin by jenkinsci.

the class ApacheAsyncHttpClientTest method simple_post_with_proxy.

@Test
public void simple_post_with_proxy() throws Exception {
    ProxyTestHandler testHandler = new ProxyTestHandler();
    prepare(testHandler);
    Jenkins.getInstance().proxy = new ProxyConfiguration("localhost", connector.getLocalPort(), "foo", "bar");
    ApacheAsyncHttpClient httpClient = new ApacheAsyncHttpClient(null, buildApplicationProperties(), new NoOpThreadLocalContextManager(), new HttpClientOptions());
    Response response = // 
    httpClient.newRequest("http://jenkins.io").setEntity(// 
    "FOO").setContentType(// 
    "text").post().get(30, TimeUnit.SECONDS);
    // we are sure to hit the proxy first :-)
    Assert.assertEquals(200, response.getStatusCode());
    Assert.assertEquals(CONTENT_RESPONSE, IOUtils.toString(response.getEntityStream()));
    Assert.assertEquals("FOO", testHandler.postReceived);
}
Also used : Response(com.atlassian.httpclient.api.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ProxyConfiguration(hudson.ProxyConfiguration) HttpClientOptions(com.atlassian.httpclient.api.factory.HttpClientOptions) Test(org.junit.Test)

Example 5 with Response

use of com.atlassian.httpclient.api.Response in project jira-plugin by jenkinsci.

the class ApacheAsyncHttpClientTest method simple_get_with_non_proxy_host.

@Test
public void simple_get_with_non_proxy_host() throws Exception {
    ProxyTestHandler testHandler = new ProxyTestHandler();
    prepare(testHandler);
    Jenkins.getInstance().proxy = new ProxyConfiguration("localhost", connector.getLocalPort(), "foo", "bar", "www.apache.org");
    ApacheAsyncHttpClient httpClient = new ApacheAsyncHttpClient(null, buildApplicationProperties(), new NoOpThreadLocalContextManager(), new HttpClientOptions());
    Response response = httpClient.newRequest("http://www.apache.org").get().get(30, TimeUnit.SECONDS);
    Assert.assertEquals(200, response.getStatusCode());
// Assert.assertEquals( CONTENT_RESPONSE, IOUtils.toString( response.getEntityStream() ) );
}
Also used : Response(com.atlassian.httpclient.api.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ProxyConfiguration(hudson.ProxyConfiguration) HttpClientOptions(com.atlassian.httpclient.api.factory.HttpClientOptions) Test(org.junit.Test)

Aggregations

Response (com.atlassian.httpclient.api.Response)6 HttpClientOptions (com.atlassian.httpclient.api.factory.HttpClientOptions)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Test (org.junit.Test)5 ProxyConfiguration (hudson.ProxyConfiguration)3 Header (org.apache.http.Header)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1