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

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

Introduction

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

Prototype

public abstract void setFollowRedirects(boolean paramBoolean);

Source Link

Usage

From source file:org.zaproxy.zap.extension.ascanrulesAlpha.CloudMetadataScanner.java

private static HttpMethod createRequestMethod(HttpRequestHeader header, HttpBody body, HttpMethodParams params)
        throws URIException {
    HttpMethod httpMethod = new ZapGetMethod();
    httpMethod.setURI(header.getURI());/*from w  ww  .j  a  va  2 s.c  o  m*/
    httpMethod.setParams(params);
    params.setVersion(HttpVersion.HTTP_1_1);

    String msg = header.getHeadersAsString();

    String[] split = Pattern.compile("\\r\\n", Pattern.MULTILINE).split(msg);
    String token = null;
    String name = null;
    String value = null;

    int pos = 0;
    for (int i = 0; i < split.length; i++) {
        token = split[i];
        if (token.equals("")) {
            continue;
        }

        if ((pos = token.indexOf(":")) < 0) {
            return null;
        }
        name = token.substring(0, pos).trim();
        value = token.substring(pos + 1).trim();
        httpMethod.addRequestHeader(name, value);
    }
    if (body != null && body.length() > 0 && (httpMethod instanceof EntityEnclosingMethod)) {
        EntityEnclosingMethod post = (EntityEnclosingMethod) httpMethod;
        post.setRequestEntity(new ByteArrayRequestEntity(body.getBytes()));
    }
    httpMethod.setFollowRedirects(false);
    return httpMethod;
}

From source file:xbl.Session.java

private <T extends Response> T connect(HttpMethod method, Class<? extends T> handler) {
    try {/*from  ww  w.  ja v a 2 s. c om*/
        method.setFollowRedirects(false);
        client.executeMethod(method);
        @SuppressWarnings({ "unchecked" })
        Constructor<T> constructor = (Constructor<T>) handler.getConstructor(HttpMethod.class);
        return constructor.newInstance(method);
    } catch (IOException e) {
        throw new NetworkException(e);
    } catch (NoSuchMethodException e) {
        throw new SystemException(e);
    } catch (InstantiationException e) {
        throw new SystemException(e);
    } catch (IllegalAccessException e) {
        throw new SystemException(e);
    } catch (InvocationTargetException e) {
        throw new SystemException(e);
    } finally {
        method.releaseConnection();
    }
}