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);
}
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();
}
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()));
}
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);
}
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() ) );
}
Aggregations