Search in sources :

Example 86 with CloseableHttpClient

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

the class UndertowHandlersConfigTestCase method testRewrite.

@Test
public void testRewrite() throws Exception {
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpGet httpget = new HttpGet(url.toExternalForm() + "rewritea");
        HttpResponse response = httpClient.execute(httpget);
        HttpEntity entity = response.getEntity();
        StatusLine statusLine = response.getStatusLine();
        assertEquals(200, statusLine.getStatusCode());
        String result = EntityUtils.toString(entity);
        Assert.assertEquals("A file", result);
        Header[] headers = response.getHeaders("MyHeader");
        Assert.assertEquals(1, headers.length);
        Assert.assertEquals("MyValue", headers[0].getValue());
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) Header(org.apache.http.Header) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 87 with CloseableHttpClient

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

the class JspMappingTestCase method testFalseCss.

@Test
public void testFalseCss() throws Exception {
    log.trace("False CSS");
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpResponse response = httpClient.execute(new HttpGet(webappUrl.toURI() + "test.css"));
        try (InputStream in = response.getEntity().getContent()) {
            String content = getContent(in);
            assertThat(content, containsString("1 + 1 = 2"));
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 88 with CloseableHttpClient

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

the class JspMappingTestCase method testTrueHtmlPage.

@Test
public void testTrueHtmlPage() throws Exception {
    log.trace("True HTML");
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpResponse response = httpClient.execute(new HttpGet(webappUrl.toURI() + "index.html"));
        try (InputStream in = response.getEntity().getContent()) {
            String content = getContent(in);
            assertThat(content, not(containsString("1 + 1 = 2")));
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 89 with CloseableHttpClient

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

the class JspMappingTestCase method testFalseHtmlPage.

@Test
public void testFalseHtmlPage() throws Exception {
    log.trace("False HTML");
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpResponse response = httpClient.execute(new HttpGet(webappUrl.toURI() + "test.html"));
        try (InputStream in = response.getEntity().getContent()) {
            String content = getContent(in);
            assertThat(content, containsString("1 + 1 = 2"));
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 90 with CloseableHttpClient

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

the class JspMappingTestCase method testSimpleJSP.

@Test
public void testSimpleJSP() throws Exception {
    log.trace("Simple JSP");
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpResponse response = httpClient.execute(new HttpGet(webappUrl.toURI() + "index.jsp"));
        try (InputStream in = response.getEntity().getContent()) {
            String content = getContent(in);
            assertThat(content, containsString("1 + 1 = 2"));
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) 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