@Override public Object getContent(Class[] types) throws IOException { return delegate.getContent(types); }
@Override public Object getContent() throws IOException { return delegate.getContent(); }
@SuppressWarnings("unchecked") // Spec does not generify @Override public Object getContent(Class[] types) throws IOException { return delegate.getContent(types); }
@Override public Object getContent() throws IOException { return delegate.getContent(); }
private static boolean isUrlReachable(String url) { boolean result = true; try { final URL verifiableUrl = new URL(url); final HttpURLConnection urlConnect = (HttpURLConnection) verifiableUrl.openConnection(); urlConnect.getContent(); } catch (IOException ignored) { result = false; } return result; }
private static boolean isUrlReachable(String url) { boolean result = true; try { final URL verifiableUrl = new URL(url); final HttpURLConnection urlConnect = (HttpURLConnection) verifiableUrl.openConnection(); urlConnect.getContent(); } catch (IOException ignored) { result = false; } return result; }
public static String getDataFromUrl(String url) { try { HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setConnectTimeout(1000); conn.setReadTimeout(1000); conn.setRequestMethod("GET"); if (conn.getResponseCode() != 200) { throw new RuntimeException("Unable to get data for URL " + url); } byte[] b = new byte[2048]; ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataInputStream d = new DataInputStream((FilterInputStream) conn.getContent()); int c; while ((c = d.read(b, 0, b.length)) != -1) bos.write(b, 0, c); String return_ = new String(bos.toByteArray(), Charsets.UTF_8); logger.info("Calling URL API: {} returns: {}", url, return_); conn.disconnect(); return return_; } catch (Exception ex) { throw new RuntimeException(ex); } }
public static String fetchData(String url) { DataInputStream responseStream = null; try { HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setConnectTimeout(1000); conn.setReadTimeout(10000); conn.setRequestMethod("GET"); if (conn.getResponseCode() != 200) throw new RuntimeException("Unable to get data for URL " + url); byte[] b = new byte[2048]; ByteArrayOutputStream bos = new ByteArrayOutputStream(); responseStream = new DataInputStream((FilterInputStream) conn.getContent()); int c = 0; while ((c = responseStream.read(b, 0, b.length)) != -1) bos.write(b, 0, c); String return_ = new String(bos.toByteArray(), Charsets.UTF_8); logger.info("Calling URL API: {} returns: {}", url, return_); conn.disconnect(); return return_; } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { if (responseStream != null) responseStream.close(); } catch (Exception e) { logger.warn("Failed to close response stream from priam", e); } } } }
public static JsonObject getContent() throws IOException { URL url = new URL("http://localhost:8080"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.connect(); InputStreamReader in = new InputStreamReader((InputStream) conn.getContent()); BufferedReader buff = new BufferedReader(in); String line; StringBuilder builder = new StringBuilder(); do { line = buff.readLine(); builder.append(line).append("\n"); } while (line != null); buff.close(); return new JsonObject(builder.toString()); }
/** * Tests the connection to the specified URL * * @param urlString the url to test * @return true if a connection a established otherwise false */ protected static boolean testConnection(String urlString) { try { HttpURLConnection urlConnect = (HttpURLConnection) new URL(urlString).openConnection(); //wait for 15sec urlConnect.setConnectTimeout(15000); urlConnect.setUseCaches(false); //trying to retrieve data from the source. If there //is no connection, this line will fail urlConnect.getContent(); return true; } catch (IOException e) { if (log.isDebugEnabled()) { log.debug("Error generated:", e); } } return false; }
try (InputStream in = (InputStream) httpConnection.getContent())
public static JsonObject getContent() throws IOException { URL url = new URL("http://localhost:8080"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.connect(); InputStreamReader in = new InputStreamReader((InputStream) conn.getContent()); BufferedReader buff = new BufferedReader(in); String line; StringBuilder builder = new StringBuilder(); do { line = buff.readLine(); builder.append(line).append("\n"); } while (line != null); buff.close(); return new JsonObject(builder.toString()); }
@SuppressWarnings("unchecked") // Spec does not generify @Override public Object getContent(Class[] types) throws IOException { return delegate.getContent(types); }
public int urlWithConnection(String urlString) throws IOException { URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); connection.getContent(); return connection.getResponseCode(); }
public Object getContent() throws IOException { try { handshake(); } catch (IOException ex) { } return connection.getContent(); }
public Object getContent() throws IOException { try { handshake(); } catch (IOException ex) { } return connection.getContent(); }
public Object getContent(Class[] classes) throws IOException { try { handshake(); } catch (IOException ex) { } return connection.getContent(classes); }
@Override public Object getContent ( Class[] classes ) throws IOException { handshake(); return this.connection.getContent(classes); }
@Override public Object getContent () throws IOException { handshake(); return this.connection.getContent(); }
static InputStream getHttpResponse(URL urlt) throws IOException { HttpURLConnection con = (HttpURLConnection)urlt.openConnection(); if (con.getResponseCode() / 100 != 2) { throw new PdfException(PdfException.InvalidHttpResponse1).setMessageParams(con.getResponseCode()); } return (InputStream) con.getContent(); }