Example usage for org.apache.commons.httpclient HttpClient HttpClient

List of usage examples for org.apache.commons.httpclient HttpClient HttpClient

Introduction

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

Prototype

public HttpClient() 

Source Link

Usage

From source file:com.bigrocksoftware.metarparser.MetarFetcher.java

public static String fetch(String station, int timeout) {
    metarData = null;//from w w  w.j  av  a2s .  c om

    // create the http client
    HttpClient client = new HttpClient();

    // set the timeout is specified
    if (timeout != 0) {
        log.debug("MetarFetch: setting timeout to '" + timeout + "' milliseconds");
        long start = System.currentTimeMillis();
        client.setConnectionTimeout(timeout);
        long end = System.currentTimeMillis();
        if (end - start < timeout) {
            client.setTimeout((int) (end - start));
        } else {
            return null;
        }
    }

    // create the http method we will use
    HttpMethod method = new GetMethod(httpMetarURL + station + ".TXT");

    // connect to the NOAA site, retrying up to the specified num
    int statusCode = -1;
    //for (int attempt = 0; statusCode == -1 && attempt < 3; attempt++) {
    try {
        // execute the get method
        log.debug("MetarFetcher: downloading data for station '" + station + "'");
        statusCode = client.executeMethod(method);
    } catch (HttpRecoverableException e) {
        log.error("a recoverable exception occurred, " + "retrying." + e.getMessage());
    } catch (IOException e) {
        log.error("failed to download file: " + e);
    }
    //}

    // check that we didn't run out of retries
    if (statusCode != HttpStatus.SC_OK) {
        log.error("failed to download station data for '" + station + "'");
        return null;
    } else {
        // read the response body
        byte[] responseBody = method.getResponseBody();

        // release the connection
        method.releaseConnection();

        // deal with the response.
        // FIXME - ensure we use the correct character encoding here
        metarData = new String(responseBody) + "\n";
        log.debug("MetarFetcher: metar data: " + metarData);
    }

    return metarData;
}

From source file:com.braindrainpain.docker.HttpSupport.java

protected HttpClient getHttpClient() {
    HttpClient client = new HttpClient();

    client.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT,
            this.getSystemProperty("docker.repo.connection.timeout", 10 * 1000));

    client.getParams().setSoTimeout(this.getSystemProperty("docker.repo.socket.timeout", 5 * 60 * 1000));

    return client;
}

From source file:com.javector.soaj.deploy.invocation.TestInvocation.java

public void testInvocation() throws Exception {
    HttpClient client = new HttpClient();

    log.info("Entered TestInvocation.testInvocation.");
    //TODO factor out the hardcoded http address
    HttpMethod method = new GetMethod("http://localhost:8080/tester/test");
    System.out.println("HTTP GET response code: " + client.executeMethod(method));
    Header hdr = method.getResponseHeader("IntegrationTest_SoajEJB30Method");
    String response = "";
    if (hdr == null) {
        // check for exception
        hdr = method.getResponseHeader("IntegrationTest_SoajEJB30Method_Exception");
        throw new Exception(hdr.getValue());
    } else {//from  w ww .j  a va2s  .c om
        response = hdr.getValue();
    }
    assertEquals("Hello World", response);

}

From source file:com.autofrog.pandabot.client.PandoraBot.java

public PandoraBot(String botId) throws JAXBException {
    this.botId = botId;
    client = new HttpClient();
    jc = JAXBContext.newInstance(PandorabotResult.class);
    u = jc.createUnmarshaller();//from  www  . j  a v  a2s.c om
}

From source file:com.sun.syndication.propono.atom.client.GDataAuthStrategy.java

private void init() throws ProponoException {
    try {// w ww  .  j  ava  2  s .com
        HttpClient httpClient = new HttpClient();
        PostMethod method = new PostMethod("https://www.google.com/accounts/ClientLogin");
        NameValuePair[] data = { new NameValuePair("Email", email), new NameValuePair("Passwd", password),
                new NameValuePair("accountType", "GOOGLE"), new NameValuePair("service", service),
                new NameValuePair("source", "ROME Propono Atompub Client") };
        method.setRequestBody(data);
        httpClient.executeMethod(method);

        String responseBody = method.getResponseBodyAsString();
        int authIndex = responseBody.indexOf("Auth=");

        authToken = "GoogleLogin auth=" + responseBody.trim().substring(authIndex + 5);

    } catch (Throwable t) {
        t.printStackTrace();
        throw new ProponoException("ERROR obtaining Google authentication string", t);
    }
}

From source file:eu.flatworld.worldexplorer.layer.bmng.BMNGHTTPProvider.java

public BMNGHTTPProvider() {
    LogX.log(Level.INFO, NAME + " starting");
    client = new HttpClient();
    Thread queueRunner = new Thread(this, this.getClass().getName() + "_queueRunner");
    queueRunner.setDaemon(true);//from  w ww .  j a  v  a2  s .  com
    queueRunner.start();
}

From source file:com.predic8.membrane.core.interceptor.cbr.XPathCBRInterceptorIntegrationTest.java

@Test
public void testRouting() throws Exception {
    PostMethod post = createPostMethod();
    HttpClient httpClient = new HttpClient();
    httpClient.executeMethod(post);/*ww  w  .  j ava 2s . c  om*/
    System.out.println(post.getResponseBodyAsString());
    httpClient.getHttpConnectionManager().closeIdleConnections(0);
}

From source file:it.pronetics.madstore.crawler.downloader.impl.DownloaderImpl.java

public Page download(Link link) {
    String url = link.getLink();//  ww  w.j a va2  s.  c o  m
    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(url);
    try {
        LOG.info("Downloading page from: {}", url);
        int status = client.executeMethod(method);
        if (status == HttpStatus.SC_OK) {
            String data = method.getResponseBodyAsString();
            return new Page(link, data);
        } else {
            return new Page(link);
        }
    } catch (Exception e) {
        LOG.warn("Download failed: {}", url);
        LOG.warn(e.getMessage());
        LOG.debug(e.getMessage(), e);
        return new Page(link);
    } finally {
        method.releaseConnection();
    }
}

From source file:com.intellij.internal.statistic.connect.StatisticsHttpClientSender.java

@Override
public void send(@NotNull String url, @NotNull String content) throws StatServiceException {
    PostMethod post = null;/*ww w. ja va 2s.  co  m*/

    try {
        //HttpConfigurable.getInstance().prepareURL(url);

        HttpClient httpclient = new HttpClient();
        post = new PostMethod(url);

        post.setRequestBody(
                new NameValuePair[] { new NameValuePair("content", content), new NameValuePair("uuid",
                        UpdateChecker.getInstallationUID(PropertiesComponent.getInstance())) });

        httpclient.executeMethod(post);

        if (post.getStatusCode() != HttpStatus.SC_OK) {
            throw new StatServiceException("Error during data sending... Code: " + post.getStatusCode());
        }

        final Header errors = post.getResponseHeader("errors");
        if (errors != null) {
            final String value = errors.getValue();

            throw new StatServiceException("Error during updating statistics "
                    + (!StringUtil.isEmptyOrSpaces(value) ? " : " + value : ""));
        }
    } catch (StatServiceException e) {
        throw e;
    } catch (Exception e) {
        throw new StatServiceException("Error during data sending...", e);
    } finally {
        if (post != null) {
            post.releaseConnection();
        }
    }
}

From source file:com.rometools.propono.atom.client.GDataAuthStrategy.java

private void init() throws ProponoException {
    try {//from w w w. j a v  a 2 s.  c om
        final HttpClient httpClient = new HttpClient();
        final PostMethod method = new PostMethod("https://www.google.com/accounts/ClientLogin");
        final NameValuePair[] data = { new NameValuePair("Email", email), new NameValuePair("Passwd", password),
                new NameValuePair("accountType", "GOOGLE"), new NameValuePair("service", service),
                new NameValuePair("source", "ROME Propono Atompub Client") };
        method.setRequestBody(data);
        httpClient.executeMethod(method);

        final String responseBody = method.getResponseBodyAsString();
        final int authIndex = responseBody.indexOf("Auth=");

        authToken = "GoogleLogin auth=" + responseBody.trim().substring(authIndex + 5);

    } catch (final Throwable t) {
        t.printStackTrace();
        throw new ProponoException("ERROR obtaining Google authentication string", t);
    }
}