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:it.geosolutions.httpproxy.utils.ProxyMethodConfig.java

/**
 * Obtain he method generation with {@link ProxyMethodConfig#method} and {@link ProxyMethodConfig#url}
 * /*from   www  .  ja v  a 2  s. c  o m*/
 * @return HttpMethod only supports {DELETE, GET, POST and PUT} @see {@link HttpMethods}
 */
public HttpMethod getMethod() {
    if (HttpMethods.METHOD_DELETE.equals(method)) {
        return new DeleteMethod(url.toExternalForm());
    } else if (HttpMethods.METHOD_GET.equals(method)) {
        return new GetMethod(url.toExternalForm());
    } else if (HttpMethods.METHOD_POST.equals(method)) {
        return new PostMethod(url.toExternalForm());
    } else if (HttpMethods.METHOD_PUT.equals(method)) {
        return new PutMethod(url.toExternalForm());
    } else {
        // Default is doGet
        return new GetMethod(url.toExternalForm());
    }
}

From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java

public static HTTPResponse get(URL url, String username, String password, long timeout, int maxRedirect,
        String charset, String useragent, ProxyData proxy, Header[] headers) throws IOException {
    return _invoke(new GetMethod(url.toExternalForm()), url, username, password, timeout, maxRedirect, charset,
            useragent, proxy, headers, null, null);
}

From source file:net.sf.ehcache.constructs.web.filter.SpeedTest.java

/**
 * Time to get 200 Cached Pages/*from   w w  w  .  j  av a 2s.  co  m*/
 * StopWatch time: 1021ms
 */
public void testSpeedHttpClientCached() throws IOException {
    StopWatch stopWatch = new StopWatch();
    String url = "http://localhost:9080/CachedPage.jsp";
    HttpClient httpClient = new HttpClient();
    HttpMethod httpMethod = new GetMethod(url);
    stopWatch.getElapsedTime();
    for (int i = 0; i < 200; i++) {
        httpClient.executeMethod(httpMethod);
        httpMethod.getResponseBodyAsStream();
    }
    long time = stopWatch.getElapsedTime();
    LOG.info("Time for 200 cached page requests: " + time);
}

From source file:edu.berkeley.ground.plugins.hive.util.PluginUtil.java

public static List<Long> getLatestVersions(String name, String type) throws GroundException {
    GetMethod get = new GetMethod(groundServerAddress + type + "/" + name + "/latest");
    try {//ww  w . j ava 2  s .c o  m
        return (List<Long>) getVersionList(get);
    } catch (IOException e) {
        throw new GroundException(e);
    }
}

From source file:edu.du.penrose.systems.fedoraApp.tests.sendEctdRestResults.java

public void testRun() {

    try {/*w  w  w  .j av  a2  s  . c  om*/
        HttpClient client = new HttpClient();
        client.getParams().setParameter("http.useragent", "fedoraProxy Client");

        final String HOST = "130.253.33.105";
        final String PORT = "8085";
        final String CMD = "/library/updatePid";
        final String KEY = "6b476c7e50726949347162353c7e3d7271336e6f3e3e4c2d703d762d24";

        String objid = "du_174_1793_primary_1999_kelly";
        String pid = "178";

        StringBuffer ectdResultsUrl = new StringBuffer("http://");
        ectdResultsUrl.append(HOST);
        ectdResultsUrl.append(":");
        ectdResultsUrl.append(PORT);
        ectdResultsUrl.append(CMD);

        GetMethod method = new GetMethod(ectdResultsUrl.toString());
        HttpMethodParams params = new HttpClientParams();
        params.setParameter("id", objid);
        params.setParameter("pid", pid);

        method.setParams(params);

        try {
            int returnCode = client.executeMethod(method);

            if (returnCode != HttpStatus.SC_OK) {
                System.err.println("ERROR");
            }
        } catch (Exception e) {
            System.err.println(e);
        } finally {
            method.releaseConnection();
        }

    } catch (Exception e) {
        System.out.println("Exception: " + e.getMessage());
    }

}

From source file:de.ingrid.mdek.quartz.jobs.util.URLValidator.java

public URLState call() {
    log.debug("checking url: " + urlState.getUrl());
    String url = urlState.getUrl() + urlState.getAdditionalParams();

    GetMethod getMethod = null;//from   w  w w.  j  a v a  2s .  c o m
    long startTime = System.currentTimeMillis();
    try {
        getMethod = new GetMethod(url);
        int responseCode = httpClient.executeMethod(getMethod);
        urlState.setResponseCode(responseCode);

        if (HttpURLConnection.HTTP_OK == responseCode) {
            urlState.setState(State.VALID);
            // get content for further analysis if page is ok
            // -> getResponseBodyAsString-method can easily lead to OOM!!!
            // responseString = getMethod.getResponseBodyAsString();
            Reader reader = new InputStreamReader(getMethod.getResponseBodyAsStream(),
                    getMethod.getResponseCharSet());
            // consume the response entity
            responseString = getStringFromInputStream(reader, 10);
        } else {
            urlState.setState(State.HTTP_ERROR);
        }

    } catch (HTTPException ex) {
        urlState.setState(State.HTTP_ERROR);

    } catch (ConnectException ex) {
        urlState.setState(State.CONNECT_REFUSED);

    } catch (ConnectTimeoutException ex) {
        urlState.setState(State.CONNECT_TIMEOUT);

    } catch (SocketTimeoutException ex) {
        urlState.setState(State.SOCKET_TIMEOUT);

    } catch (UnknownHostException ex) {
        urlState.setState(State.UNKNOWN_HOST);

    } catch (IOException ex) {
        urlState.setState(State.HTTP_ERROR);

    } catch (IllegalArgumentException ex) {
        urlState.setState(State.MALFORMED_URL);

    } catch (Exception ex) {
        urlState.setState(State.HTTP_ERROR);

    } finally {
        if (getMethod != null) {
            getMethod.releaseConnection();
        }
    }

    long endTime = System.currentTimeMillis();
    log.debug("done after " + (endTime - startTime) + "ms: " + urlState.getUrl());
    log.debug("returning: " + urlState.getState() + "(" + urlState.getResponseCode() + ")");
    return urlState;
}

From source file:com.npower.dm.msm.tools.PackageCheckerImpl.java

public PackageMetaInfo getPackageMetaInfo(String url) throws DMException {
    HttpClient client = new HttpClient();
    HttpMethod method = new GetMethod(url);
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            new DefaultHttpMethodRetryHandler(3, false));

    PackageMetaInfo metaInfo = new PackageMetaInfo();
    metaInfo.setUrl(url);//ww  w.  ja  v a 2 s  .  c  om
    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);
        metaInfo.setServerStatus(statusCode);
        if (statusCode != HttpStatus.SC_OK) {
            // System.err.println("Method failed: " + method.getStatusLine());
        }

        // Read the response body.
        byte[] responseBody = method.getResponseBody();
        System.out.println(new String(responseBody));

        Header mimeType = method.getResponseHeader("Content-Type");
        if (mimeType != null) {
            metaInfo.setMimeType(mimeType.getValue());
        }

        Header contentLength = method.getResponseHeader("Content-Length");
        if (contentLength != null && StringUtils.isNotEmpty(contentLength.getValue())) {
            metaInfo.setSize(Integer.parseInt(contentLength.getValue()));
        }

    } catch (HttpException e) {
        metaInfo.setErrorMessage(e.getMessage());
    } catch (IOException e) {
        metaInfo.setErrorMessage(e.getMessage());
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
    return metaInfo;
}

From source file:com.honnix.cheater.network.CheaterHttpClient.java

private boolean execute(HttpMethod method) {
    boolean result = true;

    try {/* ww w . j  a v a  2s.c o m*/
        httpClient.executeMethod(method);

        // We only follow the redirection once.
        Header locationHeader = method.getResponseHeader("location");

        if (locationHeader != null) {
            HttpMethod getMethod = new GetMethod(locationHeader.getValue());

            httpClient.executeMethod(getMethod);
        }
    } catch (Exception e) {
        LOG.error("Method execution error.", e);

        result = false;
    }

    return result;
}

From source file:com.owncloud.android.lib.resources.users.GetPublicKeyOperation.java

/**
 * @param client Client object//from  w ww.  j  a  va2  s  .  co  m
 */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    GetMethod getMethod = null;
    RemoteOperationResult result;

    try {
        // remote request
        getMethod = new GetMethod(client.getBaseUri() + PUBLIC_KEY_URL + JSON_FORMAT);
        getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

        int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);

        if (status == HttpStatus.SC_OK) {
            String response = getMethod.getResponseBodyAsString();

            // Parse the response
            JSONObject respJSON = new JSONObject(response);
            String key = (String) respJSON.getJSONObject(NODE_OCS).getJSONObject(NODE_DATA)
                    .getJSONObject(NODE_PUBLIC_KEYS).get(userID);

            result = new RemoteOperationResult(true, getMethod);
            ArrayList<Object> keys = new ArrayList<>();
            keys.add(key);
            result.setData(keys);
        } else {
            result = new RemoteOperationResult(false, getMethod);
            client.exhaustResponse(getMethod.getResponseBodyAsStream());
        }
    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log_OC.e(TAG, "Fetching of public key failed: " + result.getLogMessage(), result.getException());
    } finally {
        if (getMethod != null)
            getMethod.releaseConnection();
    }
    return result;
}

From source file:com.springsource.insight.plugin.apache.http.hc3.HttpPlaceholderMethodTest.java

@Test
public void testResolveHttpMethodOnExistingMethod() {
    HttpMethod method = new GetMethod("http://localhost");
    assertSame(method,//w w w.j a  v  a  2s  .  c  o  m
            HttpPlaceholderMethod.resolveHttpMethod("1234", method, Long.valueOf(System.currentTimeMillis())));
}