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:org.opencastproject.remotetest.server.resource.AdminResources.java

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

From source file:no.kantega.kwashc.server.test.HttpClientUtil.java

static String getPageText(String address) throws IOException {
    HttpClient httpclient = getHttpClient();
    HttpGet request = new HttpGet(address);
    return httpclient.execute(request, new BasicResponseHandler());
}

From source file:brokerja.Worker.java

public static Document getDoc(String root) {

    HttpClient client = new DefaultHttpClient();
    Document doc = null;// w w w  .j  a v  a  2s. co m
    try {
        while (doc == null) {
            HttpGet request = new HttpGet(root);

            request.setHeader("User-Agent", USER_AGENT);
            request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            request.setHeader("Accept-Language", "en-US,en;q=0.5");
            HttpResponse response = client.execute(request);
            //
            //                System.out.println("Response Code : "
            //                        + response.getStatusLine().getStatusCode());

            BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

            StringBuffer result = new StringBuffer();
            String line = "";
            while ((line = rd.readLine()) != null) {
                result.append(line);
            }
            doc = Jsoup.parse(result.toString());
        }
    } catch (SocketTimeoutException e) {
        //ERROR TYPE 1
        System.out.println("Socket Timeout Error");
        System.out.println(e);
        System.exit(0);
    } catch (SocketException e) {
        //ERROR TYPE 1
        System.out.println("Internet Connection Error");
        System.out.println(e);
        System.exit(0);
    } catch (Exception e) {
        //ERROR TYPE 2
        System.out.println("JSoup Error");
        System.out.println(e);
        System.exit(0);
    }
    return doc;
}

From source file:com.cyanogenmod.lockclock.weather.HttpRetriever.java

public static String retrieve(String url) {
    HttpGet request = new HttpGet(url);
    try {//from   ww  w.j  av a  2 s .co  m
        HttpResponse response = new DefaultHttpClient().execute(request);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            return EntityUtils.toString(entity);
        }
    } catch (IOException e) {
        Log.e(TAG, "Couldn't retrieve data", e);
    }
    return null;
}

From source file:com.mmd.mssp.util.HttpUtil.java

public static String httpGet(String uri) throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(uri);
    HttpResponse response = httpclient.execute(httpget);

    logger.info(httpget.getURI().toString() + " == " + response.getStatusLine());

    HttpEntity entity = response.getEntity();
    Header[] cts = response.getHeaders("Content-Type");
    String charset = "UTF-8";
    if (cts.length > 0) {
        String ContentType = cts[0].getValue();
        if (ContentType.contains("charset")) {
            charset = ContentType.split("charset=")[1];
        }//from   w w w . j  ava2 s. c  o m
    }
    if (entity != null) {
        InputStream instream = entity.getContent();
        try {
            StringBuffer buffer = new StringBuffer();
            char[] chars = new char[BUFFER_SIZE];
            while (true) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(instream, charset));
                int len = reader.read(chars);
                if (len < 0) {
                    break;
                }
                buffer.append(chars, 0, len);
            }
            return buffer.toString();
        } catch (IOException ex) {
            throw ex;
        } catch (RuntimeException ex) {
            httpget.abort();
            throw ex;
        } finally {
            instream.close();
            httpclient.getConnectionManager().shutdown();
        }
    }
    return "";
}

From source file:net.GoTicketing.GetNecessaryCookie.java

public static void getCookie(String host, String referer, String target, Map<String, String> cookieMap) {

    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        HttpGet httpGet = new HttpGet(host + target);
        httpGet.setConfig(DEFAULT_PARAMS);

        String cookies = CookieMapToString(cookieMap);
        if (!cookies.equals(""))
            httpGet.setHeader("Cookie", cookies);

        httpGet.setHeader("Referer", host + referer);

        try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {

            //  HttpStatusCode != 200 && != 404
            if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK
                    && httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_NOT_FOUND) {
                String ErrorCode = "Response Status : " + httpResponse.getStatusLine().getStatusCode();
                throw new IOException(ErrorCode);
            }//from w  ww  .  j  ava2 s .com

            try (BufferedInputStream buff = new BufferedInputStream(httpResponse.getEntity().getContent())) {
                String hstr;
                for (Header header : httpResponse.getHeaders("Set-Cookie")) {
                    hstr = header.getValue().split(";")[0];
                    cookieMap.put(hstr.split("=", 2)[0], hstr.split("=", 2)[1]);
                }
            }
        }
    } catch (IOException ex) {
        logger.log(Level.WARNING, "Get cookie from {0} failed in exception : {1}", new Object[] { target, ex });
    }
}

From source file:com.cdhxqh.travel_ticket_app.weather.HttpRetriever.java

public static String retrieve(String url) {
    HttpGet request = new HttpGet(url);
    try {/*from www .j  a v a2  s.co m*/
        HttpResponse response = new DefaultHttpClient().execute(request);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            return EntityUtils.toString(entity);
        }
    } catch (IOException e) {
        Log.e(TAG, "Couldn't retrieve data from url " + url, e);
    }
    return null;
}

From source file:com.mehmetakiftutuncu.eshotroid.utilities.Request.java

public static String get(String url) {
    try {//  ww w.j  a  va2  s.c  o m
        Log.info(Request.class, "Making GET request to url: " + url);

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);

        HttpResponse httpResponse = httpClient.execute(httpGet);

        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            Log.error(Request.class,
                    "GET request failed, invalid status code! status code: " + statusCode + ", url: " + url);
            return null;
        } else {
            HttpEntity httpEntity = httpResponse.getEntity();
            String result = EntityUtils.toString(httpEntity, "UTF-8");

            Log.info(Request.class, "GET result from url: " + url);
            Log.info(Request.class, result);

            return result;
        }
    } catch (Exception e) {
        Log.error(Request.class, "GET request failed! url: " + url, e);
        return null;
    }
}

From source file:com.devdungeon.httpexamples.HttpGetExample.java

private static String get(String url) {
    HttpClient client = new DefaultHttpClient();

    HttpParams params = client.getParams();
    HttpConnectionParams.setConnectionTimeout(params, 1000 * 5);
    HttpConnectionParams.setSoTimeout(params, 1000 * 5);

    HttpGet request = new HttpGet(url);

    HttpResponse response = null;// ww  w .  j  a va  2  s  .c  o m
    try {
        response = client.execute(request);
    } catch (IOException ex) {
        Logger.getLogger(HttpGetExample.class.getName()).log(Level.SEVERE, null, ex);
    }
    BufferedReader rd;
    String html = "";
    String line = null;
    try {
        rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        while ((line = rd.readLine()) != null) {
            html += line + "\n";

        }
    } catch (IOException ex) {
        Logger.getLogger(HttpGetExample.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedOperationException ex) {
        Logger.getLogger(HttpGetExample.class.getName()).log(Level.SEVERE, null, ex);
    }
    return html;
}

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

public static HttpResponse getState(TrustedHttpClient client) throws Exception {
    return client.execute(new HttpGet(getServiceUrl() + "state"));
}