use of org.apache.http.client.methods.HttpHead in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method sendHttpHEADRequest.
/**
* Send HTTP HEAD request to test the endpoint url
*
* @param urlVal url for which the HEAD request is sent
* @return ApiEndpointValidationResponseDTO Response DTO containing validity information of the HEAD request made
* to test the endpoint url
*/
public static ApiEndpointValidationResponseDTO sendHttpHEADRequest(String urlVal) throws APIManagementException {
ApiEndpointValidationResponseDTO apiEndpointValidationResponseDTO = new ApiEndpointValidationResponseDTO();
org.apache.http.client.HttpClient client = APIUtil.getHttpClient(urlVal);
HttpHead method = new HttpHead(urlVal);
try {
HttpResponse response = client.execute(method);
apiEndpointValidationResponseDTO.setStatusCode(response.getStatusLine().getStatusCode());
apiEndpointValidationResponseDTO.setStatusMessage(HttpStatus.getStatusText(response.getStatusLine().getStatusCode()));
} catch (UnknownHostException e) {
log.error("UnknownHostException occurred while sending the HEAD request to the given endpoint url:", e);
apiEndpointValidationResponseDTO.setError("Unknown Host");
} catch (IOException e) {
log.error("Error occurred while sending the HEAD request to the given endpoint url:", e);
apiEndpointValidationResponseDTO.setError("Connection error");
} finally {
method.releaseConnection();
}
return apiEndpointValidationResponseDTO;
}
use of org.apache.http.client.methods.HttpHead in project indy by Commonjava.
the class DefaultStoreValidator method availableSslRemoteRepository.
private ArtifactStoreValidateData availableSslRemoteRepository(CountDownLatch httpRequestsLatch, Optional<URL> remoteUrl, RemoteRepository remoteRepository) throws InterruptedException, ExecutionException, URISyntaxException {
HashMap<String, String> errors = new HashMap<>();
// Execute HTTP GET & HEAD requests in separate thread pool from executor service
Future<Integer> httpGetStatus = executeGetHttp(new HttpGet(remoteUrl.get().toURI()), httpRequestsLatch);
Future<Integer> httpHeadStatus = executeHeadHttp(new HttpHead(remoteUrl.get().toURI()), httpRequestsLatch);
// Waiting for Http GET & HEAD Request Executor tasks to finish
httpRequestsLatch.await();
if (!remoteUrl.get().getProtocol().equalsIgnoreCase(StoreValidationConstants.HTTPS)) {
errors.put(StoreValidationConstants.HTTP_PROTOCOL, remoteUrl.get().getProtocol());
}
// Check for Sucessfull Validation for only one http call to be successfull...
if (httpGetStatus.get() < 400 || httpHeadStatus.get() < 400) {
LOGGER.warn("=> Success HTTP GET and HEAD Response from Remote Repository: " + remoteUrl.get());
errors.put(StoreValidationConstants.HTTP_GET_STATUS, httpGetStatus.get().toString());
errors.put(StoreValidationConstants.HTTP_HEAD_STATUS, httpHeadStatus.get().toString());
return new ArtifactStoreValidateData.Builder(remoteRepository.getKey()).setRepositoryUrl(remoteUrl.get().toExternalForm()).setValid(true).setErrors(errors).build();
} else {
LOGGER.warn("=> Failure @ HTTP GET and HEAD Response from Remote Repository: " + remoteUrl.get());
errors.put(StoreValidationConstants.HTTP_GET_STATUS, httpGetStatus.get().toString());
errors.put(StoreValidationConstants.HTTP_HEAD_STATUS, httpHeadStatus.get().toString());
return new ArtifactStoreValidateData.Builder(remoteRepository.getKey()).setRepositoryUrl(remoteUrl.get().toExternalForm()).setValid(false).setErrors(errors).build();
}
}
use of org.apache.http.client.methods.HttpHead in project janusgraph by JanusGraph.
the class ElasticsearchIndexTest method indexExists.
private boolean indexExists(String name) throws IOException {
final CloseableHttpResponse response = httpClient.execute(host, new HttpHead(name));
final boolean exists = response.getStatusLine().getStatusCode() == 200;
IOUtils.closeQuietly(response);
return exists;
}
use of org.apache.http.client.methods.HttpHead in project undertow by undertow-io.
the class HeadBlockingExchangeTestCase method sendHttpHead.
@Test
public void sendHttpHead() throws IOException {
HttpHead head = new HttpHead(DefaultServer.getDefaultServerURL());
TestHttpClient client = new TestHttpClient();
try {
HttpResponse result = client.execute(head);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals("", HttpClientUtils.readResponse(result));
Assert.assertEquals("100", result.getFirstHeader("Content-Length").getValue());
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.client.methods.HttpHead in project undertow by undertow-io.
the class HeadTestCase method sendHttpHead.
@Test
public void sendHttpHead() throws IOException {
connection = null;
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
HttpHead head = new HttpHead(DefaultServer.getDefaultServerURL() + "/path");
TestHttpClient client = new TestHttpClient();
try {
generateMessage(1);
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(message, HttpClientUtils.readResponse(result));
result = client.execute(head);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals("", HttpClientUtils.readResponse(result));
generateMessage(1000);
result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(message, HttpClientUtils.readResponse(result));
result = client.execute(head);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals("", HttpClientUtils.readResponse(result));
} finally {
client.getConnectionManager().shutdown();
}
}
Aggregations