String httpGet(URL url) throws IOException { HttpURLConnection conn; int delayMillis = 1000; BufferedReader br = null; for (int currentTry = 0; currentTry < NUM_RETRIES; currentTry++) { try { conn = HttpUtil.getHttpConnection(url, TIMEOUT_MS); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new IOException(String.format("HTTP error fetching url %s. Returned status code %d", url.toString(), conn.getResponseCode())); } else { return br.lines().collect(Collectors.joining()); } } catch (Exception e) { LOG.error(String.format("Error in heartbeat request. Retrying [%d/%d].", currentTry + 1, NUM_RETRIES), e); sleepUninterruptibly(delayMillis); delayMillis = delayMillis * BACKOFF_MULTIPLIER; } finally { if (br != null) { br.close(); } } } throw new IOException(String.format("Error fetching url: %s. Tried %d time(s).", url.toString(), NUM_RETRIES)); }
String httpGet(URL url) throws IOException { HttpURLConnection conn; int delayMillis = 1000; BufferedReader br = null; for (int currentTry = 0; currentTry < NUM_RETRIES; currentTry++) { try { conn = HttpUtil.getHttpConnection(url, TIMEOUT_MS); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new IOException(String.format("HTTP error fetching url %s. Returned status code %d", url.toString(), conn.getResponseCode())); } else { return br.lines().collect(Collectors.joining()); } } catch (Exception e) { LOG.error(String.format("Error in heartbeat request. Retrying [%d/%d].", currentTry + 1, NUM_RETRIES), e); sleepUninterruptibly(delayMillis); delayMillis = delayMillis * BACKOFF_MULTIPLIER; } finally { if (br != null) { br.close(); } } } throw new IOException(String.format("Error fetching url: %s. Tried %d time(s).", url.toString(), NUM_RETRIES)); }
String httpGet(URL url) throws IOException { HttpURLConnection conn; int delayMillis = 1000; BufferedReader br = null; for (int currentTry = 0; currentTry < NUM_RETRIES; currentTry++) { try { conn = HttpUtil.getHttpConnection(url, TIMEOUT_MS); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new IOException(String.format("HTTP error fetching url %s. Returned status code %d", url.toString(), conn.getResponseCode())); } else { return br.lines().collect(Collectors.joining()); } } catch (Exception e) { LOG.error(String.format("Error in heartbeat request. Retrying [%d/%d].", currentTry + 1, NUM_RETRIES), e); sleepUninterruptibly(delayMillis); delayMillis = delayMillis * BACKOFF_MULTIPLIER; } finally { if (br != null) { br.close(); } } } throw new IOException(String.format("Error fetching url: %s. Tried %d time(s).", url.toString(), NUM_RETRIES)); }
String httpGet(URL url) throws IOException { HttpURLConnection conn; int delayMillis = 1000; BufferedReader br = null; for (int currentTry = 0; currentTry < NUM_RETRIES; currentTry++) { try { conn = HttpUtil.getHttpConnection(url, TIMEOUT_MS); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new IOException(String.format("HTTP error fetching url %s. Returned status code %d", url.toString(), conn.getResponseCode())); } else { return br.lines().collect(Collectors.joining()); } } catch (Exception e) { LOG.error(String.format("Error in heartbeat request. Retrying [%d/%d].", currentTry + 1, NUM_RETRIES), e); sleepUninterruptibly(delayMillis); delayMillis = delayMillis * BACKOFF_MULTIPLIER; } finally { if (br != null) { br.close(); } } } throw new IOException(String.format("Error fetching url: %s. Tried %d time(s).", url.toString(), NUM_RETRIES)); }
String httpGet(URL url) throws IOException { HttpURLConnection conn; int delayMillis = 1000; BufferedReader br = null; for (int currentTry = 0; currentTry < NUM_RETRIES; currentTry++) { try { conn = HttpUtil.getHttpConnection(url, TIMEOUT_MS); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new IOException(String.format("HTTP error fetching url %s. Returned status code %d", url.toString(), conn.getResponseCode())); } else { return br.lines().collect(Collectors.joining()); } } catch (Exception e) { LOG.error(String.format("Error in heartbeat request. Retrying [%d/%d].", currentTry + 1, NUM_RETRIES), e); sleepUninterruptibly(delayMillis); delayMillis = delayMillis * BACKOFF_MULTIPLIER; } finally { if (br != null) { br.close(); } } } throw new IOException(String.format("Error fetching url: %s. Tried %d time(s).", url.toString(), NUM_RETRIES)); }