Search in sources :

Example 81 with CloseableHttpClient

use of org.apache.http.impl.client.CloseableHttpClient in project wildfly by wildfly.

the class WebModuleDeploymentTestCase method testSimpleBeanInjected.

@Test
public void testSimpleBeanInjected() throws Exception {
    try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
        HttpGet httpget = new HttpGet(url.toExternalForm() + "/servlet");
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        StatusLine statusLine = response.getStatusLine();
        assertEquals(200, statusLine.getStatusCode());
        String result = EntityUtils.toString(entity);
        Assert.assertEquals(ModuleServlet.MODULE_SERVLET, result);
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 82 with CloseableHttpClient

use of org.apache.http.impl.client.CloseableHttpClient in project wildfly by wildfly.

the class ExternalTagLibTestCase method testExternalTagLibOnly.

@Test
public void testExternalTagLibOnly() throws Exception {
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpGet httpget = new HttpGet(external_dependency_only_url.toExternalForm() + TEST_JSP);
        HttpResponse response = httpClient.execute(httpget);
        HttpEntity entity = response.getEntity();
        String result = EntityUtils.toString(entity);
        Assert.assertTrue(result, result.contains("External Tag!"));
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 83 with CloseableHttpClient

use of org.apache.http.impl.client.CloseableHttpClient in project wildfly by wildfly.

the class DefaultServletMultipartConfigTestCase method testMultipartRequestToDefaultServlet.

@Test
public void testMultipartRequestToDefaultServlet() throws Exception {
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpPost post = new HttpPost(url.toExternalForm() + "/servlet");
        post.setEntity(MultipartEntityBuilder.create().addTextBody("file", MESSAGE).build());
        HttpResponse response = httpClient.execute(post);
        HttpEntity entity = response.getEntity();
        StatusLine statusLine = response.getStatusLine();
        assertEquals(200, statusLine.getStatusCode());
        String result = EntityUtils.toString(entity);
        Assert.assertEquals(MESSAGE, result);
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 84 with CloseableHttpClient

use of org.apache.http.impl.client.CloseableHttpClient in project wildfly by wildfly.

the class WebSecurityBASICTestCase method makeCall.

@Override
protected void makeCall(String user, String pass, int expectedStatusCode) throws Exception {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort()), new UsernamePasswordCredentials(user, pass));
    try (CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build()) {
        HttpGet httpget = new HttpGet(url.toExternalForm() + "secured/");
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        StatusLine statusLine = response.getStatusLine();
        if (entity != null) {
            log.trace("Response content length: " + entity.getContentLength());
        }
        assertEquals(expectedStatusCode, statusLine.getStatusCode());
        EntityUtils.consume(entity);
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) AuthScope(org.apache.http.auth.AuthScope) HttpResponse(org.apache.http.HttpResponse) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 85 with CloseableHttpClient

use of org.apache.http.impl.client.CloseableHttpClient in project wildfly by wildfly.

the class UndertowNonBlockingHandlerTestCase method testNonBlockingHandler.

@Test
public void testNonBlockingHandler() throws Exception {
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpGet httpget = new HttpGet(url.toExternalForm());
        HttpResponse response = httpClient.execute(httpget);
        HttpEntity entity = response.getEntity();
        StatusLine statusLine = response.getStatusLine();
        assertEquals(200, statusLine.getStatusCode());
        String result = EntityUtils.toString(entity);
        Assert.assertEquals(SimpleUndertowExtension.THIS_IS_NOT_A_SERVLET, result);
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Aggregations

CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)430 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)238 HttpGet (org.apache.http.client.methods.HttpGet)212 Test (org.junit.Test)206 HttpResponse (org.apache.http.HttpResponse)108 HttpEntity (org.apache.http.HttpEntity)92 IOException (java.io.IOException)90 HttpPost (org.apache.http.client.methods.HttpPost)85 StringEntity (org.apache.http.entity.StringEntity)67 InputStream (java.io.InputStream)57 StatusLine (org.apache.http.StatusLine)41 HttpHost (org.apache.http.HttpHost)36 URI (java.net.URI)35 RequestConfig (org.apache.http.client.config.RequestConfig)32 Header (org.apache.http.Header)24 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)24 File (java.io.File)22 HttpPut (org.apache.http.client.methods.HttpPut)22 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19