records = lookup.run(); retryCount++; } while (lookup.getResult() == Lookup.TRY_AGAIN && retryCount < DNS_NETWORK_FAILURE_RETRY_COUNT);
public static void printAnswer(String name, Lookup lookup) { System.out.print(name + ":"); int result = lookup.getResult(); if (result != Lookup.SUCCESSFUL) System.out.print(" " + lookup.getErrorString()); System.out.println(); Name [] aliases = lookup.getAliases(); if (aliases.length > 0) { System.out.print("# aliases: "); for (int i = 0; i < aliases.length; i++) { System.out.print(aliases[i]); if (i < aliases.length - 1) System.out.print(" "); } System.out.println(); } if (lookup.getResult() == Lookup.SUCCESSFUL) { Record [] answers = lookup.getAnswers(); for (int i = 0; i < answers.length; i++) System.out.println(answers[i]); } }
@Override public List<LookupResult> resolve(final String fqdn) { Lookup lookup = lookupFactory.forName(fqdn); Record[] queryResult = lookup.run(); switch (lookup.getResult()) { case Lookup.SUCCESSFUL: return toLookupResults(queryResult); case Lookup.HOST_NOT_FOUND: // fallthrough case Lookup.TYPE_NOT_FOUND: LOG.warn("No results returned for query '{}'; result from XBill: {} - {}", fqdn, lookup.getResult(), lookup.getErrorString()); return ImmutableList.of(); default: throw new DnsException( String.format("Lookup of '%s' failed with code: %d - %s ", fqdn, lookup.getResult(), lookup.getErrorString())); } }
@Override public List<LookupResult> resolve(final String fqdn) { Lookup lookup = lookupFactory.forName(fqdn); Record[] queryResult = lookup.run(); switch (lookup.getResult()) { case Lookup.SUCCESSFUL: return toLookupResults(queryResult); case Lookup.HOST_NOT_FOUND: // fallthrough case Lookup.TYPE_NOT_FOUND: LOG.warn("No results returned for query '{}'; result from XBill: {} - {}", fqdn, lookup.getResult(), lookup.getErrorString()); return ImmutableList.of(); default: throw new DnsException( String.format("Lookup of '%s' failed with code: %d - %s ", fqdn, lookup.getResult(), lookup.getErrorString())); } }
protected void checkResult(@Nonnull String query, @Nonnull Lookup lookup) throws NoSuchSrvRecordException, UnknownHostException, SocketException { final int result = lookup.getResult(); if (result == HOST_NOT_FOUND) { throw new NoSuchSrvRecordException("Could not find srv entry for query '" + query + "' on remote " + toStringOfResolver(lookup) + "."); } else if (result == TYPE_NOT_FOUND) { throw new UnknownHostException("Could not find the host that should contain the srv entry for query '" + query + "' on remote " + toStringOfResolver(lookup) + "."); } else if (result == TRY_AGAIN) { throw new ServiceTemporaryUnavailableException("Could not get information from remote " + toStringOfResolver(lookup) + "."); } else if (result != 0) { throw new RuntimeException("Could not get information from remote " + toStringOfResolver(lookup) + ". Got: " + lookup.getErrorString()); } }
records = lookup.run(); retryCount++; } while (lookup.getResult() == Lookup.TRY_AGAIN && retryCount < DNS_NETWORK_FAILURE_RETRY_COUNT);
records = lookup.run(); retryCount++; } while (lookup.getResult() == Lookup.TRY_AGAIN && retryCount < DNS_NETWORK_FAILURE_RETRY_COUNT);
private static Record [] lookupHostName(String name, boolean all) throws UnknownHostException { try { Lookup lookup = new Lookup(name, Type.A); Record [] a = lookup.run(); if (a == null) { if (lookup.getResult() == Lookup.TYPE_NOT_FOUND) { Record [] aaaa = new Lookup(name, Type.AAAA).run(); if (aaaa != null) return aaaa; } throw new UnknownHostException("unknown host"); } if (! all) return a; Record [] aaaa = new Lookup(name, Type.AAAA).run(); if (aaaa == null) return a; Record [] merged = new Record[a.length + aaaa.length]; System.arraycopy(a, 0, merged, 0, a.length); System.arraycopy(aaaa, 0, merged, a.length, aaaa.length); return merged; } catch (TextParseException e) { throw new UnknownHostException("invalid name"); } }
private List<Server> lookup() { final Lookup lookup; try { lookup = new Lookup(record, Type.SRV, DClass.IN); } catch (TextParseException e) { throw new RuntimeException(e); } final Record[] result = lookup.run(); if (lookup.getResult() != Lookup.SUCCESSFUL) { throw new RuntimeException( "DNS lookup failed: " + lookup.getErrorString() + ": " + record); } final ImmutableList.Builder<Server> results = ImmutableList.builder(); if (result != null) { for (final Record a : result) { final SRVRecord srv = (SRVRecord) a; results.add(new Server(srv.getTarget().canonicalize().toString(), srv.getPort())); } } return results.build(); } }
if (up.getResult() != 0) { log.log(Level.ERROR, "Unable to discovery endpoints for " + value + " via DNS error: " + up.getErrorString());
/** * Performs a reverse DNS lookup. * * @param addr The ip address to lookup. * @return The host name found for the ip address. * Absent if the ip is not mapped, or something. * @throws IOException on a possibly temporary network error. */ private Optional<String> getHostByAddr(byte[] addr) throws IOException { Name name = ReverseMap.fromAddress(InetAddress.getByAddress(addr)); Record[] records; Lookup lookup; if (dnsServers!=null) { final Resolver res = new ExtendedResolver(dnsServers); lookup = new Lookup(name, Type.PTR); lookup.setResolver(res); records = lookup.run(); } else { lookup = new Lookup(name, Type.PTR); records = lookup.run(); } int result = lookup.getResult(); if (result==Lookup.TRY_AGAIN) { throw new IOException("Network error when trying to look up "+ Arrays.toString(addr) +", try again."); } if (result != Lookup.SUCCESSFUL || records == null) { return Optional.absent(); } return Optional.of(((PTRRecord) records[0]).getTarget().toString()); }
/** * @see org.apache.james.jdkim.api.PublicKeyRecordRetriever#getRecords(java.lang.CharSequence, java.lang.CharSequence, java.lang.CharSequence) */ public List<String> getRecords(CharSequence methodAndOptions, CharSequence selector, CharSequence token) throws TempFailException, PermFailException { if (!"dns/txt".equals(methodAndOptions)) throw new PermFailException("Only dns/txt is supported: " + methodAndOptions + " options unsupported."); try { Lookup query = new Lookup(selector + "._domainkey." + token, Type.TXT); query.setResolver(resolver); Record[] rr = query.run(); int queryResult = query.getResult(); if (queryResult == Lookup.TRY_AGAIN) { throw new TempFailException(query.getErrorString()); } List<String> records = convertRecordsToList(rr); return records; } catch (TextParseException e) { // TODO log return null; } }
if (l.getResult() == Lookup.TRY_AGAIN) { throw new TemporaryResolutionException("DNSService is temporary not reachable"); } else {
if (l.getResult() == Lookup.TRY_AGAIN) { throw new TemporaryResolutionException("DNSService is temporary not reachable"); } else {
int queryResult = query.getResult();
int queryResult = query.getResult();