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