Example usage for org.apache.commons.httpclient HttpMethod getResponseHeaders

List of usage examples for org.apache.commons.httpclient HttpMethod getResponseHeaders

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpMethod getResponseHeaders.

Prototype

public abstract Header[] getResponseHeaders(String paramString);

Source Link

Usage

From source file:davmail.http.DavGatewayHttpClientFacade.java

/**
 * Test if the method response is gzip encoded
 *
 * @param method http method/*  w  w w  .j av a 2 s.c o m*/
 * @return true if response is gzip encoded
 */
public static boolean isGzipEncoded(HttpMethod method) {
    Header[] contentEncodingHeaders = method.getResponseHeaders("Content-Encoding");
    if (contentEncodingHeaders != null) {
        for (Header header : contentEncodingHeaders) {
            if ("gzip".equals(header.getValue())) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.tasktop.c2c.server.web.proxy.HttpProxy.java

public int getResponseContentLength(HttpMethod httpMethod) {
    Header[] headers = httpMethod.getResponseHeaders("Content-Length");
    if (headers.length == 0) {
        return -1;
    }/*from   www  . j av  a  2s  . c o m*/

    for (int i = headers.length - 1; i >= 0; i--) {
        Header header = headers[i];
        try {
            return Integer.parseInt(header.getValue());
        } catch (NumberFormatException e) {

        }
        // See if we can have better luck with another header, if present
    }
    return -1;
}

From source file:com.clarkparsia.sbol.editor.sparql.StardogEndpoint.java

private RDFParser getParser(HttpMethod response) {
    for (Header header : response.getResponseHeaders("Content-Type")) {
        for (HeaderElement headerEl : header.getElements()) {
            String mimeType = headerEl.getName();
            if (mimeType != null) {
                RDFFormat format = (RDFFormat) this.registry.getFileFormatForMIMEType(mimeType);

                RDFParserFactory factory = (RDFParserFactory) this.registry.get(format);
                if (factory != null)
                    return factory.getParser();
            }//www  . ja va 2s  .  c o m
        }
    }
    throw new UnsupportedQueryResultFormatException(
            "No parser factory available for this graph query result format");
}

From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClient.java

private long getContentLength(HttpMethod method) {
    long size = -1;
    Header[] contentLengthHeader = method.getResponseHeaders("Content-Length");
    if (contentLengthHeader != null && contentLengthHeader.length == 1 && contentLengthHeader[0] != null
            && contentLengthHeader[0].getValue() != null) {
        try {/*from  w w  w.ja va 2s.  c  o  m*/
            String contentLength = contentLengthHeader[0].getValue();
            size = Long.parseLong(contentLength);
        } catch (NumberFormatException e) {
            LOG.warn("cant parse content Content-Length", e);
        }
    }
    return size;
}

From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClient.java

private String getContentType(HttpMethod method) {
    String contentType = "application/octet-stream";
    Header[] contentTypeHeaders = method.getResponseHeaders("Content-Type");
    if (contentTypeHeaders != null && contentTypeHeaders.length == 1 && contentTypeHeaders[0] != null
            && contentTypeHeaders[0].getValue() != null) {
        contentType = contentTypeHeaders[0].getValue();
    }/*from w  ww  .  j  a v  a  2s. c om*/
    return contentType;
}

From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClient.java

private String GetFileNameFromContentDisposition(HttpMethod method) {
    String filename = "";
    ContentDisposition contentDisposition;
    Header[] contentDispositionHeader = method.getResponseHeaders("Content-Disposition");
    if (contentDispositionHeader != null && contentDispositionHeader.length == 1
            && contentDispositionHeader[0] != null && contentDispositionHeader[0].getValue() != null) {
        try {/*from w w  w  .ja v a 2  s .c o  m*/
            contentDisposition = new ContentDisposition(contentDispositionHeader[0].getValue());
            filename = contentDisposition.getFileName();
        } catch (java.text.ParseException e) {
            LOG.warn("cant parse content disposition", e);
        }
    }
    return filename;
}

From source file:com.taobao.diamond.client.impl.DefaultDiamondSubscriber.java

/**
 * //  w  ww. j a  v  a 2  s  . co m
 * 
 * @param httpMethod
 */
void changeSpacingInterval(HttpMethod httpMethod) {
    Header[] spacingIntervalHeaders = httpMethod.getResponseHeaders(Constants.SPACING_INTERVAL);
    if (spacingIntervalHeaders.length >= 1) {
        try {
            diamondConfigure.setPollingIntervalTime(Integer.parseInt(spacingIntervalHeaders[0].getValue()));
        } catch (RuntimeException e) {
            log.error("", e);
        }
    }
}

From source file:cn.leancloud.diamond.client.impl.DefaultDiamondSubscriber.java

/**
 * ?/*from ww  w  . j  a  v a 2 s.c o  m*/
 * 
 * @param httpMethod
 */
void changeSpacingInterval(HttpMethod httpMethod) {
    Header[] spacingIntervalHeaders = httpMethod.getResponseHeaders(Constants.SPACING_INTERVAL);
    if (spacingIntervalHeaders.length >= 1) {
        try {
            diamondConfigure.setPollingIntervalTime(Integer.parseInt(spacingIntervalHeaders[0].getValue()));
        } catch (RuntimeException e) {
            log.error("", e);
        }
    }
}

From source file:com.cyberway.issue.crawler.fetcher.FetchHTTP.java

/**
 * @param method Method that got a 401./*www.  j a v a 2  s.c o m*/
 * @param curi CrawlURI that got a 401.
 * @return Returns first wholesome authscheme found else null.
 */
protected AuthScheme getAuthScheme(final HttpMethod method, final CrawlURI curi) {
    Header[] headers = method.getResponseHeaders("WWW-Authenticate");
    if (headers == null || headers.length <= 0) {
        logger.info("We got a 401 but no WWW-Authenticate challenge: " + curi.toString());
        return null;
    }

    Map authschemes = null;
    try {
        authschemes = AuthChallengeParser.parseChallenges(headers);
    } catch (MalformedChallengeException e) {
        logger.info("Failed challenge parse: " + e.getMessage());
    }
    if (authschemes == null || authschemes.size() <= 0) {
        logger.info("We got a 401 and WWW-Authenticate challenge" + " but failed parse of the header "
                + curi.toString());
        return null;
    }

    AuthScheme result = null;
    // Use the first auth found.
    for (Iterator i = authschemes.keySet().iterator(); result == null && i.hasNext();) {
        String key = (String) i.next();
        String challenge = (String) authschemes.get(key);
        if (key == null || key.length() <= 0 || challenge == null || challenge.length() <= 0) {
            logger.warning("Empty scheme: " + curi.toString() + ": " + headers);
        }
        AuthScheme authscheme = null;
        if (key.equals("basic")) {
            authscheme = new BasicScheme();
        } else if (key.equals("digest")) {
            authscheme = new DigestScheme();
        } else {
            logger.info("Unsupported scheme: " + key);
            continue;
        }

        try {
            authscheme.processChallenge(challenge);
        } catch (MalformedChallengeException e) {
            logger.info(e.getMessage() + " " + curi + " " + headers);
            continue;
        }
        if (authscheme.isConnectionBased()) {
            logger.info("Connection based " + authscheme);
            continue;
        }

        if (authscheme.getRealm() == null || authscheme.getRealm().length() <= 0) {
            logger.info("Empty realm " + authscheme + " for " + curi);
            continue;
        }
        result = authscheme;
    }

    return result;
}

From source file:org.apache.jmeter.protocol.http.sampler.HTTPHC3Impl.java

/**
 * From the <code>HttpMethod</code>, store all the "set-cookie" key-pair
 * values in the cookieManager of the <code>UrlConfig</code>.
 *
 * @param method//from w  ww.  ja  v  a2s. c o m
 *            <code>HttpMethod</code> which represents the request
 * @param u
 *            <code>URL</code> of the URL request
 * @param cookieManager
 *            the <code>CookieManager</code> containing all the cookies
 */
protected void saveConnectionCookies(HttpMethod method, URL u, CookieManager cookieManager) {
    if (cookieManager != null) {
        Header[] hdr = method.getResponseHeaders(HTTPConstants.HEADER_SET_COOKIE);
        for (Header responseHeader : hdr) {
            cookieManager.addCookieFromHeader(responseHeader.getValue(), u);
        }
    }
}