List of usage examples for java.net UnknownHostException toString
public String toString()
From source file:id.nci.stm_9.HkpKeyServer.java
private String query(String request) throws QueryException, HttpError { InetAddress ips[];/*from w w w. j a v a 2s . c o m*/ try { ips = InetAddress.getAllByName(mHost); } catch (UnknownHostException e) { throw new QueryException(e.toString()); } for (int i = 0; i < ips.length; ++i) { try { String url = "http://" + ips[i].getHostAddress() + ":" + mPort + request; URL realUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection(); conn.setConnectTimeout(5000); conn.setReadTimeout(25000); conn.connect(); int response = conn.getResponseCode(); if (response >= 200 && response < 300) { return readAll(conn.getInputStream(), conn.getContentEncoding()); } else { String data = readAll(conn.getErrorStream(), conn.getContentEncoding()); throw new HttpError(response, data); } } catch (MalformedURLException e) { // nothing to do, try next IP } catch (IOException e) { // nothing to do, try next IP } } throw new QueryException("querying server(s) for '" + mHost + "' failed"); }
From source file:org.openintents.openpgp.keyserver.HkpKeyServer.java
private String submitQuery(String request) throws QueryException, HttpError { InetAddress ips[];/*w w w. ja v a2 s. com*/ try { ips = InetAddress.getAllByName(mHost); } catch (UnknownHostException e) { throw new QueryException(e.toString()); } for (int i = 0; i < ips.length; ++i) { try { String url = "http://" + ips[i].getHostAddress() + ":" + mPort + request; URL realUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection(); conn.setConnectTimeout(5000); conn.setReadTimeout(25000); conn.connect(); int response = conn.getResponseCode(); if (response >= 200 && response < 300) { return readAll(conn.getInputStream(), conn.getContentEncoding()); } else { String data = readAll(conn.getErrorStream(), conn.getContentEncoding()); throw new HttpError(response, data); } } catch (MalformedURLException e) { // nothing to do, try next IP } catch (IOException e) { // nothing to do, try next IP } } throw new QueryException("querying server(s) for '" + mHost + "' failed"); }
From source file:eu.faircode.netguard.LogAdapter.java
public LogAdapter(Context context, Cursor cursor, boolean resolve) { super(context, cursor, 0); this.resolve = resolve; colTime = cursor.getColumnIndex("time"); colVersion = cursor.getColumnIndex("version"); colProtocol = cursor.getColumnIndex("protocol"); colFlags = cursor.getColumnIndex("flags"); colSAddr = cursor.getColumnIndex("saddr"); colSPort = cursor.getColumnIndex("sport"); colDaddr = cursor.getColumnIndex("daddr"); colDPort = cursor.getColumnIndex("dport"); colDName = cursor.getColumnIndex("dname"); colUid = cursor.getColumnIndex("uid"); colData = cursor.getColumnIndex("data"); colAllowed = cursor.getColumnIndex("allowed"); colConnection = cursor.getColumnIndex("connection"); colInteractive = cursor.getColumnIndex("interactive"); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorOn, tv, true); colorOn = tv.data;/*from w w w . j av a2 s .co m*/ context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); colorOff = tv.data; try { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); dns = SinkholeService.getDns(context); vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } }
From source file:org.zenoss.app.metric.zapp.ManagedReporter.java
String getLocalHostName() { String host = null;/* w ww . j av a 2s .c om*/ try { host = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOG.info("Could not get localhost inetaddress: {}", e.toString()); LOG.debug("error getting localhost", e); } return host; }
From source file:com.android.tools.idea.sdk.remote.internal.UrlOpener.java
/** * Opens a URL. It can be a simple URL or one which requires basic * authentication.// ww w . ja v a 2s . co m * <p/> * Tries to access the given URL. If http response is either * {@code HttpStatus.SC_UNAUTHORIZED} or * {@code HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED}, asks for * login/password and tries to authenticate into proxy server and/or URL. * <p/> * This implementation relies on the Apache Http Client due to its * capabilities of proxy/http authentication. <br/> * Proxy configuration is determined by {@link ProxySelectorRoutePlanner} using the JVM proxy * settings by default. * <p/> * For more information see: <br/> * - {@code http://hc.apache.org/httpcomponents-client-ga/} <br/> * - {@code http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/conn/ProxySelectorRoutePlanner.html} * <p/> * There's a very simple realm cache implementation. * Login/Password for each realm are stored in a static {@link Map}. * Before asking the user the method verifies if the information is already * available in the memory cache. * * @param url the URL string to be opened. * @param needsMarkResetSupport Indicates the caller <em>must</em> have an input stream that * supports the mark/reset operations (as indicated by {@link InputStream#markSupported()}. * Implementation detail: If the original stream does not, it will be fetched and wrapped * into a {@link ByteArrayInputStream}. This can only work sanely if the resource is a * small file that can fit in memory. It also means the caller has no chance of showing * a meaningful download progress. If unsure, callers should set this to false. * @param monitor {@link ITaskMonitor} to output status. * @param headers An optional array of HTTP headers to use in the GET request. * @return Returns a {@link Pair} with {@code first} holding an {@link InputStream} * and {@code second} holding an {@link HttpResponse}. * The returned pair is never null and contains * at least a code; for http requests that provide them the response * also contains locale, headers and an status line. * The input stream can be null, especially in case of error. * The caller must only accept the stream if the response code is 200 or similar. * @throws IOException Exception thrown when there are problems retrieving * the URL or its content. * @throws CanceledByUserException Exception thrown if the user cancels the * authentication dialog. */ @NonNull static Pair<InputStream, HttpResponse> openUrl(@NonNull String url, boolean needsMarkResetSupport, @NonNull ITaskMonitor monitor, @Nullable Header[] headers) throws IOException, CanceledByUserException { Exception fallbackOnJavaUrlConnect = null; Pair<InputStream, HttpResponse> result = null; try { result = openWithHttpClient(url, monitor, headers); } catch (UnknownHostException e) { // Host in unknown. No need to even retry with the Url object, // if it's broken, it's broken. It's already an IOException but // it could use a better message. throw new IOException("Unknown Host " + e.getMessage(), e); } catch (ClientProtocolException e) { // We get this when HttpClient fails to accept the current protocol, // e.g. when processing file:// URLs. fallbackOnJavaUrlConnect = e; } catch (IOException e) { throw e; } catch (CanceledByUserException e) { // HTTP Basic Auth or NTLM login was canceled by user. throw e; } catch (Exception e) { if (DEBUG) { System.out.printf("[HttpClient Error] %s : %s\n", url, e.toString()); } fallbackOnJavaUrlConnect = e; } if (fallbackOnJavaUrlConnect != null) { // If the protocol is not supported by HttpClient (e.g. file:///), // revert to the standard java.net.Url.open. try { result = openWithUrl(url, headers); } catch (IOException e) { throw e; } catch (Exception e) { if (DEBUG && !fallbackOnJavaUrlConnect.equals(e)) { System.out.printf("[Url Error] %s : %s\n", url, e.toString()); } } } // If the caller requires an InputStream that supports mark/reset, let's // make sure we have such a stream. if (result != null && needsMarkResetSupport) { InputStream is = result.getFirst(); if (is != null) { if (!is.markSupported()) { try { // Consume the whole input stream and offer a byte array stream instead. // This can only work sanely if the resource is a small file that can // fit in memory. It also means the caller has no chance of showing // a meaningful download progress. InputStream is2 = toByteArrayInputStream(is); if (is2 != null) { result = Pair.of(is2, result.getSecond()); try { is.close(); } catch (Exception ignore) { } } } catch (Exception e3) { // Ignore. If this can't work, caller will fail later. } } } } if (result == null) { // Make up an error code if we don't have one already. HttpResponse outResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 0), //$NON-NLS-1$ HttpStatus.SC_METHOD_FAILURE, ""); //$NON-NLS-1$; // 420=Method Failure result = Pair.of(null, outResponse); } return result; }
From source file:org.sufficientlysecure.keychain.keyimport.HkpKeyServer.java
private String query(String request) throws QueryException, HttpError { InetAddress ips[];//w ww . ja va 2 s. c om try { ips = InetAddress.getAllByName(mHost); } catch (UnknownHostException e) { throw new QueryException(e.toString()); } for (int i = 0; i < ips.length; ++i) { try { String url = "http://" + ips[i].getHostAddress() + ":" + mPort + request; Log.d(Constants.TAG, "hkp keyserver query: " + url); URL realUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection(); conn.setConnectTimeout(5000); conn.setReadTimeout(25000); conn.connect(); int response = conn.getResponseCode(); if (response >= 200 && response < 300) { return readAll(conn.getInputStream(), conn.getContentEncoding()); } else { String data = readAll(conn.getErrorStream(), conn.getContentEncoding()); throw new HttpError(response, data); } } catch (MalformedURLException e) { // nothing to do, try next IP } catch (IOException e) { // nothing to do, try next IP } } throw new QueryException("querying server(s) for '" + mHost + "' failed"); }
From source file:org.thialfihar.android.apg.keyimport.HkpKeyserver.java
private String query(String request) throws QueryFailedException, HttpError { InetAddress ips[];// w w w . j ava 2 s.c o m try { ips = InetAddress.getAllByName(mHost); } catch (UnknownHostException e) { throw new QueryFailedException(e.toString()); } for (int i = 0; i < ips.length; ++i) { try { String url = "http://" + ips[i].getHostAddress() + ":" + mPort + request; Log.d(Constants.TAG, "hkp keyserver query: " + url); URL realUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection(); conn.setConnectTimeout(5000); conn.setReadTimeout(25000); conn.connect(); int response = conn.getResponseCode(); if (response >= 200 && response < 300) { return readAll(conn.getInputStream(), conn.getContentEncoding()); } else { String data = readAll(conn.getErrorStream(), conn.getContentEncoding()); throw new HttpError(response, data); } } catch (MalformedURLException e) { // nothing to do, try next IP } catch (IOException e) { // nothing to do, try next IP } } throw new QueryFailedException("querying server(s) for '" + mHost + "' failed"); }
From source file:org.loggo.server.Server.java
void initialize(HierarchicalINIConfiguration config) throws ConfigurationException, AccumuloException, AccumuloSecurityException { Configuration kafkaConsumerSection = config.getSection("KafkaConsumer"); Configuration serverSection = config.getSection("server"); Configuration accumuloSection = config.getSection("accumulo"); Configuration batchSection = config.getSection("batchwriter"); Configuration kafkaSection = config.getSection("kafka"); ClientConfiguration clientConfig = new ClientConfiguration(accumuloSection); // connect to accumulo, check on the table String username = batchSection.getString("user", Defaults.USER); String password = batchSection.getString("password", Defaults.PASSWORD); String table = batchSection.getString("table", Defaults.TABLE); Instance instance = new ZooKeeperInstance(clientConfig); Connector connector = instance.getConnector(username, new PasswordToken(password.getBytes())); if (!connector.tableOperations().exists(table)) { createTable(connector, table);/* w w w . j a v a 2 s. co m*/ } createTopic(kafkaConsumerSection.getString("zookeeper.connect"), kafkaSection); LinkedBlockingDeque<LogEntry> queue = new LinkedBlockingDeque<LogEntry>( config.getInt("queue.size", Defaults.QUEUE_SIZE)); this.writer = new Writer(queue, clientConfig, batchSection); ServerBootstrap b = new ServerBootstrap(); // @formatter:off // tcp b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new LoggerReaderInitializer(queue)); // udp Bootstrap bb = new Bootstrap(); bb.group(dgramGroup).channel(NioDatagramChannel.class).handler(new DgramHandler(queue)); // @formatter:on String host = serverSection.getString("host", Defaults.HOST); serverSection.setProperty("host", host); if (host.equals(Defaults.HOST)) { try { serverSection.setProperty("host", InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException ex) { throw new RuntimeException("Unable to determine local hostname: " + ex.toString()); } } try { int tcpPort = serverSection.getInteger("tcp.port", Defaults.PORT); channel = b.bind(host, tcpPort).sync().channel(); tcpPort = ((InetSocketAddress) channel.localAddress()).getPort(); serverSection.setProperty("tcp.port", tcpPort); int udpPort = serverSection.getInteger("udp.port", Defaults.PORT); Channel channel2 = bb.bind(host, udpPort).sync().channel(); udpPort = ((InetSocketAddress) channel2.localAddress()).getPort(); serverSection.setProperty("udp.port", udpPort); registerInZookeeper(serverSection); } catch (IOException | KeeperException | InterruptedException ex) { throw new RuntimeException(ex); } String zookeeperConnect = kafkaConsumerSection.getString("zookeeper.connect"); if (zookeeperConnect != null) { kafkaConsumer = new KafkaConsumer(); kafkaConsumer.initialize(config, queue); kafkaConsumer.start(); } }
From source file:com.master.metehan.filtereagle.AdapterLog.java
public AdapterLog(Context context, Cursor cursor, boolean resolve, boolean organization) { super(context, cursor, 0); this.resolve = resolve; this.organization = organization; colID = cursor.getColumnIndex("ID"); colTime = cursor.getColumnIndex("time"); colVersion = cursor.getColumnIndex("version"); colProtocol = cursor.getColumnIndex("protocol"); colFlags = cursor.getColumnIndex("flags"); colSAddr = cursor.getColumnIndex("saddr"); colSPort = cursor.getColumnIndex("sport"); colDAddr = cursor.getColumnIndex("daddr"); colDPort = cursor.getColumnIndex("dport"); colDName = cursor.getColumnIndex("dname"); colUid = cursor.getColumnIndex("uid"); colData = cursor.getColumnIndex("data"); colAllowed = cursor.getColumnIndex("allowed"); colConnection = cursor.getColumnIndex("connection"); colInteractive = cursor.getColumnIndex("interactive"); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorOn, tv, true); colorOn = tv.data;// ww w . j a v a2s. c om context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); colorOff = tv.data; iconSize = Util.dips2pixels(24, context); try { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); dns = ServiceSinkhole.getDns(context).get(0); vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } }
From source file:android_network.hetnet.vpn_service.AdapterLog.java
public AdapterLog(Context context, Cursor cursor, boolean resolve, boolean organization) { super(context, cursor, 0); this.resolve = resolve; this.organization = organization; colID = cursor.getColumnIndex("ID"); colTime = cursor.getColumnIndex("time"); colVersion = cursor.getColumnIndex("version"); colProtocol = cursor.getColumnIndex("protocol"); colFlags = cursor.getColumnIndex("flags"); colSAddr = cursor.getColumnIndex("saddr"); colSPort = cursor.getColumnIndex("sport"); colDAddr = cursor.getColumnIndex("daddr"); colDPort = cursor.getColumnIndex("dport"); colDName = cursor.getColumnIndex("dname"); colUid = cursor.getColumnIndex("uid"); colData = cursor.getColumnIndex("data"); colAllowed = cursor.getColumnIndex("allowed"); colConnection = cursor.getColumnIndex("connection"); colInteractive = cursor.getColumnIndex("interactive"); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorOn, tv, true); colorOn = tv.data;// w w w. ja va2 s . c om context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); colorOff = tv.data; iconSize = Util.dips2pixels(24, context); try { List<InetAddress> lstDns = ServiceSinkhole.getDns(context); dns1 = (lstDns.size() > 0 ? lstDns.get(0) : null); dns2 = (lstDns.size() > 1 ? lstDns.get(1) : null); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } }