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

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

Introduction

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

Prototype

@Override
public URI getURI() throws URIException 

Source Link

Document

Returns the URI of the HTTP method

Usage

From source file:com.zimbra.cs.store.triton.TritonIncomingBlob.java

@Override
protected long getRemoteSize() throws IOException {
    outStream.flush();/*from   w  w w. ja  va  2 s.  com*/
    HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
    HeadMethod head = new HeadMethod(baseUrl + uploadUrl);
    ZimbraLog.store.info("heading %s", head.getURI());
    try {
        head.addRequestHeader(TritonHeaders.SERVER_TOKEN, serverToken.getToken());
        int statusCode = HttpClientUtil.executeMethod(client, head);
        if (statusCode == HttpStatus.SC_OK) {
            String contentLength = head.getResponseHeader(TritonHeaders.CONTENT_LENGTH).getValue();
            long remoteSize = -1;
            try {
                remoteSize = Long.valueOf(contentLength);
            } catch (NumberFormatException nfe) {
                throw new IOException("Content length can't be parsed to Long", nfe);
            }
            return remoteSize;
        } else {
            ZimbraLog.store.error("failed with code %d response: %s", statusCode,
                    head.getResponseBodyAsString());
            throw new IOException("unable to head blob " + statusCode + ":" + head.getStatusText(), null);
        }
    } finally {
        head.releaseConnection();
    }
}

From source file:org.apache.hadoop.fs.swift.http.SwiftRestClient.java

/**
 * Issue a head request//  w  w w  .j a  v  a2  s.  c o m
 * @param path path to query
 * @param requestHeaders request header
 * @return the response headers. This may be an empty list
 * @throws IOException IO problems
 * @throws FileNotFoundException if there is nothing at the end
 */
public Header[] headRequest(SwiftObjectPath path, final Header... requestHeaders) throws IOException {
    preRemoteCommand("headRequest");
    return perform(pathToURI(path), new HeadMethodProcessor<Header[]>() {
        @Override
        public Header[] extractResult(HeadMethod method) throws IOException {
            if (method.getStatusCode() == SC_NOT_FOUND) {
                throw new FileNotFoundException("Not Found " + method.getURI());
            }

            return method.getResponseHeaders();
        }

        @Override
        protected void setup(HeadMethod method) throws SwiftInternalStateException {
            setHeaders(method, requestHeaders);
        }
    });
}

From source file:org.opens.tanaguru.util.http.HttpRequestHandler.java

public int getHttpStatus(String url) {
    String encodedUrl = getEncodedUrl(url);
    HttpClient httpClient = getHttpClient(encodedUrl);
    HeadMethod head = new HeadMethod(encodedUrl);
    try {//from  w w w .  j  a  v  a 2 s.c om
        LOGGER.debug("executing head request to retrieve page status on " + head.getURI());
        int status = httpClient.executeMethod(head);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("received " + status + " from head request");
            for (Header h : head.getResponseHeaders()) {
                LOGGER.debug("header : " + h.toExternalForm());
            }
        }

        return status;
    } catch (UnknownHostException uhe) {
        LOGGER.warn("UnknownHostException on " + encodedUrl);
        return HttpStatus.SC_NOT_FOUND;
    } catch (IllegalArgumentException iae) {
        LOGGER.warn("IllegalArgumentException on " + encodedUrl);
        return HttpStatus.SC_NOT_FOUND;
    } catch (IOException ioe) {
        LOGGER.warn("IOException on " + encodedUrl);
        ioe.fillInStackTrace();
        return HttpStatus.SC_NOT_FOUND;
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        head.releaseConnection();
    }
}