Example usage for org.apache.commons.httpclient.methods HeadMethod setPath

List of usage examples for org.apache.commons.httpclient.methods HeadMethod setPath

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods HeadMethod setPath.

Prototype

@Override
public void setPath(String path) 

Source Link

Document

Sets the path of the HTTP method.

Usage

From source file:org.nuxeo.ecm.core.storage.sql.ScalityBinaryManager.java

/**
 * Verifies if a specific named bucket exists.
 *
 * @param objectID/*from w  ww .java 2  s .com*/
 */
public boolean objectExists(String objectID) {
    boolean objectExists = false;
    String url = PROTOCOL_PREFIX + this.bucketName + "." + this.hostBase;
    log.debug(url);
    HeadMethod headMethod = new HeadMethod(url);
    String contentMD5 = "";
    String stringToSign = StringGenerator.getStringToSign(HTTPMethod.HEAD, contentMD5, DEFAULT_CONTENT_TYPE,
            this.bucketName, objectID, new Date());
    try {
        headMethod.addRequestHeader("Authorization",
                StringGenerator.getAuthorizationString(stringToSign, awsID, awsSecret));
        headMethod.addRequestHeader("x-amz-date", StringGenerator.getCurrentDateString());
        headMethod.setPath("/" + objectID);
        HttpClient client = new HttpClient();
        int returnCode = client.executeMethod(headMethod);
        log.debug(headMethod.getResponseBodyAsString());
        // only for logging
        if (returnCode == HttpStatus.SC_OK) {
            objectExists = true;
        } else if (returnCode == HttpStatus.SC_NOT_FOUND) {
            objectExists = false;
            log.debug("Object " + objectID + " does not exist");
        } else {
            String connectionMsg = "Scality connection problem. Object could not be verified";
            log.debug(connectionMsg);
            throw new RuntimeException(connectionMsg);
        }
        headMethod.releaseConnection();
    } catch (SignatureException e) {
        throw new RuntimeException(e);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return objectExists;
}

From source file:org.nuxeo.ecm.core.storage.sql.ScalityBinaryManager.java

/**
 * Retrieves the content-length of the remote object
 *
 * @param objectID//from  www  .  j a v  a2s .co  m
 */
public long getContentLength(String objectID) {
    String url = PROTOCOL_PREFIX + this.bucketName + "." + this.hostBase;
    log.debug(url);
    HeadMethod headMethod = new HeadMethod(url);
    String contentMD5 = "";
    String stringToSign = StringGenerator.getStringToSign(HTTPMethod.HEAD, contentMD5, DEFAULT_CONTENT_TYPE,
            this.bucketName, objectID, new Date());
    long contentLength = 0;
    try {
        headMethod.addRequestHeader("Authorization",
                StringGenerator.getAuthorizationString(stringToSign, awsID, awsSecret));
        headMethod.addRequestHeader("x-amz-date", StringGenerator.getCurrentDateString());
        headMethod.setPath("/" + objectID);
        HttpClient client = new HttpClient();
        int returnCode = client.executeMethod(headMethod);
        // specific header
        if (returnCode == HttpStatus.SC_OK) {
            Header contentLengthHeader = headMethod.getResponseHeader("Content-Length");
            contentLength = Long.parseLong(contentLengthHeader.getValue());

        } else if (returnCode == HttpStatus.SC_NOT_FOUND) {
            log.debug("Object " + objectID + " does not exist");
        } else {
            String connectionMsg = "Scality connection problem. Object could not be verified";
            log.debug(connectionMsg);
            throw new RuntimeException(connectionMsg);
        }
        headMethod.releaseConnection();
    } catch (NumberFormatException e) {
        throw new RuntimeException(e);
    } catch (SignatureException e) {
        throw new RuntimeException(e);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return contentLength;
}

From source file:org.osaf.caldav4j.CalDAVCollection.java

public int testConnection(HttpClient httpClient) throws CalDAV4JException {
    HeadMethod method = new HeadMethod();
    method.setPath(getCalendarCollectionRoot());
    try {/*from  w w w  . j  a  v a 2  s  . c  o m*/
        httpClient.executeMethod(hostConfiguration, method);
    } catch (Exception e) {
        throw new CalDAV4JException(e.getMessage(), new Throwable(e.getCause()));
    }

    switch (method.getStatusCode()) {
    case CaldavStatus.SC_OK:
        break;
    default:
        throw new BadStatusException(method.getStatusCode(), method.getName(), getCalendarCollectionRoot());
    }
    return method.getStatusCode();
}