Search in sources :

Example 76 with HttpHead

use of org.apache.http.client.methods.HttpHead in project wildfly by wildfly.

the class MicroProfileMetricsRequestMethodsTestCase method checkHead.

@Test
public void checkHead() throws Exception {
    final String endpointURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + "/metrics";
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        CloseableHttpResponse resp = client.execute(new HttpHead(endpointURL));
        assertEquals(405, resp.getStatusLine().getStatusCode());
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpHead(org.apache.http.client.methods.HttpHead) Test(org.junit.Test)

Example 77 with HttpHead

use of org.apache.http.client.methods.HttpHead in project wildfly by wildfly.

the class DenyUncoveredHttpMethodsTestCase method testHeadMethod.

@Test
public void testHeadMethod() throws Exception {
    HttpHead httpHead = new HttpHead(getURL());
    HttpResponse response = getHttpResponse(httpHead);
    assertThat(statusCodeOf(response), is(HttpServletResponse.SC_UNAUTHORIZED));
}
Also used : HttpResponse(org.apache.http.HttpResponse) HttpHead(org.apache.http.client.methods.HttpHead) Test(org.junit.Test)

Example 78 with HttpHead

use of org.apache.http.client.methods.HttpHead in project wildfly by wildfly.

the class NonHaWebSessionPersistenceTestCase method testSessionPersistence.

@Test
public void testSessionPersistence(@ArquillianResource(SimpleServlet.class) @OperateOnDeployment(DEPLOYMENT_1) URL baseURL, @ArquillianResource @OperateOnDeployment(DEPLOYMENT_1) ManagementClient managementClient) throws Exception {
    URI url = SimpleServlet.createURI(baseURL);
    try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) {
        String sessionId = null;
        try (CloseableHttpResponse response = client.execute(new HttpGet(url))) {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(1, Integer.parseInt(response.getFirstHeader("value").getValue()));
            sessionId = response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue();
        }
        try (CloseableHttpResponse response = client.execute(new HttpGet(url))) {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals(2, Integer.parseInt(response.getFirstHeader("value").getValue()));
            Assert.assertFalse(Boolean.valueOf(response.getFirstHeader("serialized").getValue()));
            Assert.assertEquals(sessionId, response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue());
        }
        NodeUtil.stop(this.controller, CONTAINER_SINGLE);
        NodeUtil.start(this.controller, CONTAINER_SINGLE);
        if (Boolean.getBoolean("ts.bootable") || Boolean.getBoolean("ts.bootable.ee9")) {
            NodeUtil.deploy(this.deployer, DEPLOYMENT_1);
        }
        try (CloseableHttpResponse response = client.execute(new HttpGet(url))) {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertEquals("Session passivation was configured but session was lost after restart.", 3, Integer.parseInt(response.getFirstHeader("value").getValue()));
            Assert.assertTrue(Boolean.valueOf(response.getFirstHeader("serialized").getValue()));
            Assert.assertEquals(sessionId, response.getFirstHeader(SimpleServlet.SESSION_ID_HEADER).getValue());
        }
        String invalidationRequest = String.format("/deployment=%s/subsystem=undertow:invalidate-session(session-id=%s)", APPLICATION_NAME, sessionId);
        ClusterTestUtil.execute(managementClient, invalidationRequest);
        try (CloseableHttpResponse response = client.execute(new HttpHead(url))) {
            Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode());
            Assert.assertFalse(response.containsHeader(SimpleServlet.SESSION_ID_HEADER));
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) URI(java.net.URI) HttpHead(org.apache.http.client.methods.HttpHead) Test(org.junit.Test)

Example 79 with HttpHead

use of org.apache.http.client.methods.HttpHead in project undertow by undertow-io.

the class FileHandlerTestCase method testHeadRequest.

@Test
public void testHeadRequest() throws IOException, URISyntaxException {
    TestHttpClient client = new TestHttpClient();
    Path file = Paths.get(getClass().getResource("page.html").toURI());
    Path rootPath = file.getParent();
    try {
        DefaultServer.setRootHandler(new CanonicalPathHandler().setNext(new PathHandler().addPrefixPath("/path", new ResourceHandler(new PathResourceManager(rootPath, 10485760)).setDirectoryListingEnabled(true))));
        HttpHead get = new HttpHead(DefaultServer.getDefaultServerURL() + "/path/page.html");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        Assert.assertEquals(Long.toString(Files.size(file)), result.getHeaders(Headers.CONTENT_LENGTH_STRING)[0].getValue());
        Header[] headers = result.getHeaders("Content-Type");
        Assert.assertEquals("text/html", headers[0].getValue());
    } finally {
        client.getConnectionManager().shutdown();
    }
}
Also used : Path(java.nio.file.Path) Header(org.apache.http.Header) CanonicalPathHandler(io.undertow.server.handlers.CanonicalPathHandler) CanonicalPathHandler(io.undertow.server.handlers.CanonicalPathHandler) PathHandler(io.undertow.server.handlers.PathHandler) HttpResponse(org.apache.http.HttpResponse) ResourceHandler(io.undertow.server.handlers.resource.ResourceHandler) PathResourceManager(io.undertow.server.handlers.resource.PathResourceManager) HttpHead(org.apache.http.client.methods.HttpHead) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 80 with HttpHead

use of org.apache.http.client.methods.HttpHead in project indy by Commonjava.

the class ProxyHttpsWildcardHostCertTest method head.

protected String head(String url, boolean withCACert, String user, String pass) throws Exception {
    CloseableHttpClient client;
    if (withCACert) {
        File jks = new File(etcDir, "ssl/ca.jks");
        KeyStore trustStore = getTrustStore(jks);
        SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
        client = proxiedHttp(user, pass, socketFactory);
    } else {
        client = proxiedHttp(user, pass);
    }
    HttpHead req = new HttpHead(url);
    CloseableHttpResponse response = null;
    InputStream stream = null;
    try {
        response = client.execute(req, proxyContext(user, pass));
        return response.toString();
    } finally {
        IOUtils.closeQuietly(stream);
        HttpResources.cleanupResources(req, response, client);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) File(java.io.File) KeyStore(java.security.KeyStore) HttpHead(org.apache.http.client.methods.HttpHead)

Aggregations

HttpHead (org.apache.http.client.methods.HttpHead)104 HttpResponse (org.apache.http.HttpResponse)42 HttpGet (org.apache.http.client.methods.HttpGet)30 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)27 IOException (java.io.IOException)26 HttpPut (org.apache.http.client.methods.HttpPut)24 Test (org.junit.Test)24 HttpPost (org.apache.http.client.methods.HttpPost)23 URI (java.net.URI)22 Header (org.apache.http.Header)21 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)19 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)16 HttpDelete (org.apache.http.client.methods.HttpDelete)14 InputStream (java.io.InputStream)13 HttpEntity (org.apache.http.HttpEntity)11 File (java.io.File)9 HttpOptions (org.apache.http.client.methods.HttpOptions)9 StringEntity (org.apache.http.entity.StringEntity)9 HttpPatch (org.apache.http.client.methods.HttpPatch)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6