use of org.apache.commons.httpclient.methods.HeadMethod in project cosmic by MissionCriticalCloud.
the class UriUtils method checkUrlExistence.
// use http HEAD method to validate url
public static void checkUrlExistence(final String url) {
if (url.toLowerCase().startsWith("http") || url.toLowerCase().startsWith("https")) {
final HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
final HeadMethod httphead = new HeadMethod(url);
try {
if (httpClient.executeMethod(httphead) != HttpStatus.SC_OK) {
throw new IllegalArgumentException("Invalid URL: " + url);
}
} catch (final HttpException hte) {
throw new IllegalArgumentException("Cannot reach URL: " + url);
} catch (final IOException ioe) {
throw new IllegalArgumentException("Cannot reach URL: " + url);
}
}
}
use of org.apache.commons.httpclient.methods.HeadMethod in project ant-ivy by apache.
the class HelloIvy method main.
public static void main(String[] args) throws Exception {
String message = "Hello Ivy!";
System.out.println("standard message : " + message);
System.out.println("capitalized by " + WordUtils.class.getName() + " : " + WordUtils.capitalizeFully(message));
HttpClient client = new HttpClient();
HeadMethod head = new HeadMethod("http://www.ibiblio.org/");
client.executeMethod(head);
int status = head.getStatusCode();
System.out.println("head status code with httpclient: " + status);
head.releaseConnection();
System.out.println("now check if httpclient dependency on commons-logging has been realized");
Class<?> clss = Class.forName("org.apache.commons.logging.Log");
System.out.println("found logging class in classpath: " + clss);
}
use of org.apache.commons.httpclient.methods.HeadMethod in project intellij by bazelbuild.
the class ProjectViewDocumentationProvider method pageExists.
private static boolean pageExists(String url) {
final HttpClient client = new HttpClient();
final HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
params.setSoTimeout(5 * 1000);
params.setConnectionTimeout(5 * 1000);
try {
final HeadMethod method = new HeadMethod(url);
final int rc = client.executeMethod(method);
if (rc == 404) {
return false;
}
} catch (IllegalArgumentException e) {
return false;
} catch (IOException e) {
// ignore
}
return true;
}
Aggregations