Example usage for org.apache.http.client.methods HttpGet HttpGet

List of usage examples for org.apache.http.client.methods HttpGet HttpGet

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpGet HttpGet.

Prototype

public HttpGet(final String uri) 

Source Link

Usage

From source file:com.mvn.aircraft.ApiTest.java

@Test
public static void testMimeType(String restURL, String expectedMimeType)
        throws ClientProtocolException, IOException {

    HttpUriRequest request = new HttpGet(restURL);
    HttpResponse httpResponse = (HttpResponse) HttpClientBuilder.create().build().execute(request);

    Assert.assertEquals(expectedMimeType,
            ContentType.getOrDefault((HttpEntity) httpResponse.getStatus()).getMimeType());
}

From source file:org.opencastproject.remotetest.server.resource.AdminResources.java

public static HttpResponse recordingsCapturing(TrustedHttpClient client) {
    return client.execute(new HttpGet(getServiceUrl() + "recordings/capturing"));
}

From source file:com.ecofactor.qa.automation.util.HttpUtil.java

/**
 * Gets the./*from w  ww .  j av a 2 s. com*/
 * @param url the url
 * @return the http response
 */
public static String get(String url, Map<String, String> params, int expectedStatus) {

    String content = null;
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);
    URIBuilder builder = new URIBuilder(request.getURI());

    Set<String> keys = params.keySet();
    for (String key : keys) {
        builder.addParameter(key, params.get(key));
    }

    HttpResponse response = null;
    try {
        request.setURI(builder.build());
        DriverConfig.setLogString("URL " + request.getURI().toString(), true);
        response = httpClient.execute(request);
        content = IOUtils.toString(response.getEntity().getContent());
        DriverConfig.setLogString("Content " + content, true);
        Assert.assertEquals(response.getStatusLine().getStatusCode(), expectedStatus);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        request.releaseConnection();
    }

    return content;
}

From source file:org.android.CPForAndroidPlusPlus.HttpClient.java

public static String makeRequest(String path) throws Exception {
    final String TAG = "HttpClient"; //Used in logging etc.
    String str = "";

    try {//from ww  w  .j ava  2s . co  m
        DefaultHttpClient httpclient = new DefaultHttpClient();
        //HttpParams params = new BasicHttpParams();
        //params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 1000L);
        //httpclient.setParams(params);
        HttpGet httpost = new HttpGet(path);

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        str = (String) httpclient.execute(httpost, responseHandler);
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }
    return str;
}

From source file:server.web.HttpRequestHelper.java

public static String sendingStartKillRequest(String url, String command) throws IOException {
    String sendingUrl = "http://" + url;

    HttpGet request = new HttpGet(sendingUrl);
    request.addHeader(VMCommand.COMMAND, command);

    log.info("Sending 'GET' request (command = " + command + ") to URL : " + sendingUrl);

    return send(request);
}

From source file:eu.musesproject.windowsclient.contextmonitoring.sensors.RESTController.java

public static Map<String, String> requestSensorInfo(String sensorType) throws IOException {
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet("http://localhost:9000/api/" + sensorType);
    HttpResponse response = client.execute(request);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String responseData = "";
    Gson gson = new Gson();
    //ToDo:check for readLine function
    responseData = rd.readLine();/*from   w  w  w .  j  a va 2  s.  c  om*/

    return gson.fromJson(responseData, new HashMap<String, String>().getClass());
}

From source file:org.mobile.mpos.util.HttpClientHelper.java

/**
 * get request/*from   ww w.j  a v  a 2  s .c om*/
 * @param uri
 * @return
 */
public static String get(String uri) {
    CloseableHttpClient httpClient = HttpClients.createDefault();
    try {
        HttpGet httpget = new HttpGet(uri);
        log.info("Executing request " + httpget.getRequestLine());
        // Create a custom response handler
        ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
            public String handleResponse(final HttpResponse response)
                    throws ClientProtocolException, IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= 200 && status < 300) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity) : null;
                } else {
                    throw new ClientProtocolException("Unexpected response status: " + status);
                }
            }
        };
        String responseBody = httpClient.execute(httpget, responseHandler);
        log.info(" response " + responseBody);
        return responseBody;
    } catch (ClientProtocolException e) {
        log.error("ClientProtocolException " + e.getMessage());
    } catch (IOException e) {
        log.error("IOException " + e.getMessage());
    } finally {
        close(httpClient);
    }
    return null;
}

From source file:com.buddycloud.friendfinder.HttpUtils.java

public static JsonElement consumeJSON(String URL) throws Exception {
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(URL);
    HttpResponse httpResponse = client.execute(httpGet);

    JsonElement parse = new JsonParser()
            .parse(new JsonReader(new InputStreamReader(httpResponse.getEntity().getContent())));

    return parse;
}

From source file:org.outburstframework.test.util.http.HTTPUtils.java

/**
 * Makes a HTTP Get request./*  w w  w .  java  2 s . co m*/
 * 
 * @param url
  *          The URL fo the page you would like to return
 * @return The body of the HTTP request
 * @throws HTTPException
  *              The was a problem making the request
 * @throws InvalidResponseException
 *             The Response HTTP Status was not 200 OK
 */
public static String HTTPGet(String url) throws InvalidResponseException, HTTPException {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);

    HttpResponse response;
    try {
        response = httpclient.execute(httpget);
    } catch (Exception e) {
        throw new HTTPException(e.getMessage(), e);
    }

    if (response.getStatusLine().toString().indexOf("200 OK") == -1) {
        throw new InvalidResponseException("Invalid status: " + response.getStatusLine());
    }

    try {
        return EntityUtils.toString(response.getEntity());
    } catch (Exception e) {
        throw new HTTPException(e.getMessage(), e);
    }
}

From source file:neembuu.release1.httpclient.utils.NHttpClientUtils.java

/**
 * Calculate the length/*from   www  .  java  2 s  . com*/
 * @param url
 * @param httpClient
 * @return the length
 */
public static long calculateLength(String url, DefaultHttpClient httpClient) {
    try {
        //DefaultHttpClient httpClient = NHttpClient.getInstance();
        HttpGet httpGet = new HttpGet(url);
        HttpResponse response = httpClient.execute(httpGet);
        long length = response.getEntity().getContentLength();
        System.out.println("Length: " + length);
        httpGet.abort();
        return length;
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return -1;
}