@Override public List<InetAddress> lookup(String hostname) throws UnknownHostException { if (!this.dnsHostname.equals(hostname)) { throw new UnknownHostException( "BootstrapDns called for " + hostname + " instead of " + dnsHostname); } return dnsServers; } }
@Override public List<InetAddress> lookup(String hostname) throws UnknownHostException { requestedHosts.add(hostname); List<InetAddress> result = hostAddresses.get(hostname); if (result != null) return result; throw new UnknownHostException(); }
@Override public List<InetAddress> lookup(String hostname) throws UnknownHostException { if (hostname == null) throw new UnknownHostException("hostname == null"); return Arrays.asList(InetAddress.getAllByName(hostname)); } };
@Override public List<InetAddress> lookup(String hostname) throws UnknownHostException { if (!resolvePrivateAddresses || !resolvePublicAddresses) { boolean privateHost = isPrivateHost(hostname); if (privateHost && !resolvePrivateAddresses) { throw new UnknownHostException("private hosts not resolved"); } if (!privateHost && !resolvePublicAddresses) { throw new UnknownHostException("public hosts not resolved"); } } return lookupHttps(hostname); }
private List<InetAddress> throwBestFailure(String hostname, List<Exception> failures) throws UnknownHostException { if (failures.size() == 0) { throw new UnknownHostException(hostname); } Exception failure = failures.get(0); if (failure instanceof UnknownHostException) { throw (UnknownHostException) failure; } UnknownHostException unknownHostException = new UnknownHostException(hostname); unknownHostException.initCause(failure); for (int i = 1; i < failures.size(); i++) { Util.addSuppressedIfPossible(unknownHostException, failures.get(i)); } throw unknownHostException; }
@Override public InetAddress[] getAllByName(String name) throws UnknownHostException { throw new UnknownHostException(); } };
public IpSubnet(String cidr) throws UnknownHostException { Objects.requireNonNull(cidr, "CIDR must not be null"); /* split CIDR to address and prefix part */ if (cidr.contains("/")) { int index = cidr.indexOf("/"); String addressPart = cidr.substring(0, index); String networkPart = cidr.substring(index + 1); inetAddress = InetAddress.getByName(addressPart); prefixLength = Integer.parseInt(networkPart); calculate(); } else { throw new UnknownHostException("Invalid subnet: " + cidr); } }
@Override public byte[] getAddress() throws UnknownHostException { final SocketAddress remoteAddress = ioSession.getRemoteAddress(); if (remoteAddress == null) throw new UnknownHostException(); final InetSocketAddress socketAddress = (InetSocketAddress) remoteAddress; final InetAddress address = socketAddress.getAddress(); return address.getAddress(); }
@Override public String getHostAddress() throws UnknownHostException { final SocketAddress remoteAddress = ioSession.getRemoteAddress(); if (remoteAddress == null) throw new UnknownHostException(); final InetSocketAddress socketAddress = (InetSocketAddress) remoteAddress; final InetAddress inetAddress = socketAddress.getAddress(); return inetAddress.getHostAddress(); }
@Override public String getHostAddress() throws UnknownHostException { if (conn == null) { throw new UnknownHostException("Detached session"); } return conn.getHostAddress(); }
@Override public String getHostName() throws UnknownHostException { final SocketAddress remoteAddress = ioSession.getRemoteAddress(); if (remoteAddress == null) throw new UnknownHostException(); final InetSocketAddress socketAddress = (InetSocketAddress) remoteAddress; final InetAddress inetAddress = socketAddress.getAddress(); return inetAddress.getHostName(); }
@Override public String getHostName() throws UnknownHostException { if (conn == null) { throw new UnknownHostException("Detached session"); } return conn.getHostName(); }
@Override public void operationComplete(Future<List<InetAddress>> future) throws Exception { if (future.isSuccess()) { List<InetAddress> inetAddresses = future.getNow(); int numAddresses = inetAddresses.size(); if (numAddresses > 0) { // if there are multiple addresses: we shall pick one by one // to support the round robin distribution promise.setSuccess(inetAddresses.get(randomIndex(numAddresses))); } else { promise.setFailure(new UnknownHostException(inetHost)); } } else { promise.setFailure(future.cause()); } } });
@Override public InetAddress[] getAllByName(String name) throws UnknownHostException { if (name.contains("resolvable")) { byte[] addr = new byte[] { 10, 0, 0, (byte)(counter++ % 10) }; return new InetAddress[] { InetAddress.getByAddress(name, addr) }; } throw new UnknownHostException(); } }
@Override public void operationComplete(Future<List<InetAddress>> future) throws Exception { if (future.isSuccess()) { List<InetAddress> inetAddresses = future.getNow(); int numAddresses = inetAddresses.size(); if (numAddresses > 0) { // if there are multiple addresses: we shall pick one by one // to support the round robin distribution promise.setSuccess(inetAddresses.get(randomIndex(numAddresses))); } else { promise.setFailure(new UnknownHostException(inetHost)); } } else { promise.setFailure(future.cause()); } } });
@Override public synchronized void onFailed( UrlRequest request, UrlResponseInfo info, CronetException error) { if (request != currentUrlRequest) { return; } if (error instanceof NetworkException && ((NetworkException) error).getErrorCode() == NetworkException.ERROR_HOSTNAME_NOT_RESOLVED) { exception = new UnknownHostException(); } else { exception = error; } operation.open(); } }
private InetSocketAddress createAddr(ServerName sn) throws UnknownHostException { InetSocketAddress addr = new InetSocketAddress(sn.getHostname(), sn.getPort()); if (addr.isUnresolved()) { throw new UnknownHostException("can not resolve " + sn.getServerName()); } return addr; }
/** * Returns a new {@code HttpUrl} representing {@code url} if it is a well-formed HTTP or HTTPS * URL, or throws an exception if it isn't. * * @throws MalformedURLException if there was a non-host related URL issue * @throws UnknownHostException if the host was invalid */ static HttpUrl getChecked(String url) throws MalformedURLException, UnknownHostException { Builder builder = new Builder(); Builder.ParseResult result = builder.parse(null, url); switch (result) { case SUCCESS: return builder.build(); case INVALID_HOST: throw new UnknownHostException("Invalid host: " + url); case UNSUPPORTED_SCHEME: case MISSING_SCHEME: case INVALID_PORT: default: throw new MalformedURLException("Invalid URL: " + result + " for " + url); } }
throw new UnknownHostException(address.dns() + " returned no addresses for " + socketHost);
throw new UnknownHostException(hostname + ": NXDOMAIN"); } else if (responseCode == SERVFAIL) { throw new UnknownHostException(hostname + ": SERVFAIL");