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

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

Introduction

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

Prototype

public GetMethod(String uri) 

Source Link

Usage

From source file:com.silverpeas.ical.FeedUtilities.java

public static final byte[] loadFeed(String feedURL, String username, String password) throws Exception {
    // Load feed//from   w w  w.  j a va  2  s.c o  m
    GetMethod get = new GetMethod(feedURL);
    get.addRequestHeader("User-Agent", USER_AGENT);
    get.setFollowRedirects(true);
    SilverTrace.info("agenda", "FeedUtilities.loadFeed()", "root.MSG_GEN_PARAM_VALUE",
            "username=" + username + " - pwd=" + password);
    if (StringUtil.isDefined(username)) {
        // Set username/password
        byte[] auth = StringUtils.encodeString(username + ':' + StringUtils.decodePassword(password),
                Charsets.UTF_8);
        get.addRequestHeader("Authorization", "Basic " + StringUtils.encodeBASE64(auth));

    }
    byte[] bytes = null;
    for (int tries = 0; tries < 5; tries++) {
        try {
            int status = httpClient.executeMethod(get);
            SilverTrace.warn("agenda", "FeedUtilities.loadFeed()", "Http connection status : " + status);
            if (status == REMOTE_CALENDAR_RETURNCODE_OK) {
                bytes = get.getResponseBody();
                SilverTrace.info("agenda", "FeedUtilities.loadFeed()", "agenda.FEED_LOADING_SUCCESSFULLY",
                        bytes.length + " bytes.");
            } else {
                SilverTrace.warn("agenda", "FeedUtilities.loadFeed()", "agenda.FEED_LOADING_FAILED",
                        "Status Http Client=" + status + " Content=" + Arrays.toString(bytes));
                bytes = null;
            }
        } catch (Exception loadError) {
            SilverTrace.warn("agenda", "FeedUtilities.loadFeed()", "Attempt #" + tries + " Status=",
                    loadError.getMessage());
            if (tries == 5) {
                bytes = null;
                SilverTrace.warn("agenda", "FeedUtilities.loadFeed()", "agenda.CONNECTIONS_REFUSED",
                        loadError.getMessage());
            }
            Thread.sleep(FEED_RETRY_MILLIS);
        } finally {
            get.releaseConnection();
        }
    }
    return bytes;
}

From source file:com.kagilum.intellij.icescrum.IceScrumRepository.java

@Override
public Task[] getIssues(@Nullable String s, int i, long l) throws Exception {
    String url = createCompleteUrl();
    GetMethod method = new GetMethod(url);
    configureHttpMethod(method);/*from  www.  java  2 s .  c  o  m*/
    method.setRequestHeader("Content-type", "text/json");

    getHttpClient().executeMethod(method);
    int code = method.getStatusCode();
    if (code != HttpStatus.SC_OK) {
        checkServerStatus(code);
    }

    JsonElement json = new JsonParser().parse(method.getResponseBodyAsString());
    JsonArray array = json.getAsJsonArray();
    Iterator iterator = array.iterator();
    List<Task> tasks = new ArrayList<Task>();
    while (iterator.hasNext()) {
        JsonObject element = (JsonObject) iterator.next();
        IceScrumTask task = new IceScrumTask(element, this.serverUrl, this.pkey);
        tasks.add(task);
    }
    return tasks.toArray(new Task[] {});
}

From source file:com.google.wave.api.robot.HttpRobotConnection.java

@Override
public String get(String url) throws RobotConnectionException {
    GetMethod method = new GetMethod(url);
    return fetch(url, method);
}

From source file:com.cerema.cloud2.lib.resources.shares.GetRemoteShareOperation.java

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    int status = -1;

    // Get Method        
    GetMethod get = null;//ww  w  .  java  2 s . com

    // Get the response
    try {
        get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH + "/" + Long.toString(mRemoteId));
        get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

        status = client.executeMethod(get);

        if (isSuccess(status)) {
            String response = get.getResponseBodyAsString();

            // Parse xml response and obtain the list of shares
            ShareToRemoteOperationResultParser parser = new ShareToRemoteOperationResultParser(
                    new ShareXMLParser());
            parser.setOneOrMoreSharesRequired(true);
            parser.setOwnCloudVersion(client.getOwnCloudVersion());
            parser.setServerBaseUri(client.getBaseUri());
            result = parser.parse(response);

        } else {
            result = new RemoteOperationResult(false, status, get.getResponseHeaders());
        }

    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Exception while getting remote shares ", e);

    } finally {
        if (get != null) {
            get.releaseConnection();
        }
    }
    return result;
}

From source file:com.eucalyptus.imaging.manifest.ImportImageManifest.java

@Override
public String getManifest(String location) throws EucalyptusCloudException {
    HttpClient client = new HttpClient();
    client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
    GetMethod method = new GetMethod(location);
    String s = null;/*from w w  w . j a  v  a 2 s.c o m*/
    try {
        client.executeMethod(method);
        s = method.getResponseBodyAsString();
        if (s == null) {
            throw new EucalyptusCloudException("Can't download manifest from " + location + " content is null");
        }
    } catch (IOException ex) {
        throw new EucalyptusCloudException("Can't download manifest from " + location, ex);
    } finally {
        method.releaseConnection();
    }
    return s;
}

From source file:com.predic8.membrane.integration.ProxyRuleTest.java

@Test
public void testPost() throws Exception {
    HttpClient client = new HttpClient();
    GetMethod get = new GetMethod("https://predic8.com");
    assertEquals(200, client.executeMethod(get));
}

From source file:net.neurowork.cenatic.centraldir.workers.xml.CapacidadXmlImporter.java

public Capacidad buscarCapacidad(int capacityCode) {
    HttpClient httpclient = XMLRestWorker.getHttpClient();
    GetMethod get = new GetMethod(restUrl.getCapacidadUrl());
    get.addRequestHeader("Accept", "application/xml");
    Capacidad ret = null;//from  w  ww.j  a v a2 s  .c om
    try {
        int result = httpclient.executeMethod(get);
        if (logger.isTraceEnabled())
            logger.trace("Response status code: " + result);
        String xmlString = get.getResponseBodyAsString();
        if (logger.isTraceEnabled())
            logger.trace("Response body: " + xmlString);

        ret = importCapacidad(xmlString, capacityCode);
    } catch (HttpException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    } catch (ParserConfigurationException e) {
        logger.error(e.getMessage());
    } catch (SAXException e) {
        logger.error(e.getMessage());
    } finally {
        get.releaseConnection();
    }
    return ret;
}

From source file:net.bioclipse.opentox.api.Dataset.java

@SuppressWarnings("serial")
public static List<String> getListOfAvailableDatasets(String service) throws IOException {
    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(service + "dataset");
    HttpMethodHelper.addMethodHeaders(method, new HashMap<String, String>() {
        {//from   w  w  w.ja v  a2  s  . c  o  m
            put("Accept", "text/uri-list");
        }
    });
    client.executeMethod(method);

    List<String> datasets = new ArrayList<String>();
    BufferedReader reader = new BufferedReader(new StringReader(method.getResponseBodyAsString()));
    String line;
    while ((line = reader.readLine()) != null) {
        line = line.trim();
        if (line.length() > 0)
            datasets.add(line);
    }
    reader.close();
    method.releaseConnection();
    return datasets;
}

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

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

    log.info("Entered InvocationTest_EJB21.");
    //TODO factor out the hardcoded http address
    HttpMethod method = new GetMethod("http://localhost:8080/tester/test/ejb21");
    System.out.println("HTTP GET response code: " + client.executeMethod(method));
    Header hdr = method.getResponseHeader("IntegrationTest_SoajEJB21Method");
    String response = "";
    if (hdr == null) {
        // check for exception
        hdr = method.getResponseHeader("IntegrationTest_SoajEJB21Method_Exception");
        throw new Exception(hdr.getValue());
    } else {/*from   w  w  w  .  ja  va  2  s  .c om*/
        response = hdr.getValue();
    }
    assertEquals("Hello World", response);

}

From source file:net.praqma.jenkins.rqm.request.RQMGetRequest.java

public RQMGetRequest(RQMHttpClient client, String url, NameValuePair[] parameters) {
    this.method = new GetMethod(url);
    method.addRequestHeader("Accept", "");
    method.addRequestHeader("Content-Type", "application/atom+xml");

    if (parameters != null) {
        method.setQueryString(parameters);
    }//  w  ww  .  j a v  a2s. c  o  m
    Header[] headers = method.getRequestHeaders();

    for (Header h : headers) {
        log.finest(String.format("[%s,%s]", h.getName(), h.getValue()));
    }

    this.client = client;
}