Search in sources :

Example 11 with HeadMethod

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);
        }
    }
}
Also used : HeadMethod(org.apache.commons.httpclient.methods.HeadMethod) HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException)

Example 12 with HeadMethod

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);
}
Also used : HeadMethod(org.apache.commons.httpclient.methods.HeadMethod) HttpClient(org.apache.commons.httpclient.HttpClient)

Example 13 with HeadMethod

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;
}
Also used : HeadMethod(org.apache.commons.httpclient.methods.HeadMethod) HttpConnectionManagerParams(org.apache.commons.httpclient.params.HttpConnectionManagerParams) HttpClient(org.apache.commons.httpclient.HttpClient) IOException(java.io.IOException)

Aggregations

HeadMethod (org.apache.commons.httpclient.methods.HeadMethod)13 IOException (java.io.IOException)6 HttpClient (org.apache.commons.httpclient.HttpClient)6 Header (org.apache.commons.httpclient.Header)3 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)3 Test (org.junit.Test)3 HttpException (org.apache.commons.httpclient.HttpException)2 HttpMethodBase (org.apache.commons.httpclient.HttpMethodBase)2 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)2 DeleteMethod (org.apache.commons.httpclient.methods.DeleteMethod)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 InputStreamRequestEntity (org.apache.commons.httpclient.methods.InputStreamRequestEntity)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2 PutMethod (org.apache.commons.httpclient.methods.PutMethod)2 HttpConnectionManagerParams (org.apache.commons.httpclient.params.HttpConnectionManagerParams)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1