Get a saved body for a given url.

@param url url for which we need to retrieve the response body in offline mode.
@return response body as string.
543961
private String retrieveFromCache(String url) {
        String savedJson;

        savedJson = mCacheQueryHandler.get(getContext(), url);
        log("---------- body found in offline saver : " + savedJson);
        log("----- NO NETWORK : retrieving ends");
        return savedJson;
    }
1046110
public String getPageHtml(String url) {
        HttpClient httpClient = new HttpClient();
        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(2000);
        httpClient.getHttpConnectionManager().getParams().setSoTimeout(3000);
        GetMethod getMethod = new GetMethod(url);
        try {
            int statusCode = httpClient.executeMethod(getMethod);
            if (statusCode != HttpStatus.SC_OK) {
                LOG.warn("HttpStatus not equal to 200, some problems may occurred:"
                        + getMethod.getStatusLine());
            }
            InputStream inputStream = getMethod.getResponseBodyAsStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            StringBuffer stringBuffer = new StringBuffer();
            String html = "";
            while ((html = br.readLine()) != null) {
                stringBuffer.append(html);
            }
            return stringBuffer.toString();
        } catch (Exception e) {
            LOG.error("Error to get html of url=" + url + " due to " + e.getMessage());
            throw new RuntimeException("Get html failed, " + e.getMessage(), e);
        } finally {
            try {
                getMethod.releaseConnection();
            } catch (Exception e2) {
                // TODO: handle exception
            }
        }
    }
923461
public static String getBody(){
		try {
			return IoUtil.read(getServletRequest().getReader());
		} catch (IOException e) {
			throw new ActionRuntimeException(e);
		}
	}
364507
public byte[] simpleGetBytes(String url) throws IOException {
		final AtomicReference<byte[]> bytes = new AtomicReference<>();
		simpleGetInternal(url, inputStream -> {
            try {
                bytes.set(IOUtils.toByteArray(inputStream));
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }, null);

		return bytes.get();
	}
857804
public static String getStringFromUrl(String urlString) {
    ApacheHttpClient lclient = ApacheHttpClient.create();
    WebResource webResource = lclient.resource(urlString);
    ClientResponse response = webResource.get(ClientResponse.class);

    if (response.getStatus() != 200) {
      throw new RuntimeException("HTTP error code : " + response.getStatus());
    }
    String result = response.getEntity(String.class);
    return result;
  }
562110
public static URL url(final String url) {
        if (url == null) {
            return null;
        }
        try {
            if (url.startsWith("classpath:")) {
                return new URL(null, url, new ClasspathURLStreamHandler());
            }
            return new URL(url);
        } catch (final MalformedURLException ex) {
            throw new IllegalArgumentException("Invalid URL: " + url, ex);
        }
    }
155442
public static String delete(String url, String body) {
        return request(HttpRequest.delete(replaceLocalHost(url)), body).body();
    }
316815
public XmlHttpResponse doHttpGetXml(String url) {
        XmlHttpResponse response = new XmlHttpResponse();
        doGet(url, response);
        setContext(response);
        return response;
    }
873363
private String getContent(String url) throws RottenTomatoesException {
        LOG.trace("Requesting: {}", url);
        try {
            final HttpGet httpGet = new HttpGet(url);
            httpGet.addHeader("accept", "application/json");
            final DigestedResponse response = DigestedResponseReader.requestContent(httpClient, httpGet, charset);

            if (response.getStatusCode() >= HTTP_STATUS_500) {
                throw new RottenTomatoesException(ApiExceptionType.HTTP_503_ERROR, response.getContent(), response.getStatusCode(), url);
            } else if (response.getStatusCode() >= HTTP_STATUS_300) {
                throw new RottenTomatoesException(ApiExceptionType.HTTP_404_ERROR, response.getContent(), response.getStatusCode(), url);
            }

            return response.getContent();
        } catch (IOException ex) {
            throw new RottenTomatoesException(ApiExceptionType.CONNECTION_ERROR, "Error retrieving URL", url, ex);
        }
    }
530001
public InputStream get(String url) throws IOException {
        HttpGet get = null;
        boolean ok = false;
        try {
            // don't bother with challenges
            DefaultHttpClient client = new PreemptiveAuth(m_cManager);
            client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20000);
            client.getCredentialsProvider().setCredentials(m_authScope, m_creds);
            int redirectCount = 0; // how many redirects did we follow
            int resultCode = 300; // not really, but enter the loop that way
            Dimension d = null;
            HttpResponse response = null;
            while (resultCode > 299 && resultCode < 400 && redirectCount < 25) {
                get = new HttpGet(url);
                client.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
                if (Administrator.INSTANCE != null) {
                    d = Administrator.PROGRESS.getSize();
                    // if they're using Administrator, tell them we're downloading...
                    Administrator.PROGRESS.setString("Downloading " + url
                            + " . . .");
                    Administrator.PROGRESS.setValue(100);
                    Administrator.PROGRESS.paintImmediately(0, 0, (int) d
                            .getWidth() - 1, (int) d.getHeight() - 1);
                }
                response = client.execute(get);
                resultCode = response.getStatusLine().getStatusCode();
                if (resultCode > 299 && resultCode < 400) {
                    redirectCount++;
                    url = response.getFirstHeader(HttpHeaders.LOCATION).getValue();
                }
            }
            if (resultCode != 200) {
                System.err.println(EntityUtils.toString(response.getEntity()));
                throw new IOException("Server returned error: " + resultCode
                        + " " + response.getStatusLine().getReasonPhrase());
            }
            ok = true;
            if (Administrator.INSTANCE != null) {
                // cache it to a file
                File tempFile =
                        File.createTempFile("fedora-client-download-", null);
                tempFile.deleteOnExit();
                final InputStream in = response.getEntity().getContent();
                final OutputStream out= new FileOutputStream(tempFile);
                // do the actual download in a safe thread
                SwingWorker<String> worker = new SwingWorker<String>() {

                    @Override
                    public String construct() {
                        try {
                            StreamUtility.pipeStream(in,
                                                     out,
                                                     8192);
                        } catch (Exception e) {
                            thrownException = e;
                        }
                        return "";
                    }
                };
                worker.start();
                // The following code will run in the (safe)
                // Swing event dispatcher thread.
                int ms = 200;
                while (!worker.done) {
                    try {
                        Administrator.PROGRESS.setValue(ms);
                        Administrator.PROGRESS.paintImmediately(0, 0, (int) d
                                .getWidth() - 1, (int) d.getHeight() - 1);
                        Thread.sleep(100);
                        ms = ms + 100;
                        if (ms >= 2000) {
                            ms = 200;
                        }
                    } catch (InterruptedException ie) {
                    }
                }
                if (worker.thrownException != null) {
                    throw worker.thrownException;
                }
                Administrator.PROGRESS.setValue(2000);
                Administrator.PROGRESS.paintImmediately(0, 0, (int) d
                        .getWidth() - 1, (int) d.getHeight() - 1);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ie) {
                }
                in.close();
                return new FileInputStream(tempFile);
            }
            return response.getEntity().getContent();
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        } finally {
            if (get != null && !ok) {
                get.releaseConnection();
            }
            if (Administrator.INSTANCE != null) {
                Administrator.PROGRESS.setValue(0);
                Administrator.PROGRESS.setString("");
            }
        }

    }
20705
public static byte[] getBytes(URL url) throws IOException {
        final String path = url.getPath();
        final File file = new File(path);
        if (file.exists()) {
            return getFileBytes(file);
        }

        return null;
    }
1043944
private static String fetchHttpResponse(URL url) throws IOException {
      HttpURLConnection conn = null;
      try {
         logger.info("fetching from url = " + url);
         conn = (HttpURLConnection) url.openConnection();
         int response = conn.getResponseCode();
         if (response != HttpURLConnection.HTTP_ACCEPTED) {
            String responseContent = IOUtils.toString(conn.getInputStream());
            logger.info("responseContent = " + responseContent);
            
            return responseContent;
         }
         throw new IOException("response from service not valid");
      } catch (IOException e) {
         logger.severe("unable to do proper http request url = " + url.toString());
         throw e;
      } finally {
         conn.disconnect();
      }

   }
522028
public static String put(String url, String body) {
        return request(HttpRequest.put(replaceLocalHost(url)), body).body();
    }
988874
public String doPost(String url, String body) throws IOException {
        HttpPost httpPost = new HttpPost(getWsapiUrl() + url);
        httpPost.setEntity(new StringEntity(body, "utf-8"));
        return doRequest(httpPost);
    }
758047
public static Response get(String url) throws URISyntaxException, HttpException {
        return send(new HttpGet(url), null, null);
    }
1076355
private static String encodeUrl(String url) {
        try {
            URL u = new URL(url);
            return encodeUrl(u).toExternalForm();
        } catch (Exception e) {
            return url;
        }
	}
308129
private HttpGet prepareGet(final String url) {
    final HttpGet httpGet = new HttpGet(this.instanceUrl + url);
    for (final Header header : this.headers) {
      httpGet.addHeader(header);
    }
    return httpGet;
  }