Search in sources :

Example 6 with HttpClientOptions

use of com.atlassian.httpclient.api.factory.HttpClientOptions 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 7 with HttpClientOptions

use of com.atlassian.httpclient.api.factory.HttpClientOptions 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 8 with HttpClientOptions

use of com.atlassian.httpclient.api.factory.HttpClientOptions 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)

Example 9 with HttpClientOptions

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

the class ApacheAsyncHttpClientTest method simple_get.

@Test
public void simple_get() 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").get().get(10, 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) HttpClientOptions(com.atlassian.httpclient.api.factory.HttpClientOptions) Test(org.junit.Test)

Aggregations

HttpClientOptions (com.atlassian.httpclient.api.factory.HttpClientOptions)9 Response (com.atlassian.httpclient.api.Response)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Test (org.junit.Test)5 ProxyConfiguration (hudson.ProxyConfiguration)4 DefaultHttpClientFactory (com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClientFactory)2 HttpClient (com.atlassian.httpclient.api.HttpClient)2 ThreadLocalContextManager (com.atlassian.sal.api.executor.ThreadLocalContextManager)2 IOException (java.io.IOException)1 HttpHost (org.apache.http.HttpHost)1 AuthScope (org.apache.http.auth.AuthScope)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 HttpAsyncClientBuilder (org.apache.http.impl.nio.client.HttpAsyncClientBuilder)1 PoolingNHttpClientConnectionManager (org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager)1 DefaultConnectingIOReactor (org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor)1 IOReactorConfig (org.apache.http.impl.nio.reactor.IOReactorConfig)1 IOReactorExceptionHandler (org.apache.http.nio.reactor.IOReactorExceptionHandler)1