List of usage examples for org.apache.http.client.methods HttpGet HttpGet
public HttpGet(final String uri)
From source file:org.liberty.android.fantastischmemo.downloader.DownloaderUtils.java
public static String downloadJSONString(String url) throws Exception { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); HttpResponse response;/*from w w w .ja va 2s. c o m*/ response = httpclient.execute(httpget); Log.i(TAG, "Response: " + response.getStatusLine().toString()); HttpEntity entity = response.getEntity(); if (entity == null) { throw new NullPointerException("Null entity error"); } InputStream instream = entity.getContent(); // Now convert stream to string BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); StringBuilder sb = new StringBuilder(); String line = null; String result = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } result = sb.toString(); return result; }
From source file:com.gogh.plugin.translator.TranslatorUtil.java
public static String fetchInfo(String query, TranslatorEx translator) { final CloseableHttpClient client = TranslatorUtil.createClient(); try {/*from w w w .j a v a 2 s . c o m*/ final URI queryUrl = translator.createUrl(query); HttpGet httpGet = new HttpGet(queryUrl); HttpResponse response = client.execute(httpGet); int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { HttpEntity resEntity = response.getEntity(); return translator.generateSuccess(resEntity); } else { return translator.generateFail(response); } } catch (Exception ignore) { ignore.printStackTrace(); } finally { try { client.close(); } catch (IOException ignore) { } } return null; }
From source file:org.keycloak.example.CamelClient.java
public static String sendRequest(HttpServletRequest req) throws CxfRsClient.Failure { KeycloakSecurityContext session = (KeycloakSecurityContext) req .getAttribute(KeycloakSecurityContext.class.getName()); HttpClient client = new HttpClientBuilder().disableTrustManager().build(); StringBuilder sb = new StringBuilder(); try {//w ww . j a v a 2 s . c om // Initially let's invoke a simple Camel-Jetty exposed endpoint HttpGet get = new HttpGet("http://localhost:8383/admin-camel-endpoint"); get.addHeader("Authorization", "Bearer " + session.getTokenString()); try { HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() != 200) { return "There was a failure processing request. You either didn't configure Keycloak properly or you don't have admin permission? Status code is " + response.getStatusLine().getStatusCode(); } HttpEntity entity = response.getEntity(); InputStream is = entity.getContent(); try { sb.append(getStringFromInputStream(is)); } finally { is.close(); } } catch (IOException e) { throw new RuntimeException(e); } // Here we invoke a Jetty endpoint, published using Camel RestDSL get = new HttpGet("http://localhost:8484/restdsl/hello/world"); get.addHeader("Authorization", "Bearer " + session.getTokenString()); try { HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() != 200) { return "There was a failure processing request with the RestDSL endpoint. You either didn't configure Keycloak properly or you don't have admin permission? Status code is " + response.getStatusLine().getStatusCode(); } HttpEntity entity = response.getEntity(); InputStream is = entity.getContent(); try { sb.append(getStringFromInputStream(is)); } finally { is.close(); } } catch (IOException e) { throw new RuntimeException(e); } } finally { client.getConnectionManager().shutdown(); } return sb.toString(); }
From source file:steamdb.parser.HttpGetRequest.java
public String getPage(String url) throws Exception { URI uri = new URI(url); HttpGet request = new HttpGet(url); 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);/*from www . j a v a2s. c o m*/ } return result.toString(); }
From source file:me.xingrz.prox.pac.AutoConfig.java
/** * {@code url} ? PAC /*from ww w.j a v a 2 s .com*/ * * @param url PAC ? * @return {@code ProxAutoConfig} * @throws IOException */ public static AutoConfig fromUrl(String url) throws IOException { HttpResponse response = new DefaultHttpClient().execute(new HttpGet(url)); String config = EntityUtils.toString(response.getEntity()); return new AutoConfig(config); }
From source file:io.fabric8.maven.docker.access.util.RequestUtil.java
public static HttpUriRequest newGet(String url) { return addDefaultHeaders(new HttpGet(url)); }
From source file:fr.julienvermet.bugdroid.util.NetworkUtils.java
public static NetworkResult readJson(String url) { StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); int statusCode = 0; try {//from ww w . j a va 2s . c o m HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { builder.append(line); } reader.close(); } else { Log.e(NetworkUtils.class.toString(), "Failed to download Json content"); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { } return new NetworkResult(statusCode, builder.toString()); }
From source file:org.opencastproject.remotetest.util.CaptureUtils.java
/** * Returns <code>true</code> if the capture agent with id <code>{@link #CAPTURE_AGENT_ID}</code> is online. * //w ww .j av a2 s . c o m * @param agent * the agent identifier * @return <code>true</code> if the agent is online */ public static boolean isOnline(String agent) { HttpGet request = new HttpGet(BASE_URL + "/capture-admin/agents/" + agent); return HttpStatus.SC_OK == Main.getClient().execute(request).getStatusLine().getStatusCode(); }
From source file:fm.krui.kruifm.JSONFunctions.java
public static JSONObject getJSONObjectFromURL(String url) { InputStream is = null;//from w w w . j ava2s . c o m String result = ""; JSONObject jArray = null; //http post try { HttpClient httpclient = new DefaultHttpClient(); HttpGet httppost = new HttpGet(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e(TAG, "Error in http connection " + e.toString()); } //convert response to string try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch (Exception e) { Log.e(TAG, "Error converting result " + e.toString()); } try { jArray = new JSONObject(result); } catch (JSONException e) { Log.e(TAG, "Error parsing data " + e.toString()); } return jArray; }
From source file:com.mycompany.rakornas.getDataURL.java
String getData(String url) throws IOException { try (CloseableHttpClient httpclient = HttpClients.createDefault()) { HttpGet httpget = new HttpGet(url); System.out.println("Executing request " + httpget.getRequestLine()); ResponseHandler<String> responseHandler; responseHandler = new ResponseHandler<String>() { @Override/*from w ww.j av a2s. c o m*/ 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 responseURL = httpclient.execute(httpget, responseHandler); return responseURL; } }