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

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

Introduction

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

Prototype

public HttpClientParams() 

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"),
      };//www .j  a v a  2s .  co 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:edu.northwestern.bioinformatics.studycalendar.security.plugin.cas.direct.DirectLoginHttpFacade.java

public DirectLoginHttpFacade(String loginUrl, String serviceUrl) {
    this.loginUrl = loginUrl;
    this.serviceUrl = serviceUrl;
    HttpClientParams params = new HttpClientParams();
    params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    this.httpClient = new HttpClient(params);
}

From source file:edu.unc.lib.dl.ui.util.FileIOUtil.java

public static String postImport(HttpServletRequest request, String url) {
    Map<String, String[]> parameters = request.getParameterMap();
    HttpClientParams params = new HttpClientParams();
    params.setContentCharset("UTF-8");
    HttpClient client = new HttpClient();
    client.setParams(params);/* www  .  j  av  a 2  s.c  o m*/

    PostMethod post = new PostMethod(url);
    Iterator<Entry<String, String[]>> parameterIt = parameters.entrySet().iterator();
    while (parameterIt.hasNext()) {
        Entry<String, String[]> parameter = parameterIt.next();
        for (String parameterValue : parameter.getValue()) {
            post.addParameter(parameter.getKey(), parameterValue);
        }
    }

    try {
        client.executeMethod(post);
        return post.getResponseBodyAsString();
    } catch (Exception e) {
        throw new ResourceNotFoundException("Failed to retrieve POST import request for " + url, e);
    } finally {
        post.releaseConnection();
    }
}

From source file:com.exalead.io.failover.FailoverHttpClient.java

public FailoverHttpClient() {
    manager = new MonitoredHttpConnectionManager();
    client = new HttpClient(manager);

    client.setParams(new HttpClientParams());
    manager.getParams().setStaleCheckingEnabled(false);
}

From source file:edu.unc.lib.dl.ui.service.DjatokaContentService.java

public void getMetadata(String simplepid, String datastream, OutputStream outStream,
        HttpServletResponse response, int retryServerError) {
    HttpClientParams params = new HttpClientParams();
    params.setContentCharset("UTF-8");
    HttpClient client = new HttpClient();
    client.setParams(params);/*from  w w w.  j a  v a 2  s. c  o  m*/

    StringBuilder path = new StringBuilder(applicationPathSettings.getDjatokaPath());
    path.append("resolver?url_ver=Z39.88-2004&rft_id=")
            .append(applicationPathSettings.getFedoraPathWithoutDefaultPort()).append("/objects/")
            .append(simplepid).append("/datastreams/").append(datastream).append("/content")
            .append("&svc_id=info:lanl-repo/svc/getMetadata");

    GetMethod method = new GetMethod(path.toString());
    try {
        client.executeMethod(method);
        if (method.getStatusCode() == HttpStatus.SC_OK) {
            if (response != null) {
                response.setHeader("Content-Type", "application/json");
                response.setHeader("content-disposition", "inline");

                FileIOUtil.stream(outStream, method);
            }
        } else {
            if ((method.getStatusCode() == 500 || method.getStatusCode() == 404) && retryServerError > 0) {
                this.getMetadata(simplepid, datastream, outStream, response, retryServerError - 1);
            } else {
                LOG.error("Unexpected failure: " + method.getStatusLine().toString());
                LOG.error("Path was: " + method.getURI().getURI());
            }
        }
    } catch (ClientAbortException e) {
        if (LOG.isDebugEnabled())
            LOG.debug("User client aborted request to stream jp2 metadata for " + simplepid, e);
    } catch (Exception e) {
        LOG.error("Problem retrieving metadata for " + path, e);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.discogs.api.webservice.impl.HttpClientWebService.java

private void initConfiguration() {
    HttpClientParams hcp = new HttpClientParams();
    hcp.setParameter(HttpClientParams.USER_AGENT, "Discogs Java Api v1.0");
    httpClient.setParams(hcp);/*  ww w .j ava2 s . c om*/
}

From source file:com.isencia.passerelle.model.util.RESTFacade.java

public RESTFacade(int connectionTimeout, int socketTimeout) {
    httpClient = new HttpClient();
    HttpClientParams params = new HttpClientParams();
    params.setSoTimeout(socketTimeout);/*from  w  ww  . ja v a 2 s  .  c om*/
    params.setConnectionManagerTimeout(connectionTimeout);
    httpClient.setParams(params);
}

From source file:com.thoughtworks.go.remote.work.RemoteConsoleAppender.java

public void append(String content) throws IOException {
    PutMethod putMethod = new PutMethod(consoleUri);
    try {/*from  ww  w .jav a2s .c  om*/
        HttpClient httpClient = httpService.httpClient();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Appending console to URL -> " + consoleUri);
        }
        putMethod.setRequestEntity(new StringRequestEntity(content));

        HttpClientParams clientParams = new HttpClientParams();
        clientParams.setParameter("agentId", agentIdentifier.getUuid());
        HttpService.setSizeHeader(putMethod, content.getBytes().length);
        putMethod.setParams(clientParams);
        httpClient.executeMethod(putMethod);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Got " + putMethod.getStatusCode());
        }
    } finally {
        putMethod.releaseConnection();
    }
}

From source file:com.sun.syndication.fetcher.impl.HttpClientFeedFetcher.java

public HttpClientFeedFetcher() {
    super();
    setHttpClientParams(new HttpClientParams());
}

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  ww. j a v a2s.  c o m*/
    client.getParams().setAuthenticationPreemptive(true);
    //throw new RuntimeException("TRYING TO CREATE EMMLRestRunner. BAD!");
}