Example usage for org.apache.http.client.methods HttpHead getMethod

List of usage examples for org.apache.http.client.methods HttpHead getMethod

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpHead getMethod.

Prototype

@Override
    public String getMethod() 

Source Link

Usage

From source file:com.github.caldav4j.CalDAVCollection.java

/**
 * Uses the HTTP HEAD Method to check if the connection is possible.
 * @param httpClient HTTPClient to make the request
 * @return StatusCode//from w w  w  .ja  v a 2 s  .  c  o  m
 * @throws CalDAV4JException when Status is not {@link CalDAVStatus#SC_OK}
 */
public int testConnection(HttpClient httpClient) throws CalDAV4JException {
    HttpHead method = new HttpHead(getCalendarCollectionRoot());

    HttpResponse response = null;
    try {
        response = httpClient.execute(getDefaultHttpHost(method.getURI()), method);
    } catch (Exception e) {
        throw new CalDAV4JException(e.getMessage(), new Throwable(e.getCause()));
    }

    switch (response.getStatusLine().getStatusCode()) {
    case CalDAVStatus.SC_OK:
        break;
    default:
        throw new BadStatusException(response.getStatusLine().getStatusCode(), method.getMethod(),
                getCalendarCollectionRoot());
    }
    return response.getStatusLine().getStatusCode();
}