Example usage for org.apache.commons.httpclient.methods GetMethod toString

List of usage examples for org.apache.commons.httpclient.methods GetMethod toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.support.HqAuthenticationFilter.java

/**
 * This method makes a request to a hook inside HQU tomcatserverconfig plugin. If the returned status code indicates
 * a redirect, then this would be expiration of the session, and being sent back to the login page. Otherwise, it
 * indicates the session is active./*from   w  w w .j a v  a2s .  c  om*/
 * 
 * @param request
 * @param sessionId
 * @return
 */
private boolean sessionIdExpired(ServletRequest request, String sessionId) {
    String basePath = RequestUtils.getLocalHqUrl(request);

    GetMethod method = new GetMethod(
            basePath + "/hqu/tomcatserverconfig/tomcatserverconfig/checkSessionStatus.hqu");

    logger.debug("About to check status at " + method.toString());

    method.setFollowRedirects(false);
    method.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    method.setRequestHeader("Cookie", "JSESSIONID=" + sessionId);
    HttpClient httpClient = new HttpClient();
    try {
        httpClient.executeMethod(method);
        if (method.getStatusCode() >= 300 && method.getStatusCode() < 400) {
            logger.info("User's session has expired. Redirecting to login page");
            return true;
        }
    } catch (HttpException e) {
        logger.warn("Failure occurred when checking if session has expired. Redirecting to login page.", e);
        return true;
    } catch (IOException e) {
        logger.warn("Failure occurred when checking if session has expired. Redirecting to login page.", e);
        return true;
    }

    return false;
}

From source file:com.wandisco.s3hdfs.rewrite.redirect.MetadataFileRedirect.java

/**
 * Sends a GET command to read a metadata file inside of HDFS.
 * It uses the URL from the modified URI to do so.
 * It will then consume the 307 response and read from the DataNode as well.
 *
 * @throws IOException//from w  ww . j  av  a2 s.c  o m
 */
public Properties sendHeadRead(String metadataPath, String nnHostAddress, String userName) throws IOException {
    // Set up HttpGet and get response
    String[] nnHost = nnHostAddress.split(":");
    GetMethod httpGet = (GetMethod) getHttpMethod(request.getScheme(), nnHost[0], Integer.decode(nnHost[1]),
            "OPEN", userName, ADD_WEBHDFS(metadataPath), GET);

    // Try up to 5 times to get the metadata
    httpClient.executeMethod(httpGet);
    LOG.info("1st response: " + httpGet.toString());
    System.out.println("1st response: " + httpGet.toString());

    for (int i = 0; i < 5 && httpGet.getStatusCode() == 403; i++) {
        httpGet.releaseConnection();
        httpClient.executeMethod(httpGet);
        LOG.info("Next response: " + httpGet.toString());
        System.out.println("Next response: " + httpGet.toString());
    }
    assert httpGet.getStatusCode() == 200;

    // Read metadata map
    InputStream is = httpGet.getResponseBodyAsStream();
    Properties metadata = new Properties();
    metadata.load(is);

    // Consume response remainder to re-allocate connection and return map
    httpGet.releaseConnection();
    return metadata;
}