Example usage for org.apache.commons.httpclient.params HttpClientParams ALLOW_CIRCULAR_REDIRECTS

List of usage examples for org.apache.commons.httpclient.params HttpClientParams ALLOW_CIRCULAR_REDIRECTS

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpClientParams ALLOW_CIRCULAR_REDIRECTS.

Prototype

String ALLOW_CIRCULAR_REDIRECTS

To view the source code for org.apache.commons.httpclient.params HttpClientParams ALLOW_CIRCULAR_REDIRECTS.

Click Source Link

Usage

From source file:com.simplifide.core.net.LicenseConnection.java

public void connect() {
    HttpClientParams params = new HttpClientParams();
    params.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
    params.setIntParameter(HttpClientParams.MAX_REDIRECTS, 4);

    HttpClient client = new HttpClient(params);
    client.getHttpConnectionManager().getParams().setConnectionTimeout(30000);

    GetMethod post = new GetMethod("http://simplifide.com/drupal/free_trial2");
    post.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

    /* NameValuePair[] data = {
        new NameValuePair("user_name", "joe"),
        new NameValuePair("password", "aaa"),
        new NameValuePair("name", "joker"),
        new NameValuePair("email", "beta"),
      };/*from   w  w w.  ja v  a  2 s .c  o  m*/
      post.setRequestBody(data);
      */
    try {
        int rettype = client.executeMethod(post);

        byte[] responseBody = post.getResponseBody();

        // Deal with the response.
        // Use caution: ensure correct character encoding and is not binary data
        String tstring = new String(responseBody);

    } catch (HttpException e) {

        HardwareLog.logError(e);
    } catch (IOException e) {

        HardwareLog.logError(e);
    } finally {
        post.releaseConnection();
    }

}

From source file:ch.ksfx.web.services.spidering.http.HttpClientHelper.java

/**
 * Creates a new Http Client Helper//from  w ww .jav a  2  s  .  c  o  m
 *
 * @param headers User-Agent HTTP headers sent by the request
 */
public HttpClientHelper(HttpUserAgentHeaders headers, int httpSocketTimeout, int retryCount, boolean torify) {
    this.torify = torify;
    this.httpClient = new HttpClient();
    this.httpClient.getParams().setSoTimeout(httpSocketTimeout);
    this.httpClient.setConnectionTimeout(httpSocketTimeout);
    this.httpClient.setHttpConnectionFactoryTimeout(httpSocketTimeout);

    httpClient.getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
    this.headers = headers;
    this.retryCount = retryCount;
}

From source file:com.jackbe.mapreduce.RESTClient.java

public RESTClient() {
    client = new HttpClient();
    client.getState().setCredentials(new AuthScope(host, Integer.parseInt(port)),
            new UsernamePasswordCredentials(user, password));

    HttpClientParams params = new HttpClientParams();
    params.setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, Boolean.TRUE);
    client.setParams(params);/*from  w  w w. j  a v a2 s  .co m*/
    client.getParams().setAuthenticationPreemptive(true);
    //throw new RuntimeException("TRYING TO CREATE EMMLRestRunner. BAD!");
}

From source file:de.mpg.escidoc.services.tools.scripts.person_grants.Util.java

/**
 * Queries an eSciDoc instance/*  w ww.j  ava2  s  .  c om*/
 * 
 * @param url
 * @param query
 * @param adminUserName
 * @param adminPassword
 * @param frameworkUrl
 * @return
 */
public static Document queryFramework(String url, String query, String adminUserName, String adminPassword,
        String frameworkUrl) {
    try {
        DocumentBuilder documentBuilder;
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactoryImpl.newInstance();
        documentBuilderFactory.setNamespaceAware(true);
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.newDocument();
        HttpClient client = new HttpClient();
        client.getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
        GetMethod getMethod = new GetMethod(url + "?query="
                + (query != null ? URLEncoder.encode(query, "UTF-8") : "") + "&eSciDocUserHandle="
                + Base64.encode(
                        getAdminUserHandle(adminUserName, adminPassword, frameworkUrl).getBytes("UTF-8")));
        System.out.println("Querying <" + url + "?query="
                + (query != null ? URLEncoder.encode(query, "UTF-8") : "") + "&eSciDocUserHandle="
                + Base64.encode(
                        getAdminUserHandle(adminUserName, adminPassword, frameworkUrl).getBytes("UTF-8")));
        client.executeMethod(getMethod);
        if (getMethod.getStatusCode() == 200) {
            document = documentBuilder.parse(getMethod.getResponseBodyAsStream());
        } else {
            System.out.println("Error querying: Status " + getMethod.getStatusCode() + "\n"
                    + getMethod.getResponseBodyAsString());
        }
        return document;
    } catch (Exception e) {
        try {
            System.out.println("Error querying Framework <" + url + "?query="
                    + (query != null ? URLEncoder.encode(query, "UTF-8") : "") + "&eSciDocUserHandle="
                    + Base64.encode(
                            getAdminUserHandle(adminUserName, adminPassword, frameworkUrl).getBytes("UTF-8"))
                    + ">");
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        e.printStackTrace();
    }
    return null;
}

From source file:com.jackbe.mapreduce.EMMLRestRunner.java

public EMMLRestRunner() {
    client = new HttpClient();
    client.getState().setCredentials(new AuthScope(host, Integer.parseInt(port)),
            new UsernamePasswordCredentials(user, password));

    HttpClientParams params = new HttpClientParams();
    params.setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, Boolean.TRUE);
    client.setParams(params);/*from   w ww .  jav  a2 s . c o m*/
    client.getParams().setAuthenticationPreemptive(true);
    throw new RuntimeException("TRYING TO CREATE EMMLRestRunner. BAD!");
}

From source file:com.orange.mmp.net.http.HttpConnectionManager.java

public Connection getConnection() throws MMPNetException {
    SimpleHttpConnectionManager shcm = new SimpleHttpConnectionManager();

    HttpClientParams defaultHttpParams = new HttpClientParams();
    defaultHttpParams.setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    defaultHttpParams.setParameter(HttpConnectionParams.TCP_NODELAY, true);
    defaultHttpParams.setParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false);
    defaultHttpParams.setParameter(HttpConnectionParams.SO_LINGER, 0);
    defaultHttpParams.setParameter(HttpClientParams.MAX_REDIRECTS, 3);
    defaultHttpParams.setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, false);

    HttpClient httpClient2 = new HttpClient(defaultHttpParams, shcm);

    if (HttpConnectionManager.proxyHost != null) {
        defaultHttpParams.setParameter("http.route.default-proxy",
                new HttpHost(HttpConnectionManager.proxyHost, HttpConnectionManager.proxyPort)); // TODO Host configuration !
        if (HttpConnectionManager.proxyHost != null/* && this.useProxy*/) {
            HostConfiguration config = new HostConfiguration();
            config.setProxy(HttpConnectionManager.proxyHost, HttpConnectionManager.proxyPort);
            httpClient2.setHostConfiguration(config);
        } else {/*w ww  . j  a  v  a 2 s. co m*/
            HostConfiguration config = new HostConfiguration();
            config.setProxyHost(null);
            httpClient2.setHostConfiguration(config);
        }
    }

    return new HttpConnection(httpClient2);
}

From source file:com.collabnet.tracker.common.httpClient.TrackerHttpSender.java

private static void setupHttpClientParams(HttpClient client, String userAgent) {
    client.getParams().setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
    client.getHttpConnectionManager().getParams().setSoTimeout(SOCKET_TIMEOUT);
    client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNNECT_TIMEOUT);
}

From source file:fr.unix_experience.owncloud_sms.engine.OCHttpClient.java

public OCHttpClient(Context context, Uri serverURI, String accountName, String accountPassword) {
    super(new MultiThreadedHttpConnectionManager());
    Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443);
    Protocol.registerProtocol("https", easyhttps);
    _serverURI = serverURI;//from   w ww.jav a 2  s  . c o  m
    _username = accountName;
    _password = accountPassword;
    getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
    getParams().setParameter(PARAM_PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    getParams().setParameter(HttpMethodParams.USER_AGENT,
            "nextcloud-phonesync (" + new AndroidVersionProvider(context).getVersionCode() + ")");
}

From source file:com.lp.client.frame.component.phone.HttpPhoneDialer.java

protected void prepareClient(HttpClient client, GetMethod method) {
    client.getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
}

From source file:io.hops.hopsworks.api.admin.YarnUIProxyServlet.java

@Override
protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
        throws ServletException, IOException {

    if (servletRequest.getUserPrincipal() == null) {
        servletResponse.sendError(403, "User is not logged in");
        return;//from   w  w  w .ja  va  2  s  . co m
    }
    if (!servletRequest.isUserInRole("HOPS_ADMIN")) {
        servletResponse.sendError(Response.Status.BAD_REQUEST.getStatusCode(),
                "You don't have the access right for this service");
        return;
    }
    if (servletRequest.getAttribute(ATTR_TARGET_URI) == null) {
        servletRequest.setAttribute(ATTR_TARGET_URI, targetUri);
    }
    if (servletRequest.getAttribute(ATTR_TARGET_HOST) == null) {
        servletRequest.setAttribute(ATTR_TARGET_HOST, targetHost);
    }

    // Make the Request
    // note: we won't transfer the protocol version because I'm not 
    // sure it would truly be compatible
    String proxyRequestUri = rewriteUrlFromRequest(servletRequest);

    try {
        // Execute the request

        HttpClientParams params = new HttpClientParams();
        params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
        params.setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
        HttpClient client = new HttpClient(params);
        HostConfiguration config = new HostConfiguration();
        InetAddress localAddress = InetAddress.getLocalHost();
        config.setLocalAddress(localAddress);

        String method = servletRequest.getMethod();
        HttpMethod m;
        if (method.equalsIgnoreCase("PUT")) {
            m = new PutMethod(proxyRequestUri);
            RequestEntity requestEntity = new InputStreamRequestEntity(servletRequest.getInputStream(),
                    servletRequest.getContentType());
            ((PutMethod) m).setRequestEntity(requestEntity);
        } else {
            m = new GetMethod(proxyRequestUri);
        }
        Enumeration<String> names = servletRequest.getHeaderNames();
        while (names.hasMoreElements()) {
            String headerName = names.nextElement();
            String value = servletRequest.getHeader(headerName);
            if (PASS_THROUGH_HEADERS.contains(headerName)) {
                //yarn does not send back the js if encoding is not accepted
                //but we don't want to accept encoding for the html because we
                //need to be able to parse it
                if (headerName.equalsIgnoreCase("accept-encoding") && (servletRequest.getPathInfo() == null
                        || !servletRequest.getPathInfo().contains(".js"))) {
                    continue;
                } else {
                    m.setRequestHeader(headerName, value);
                }
            }
        }
        String user = servletRequest.getRemoteUser();
        if (user != null && !user.isEmpty()) {
            m.setRequestHeader("Cookie", "proxy-user" + "=" + URLEncoder.encode(user, "ASCII"));
        }

        client.executeMethod(config, m);

        // Process the response
        int statusCode = m.getStatusCode();

        // Pass the response code. This method with the "reason phrase" is 
        //deprecated but it's the only way to pass the reason along too.
        //noinspection deprecation
        servletResponse.setStatus(statusCode, m.getStatusLine().getReasonPhrase());

        copyResponseHeaders(m, servletRequest, servletResponse);

        // Send the content to the client
        copyResponseEntity(m, servletResponse);

    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        if (e instanceof ServletException) {
            throw (ServletException) e;
        }
        //noinspection ConstantConditions
        if (e instanceof IOException) {
            throw (IOException) e;
        }
        throw new RuntimeException(e);

    }
}