Search in sources :

Example 6 with SRVRecord

use of org.jivesoftware.smack.util.dns.SRVRecord in project Smack by igniterealtime.

the class JavaxResolver method lookupSRVRecords0.

@Override
protected List<SRVRecord> lookupSRVRecords0(String name, List<HostAddress> failedAddresses, DnssecMode dnssecMode) {
    List<SRVRecord> res = null;
    Attribute srvAttribute;
    try {
        Attributes dnsLookup = dirContext.getAttributes(name, new String[] { "SRV" });
        srvAttribute = dnsLookup.get("SRV");
        if (srvAttribute == null)
            return null;
    } catch (NameNotFoundException e) {
        LOGGER.log(Level.FINEST, "No DNS SRV RR found for " + name, e);
        return null;
    } catch (NamingException e) {
        LOGGER.log(Level.WARNING, "Exception while resolving DNS SRV RR for " + name, e);
        return null;
    }
    try {
        @SuppressWarnings("unchecked") NamingEnumeration<String> srvRecords = (NamingEnumeration<String>) srvAttribute.getAll();
        res = new ArrayList<>();
        while (srvRecords.hasMore()) {
            String srvRecordString = srvRecords.next();
            String[] srvRecordEntries = srvRecordString.split(" ");
            int priority = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 4]);
            int port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 2]);
            int weight = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 3]);
            String host = srvRecordEntries[srvRecordEntries.length - 1];
            List<InetAddress> hostAddresses = lookupHostAddress0(host, failedAddresses, dnssecMode);
            if (hostAddresses == null) {
                continue;
            }
            SRVRecord srvRecord = new SRVRecord(host, port, priority, weight, hostAddresses);
            res.add(srvRecord);
        }
    } catch (NamingException e) {
        LOGGER.log(Level.SEVERE, "Exception while resolving DNS SRV RR for" + name, e);
    }
    return res;
}
Also used : Attribute(javax.naming.directory.Attribute) NameNotFoundException(javax.naming.NameNotFoundException) Attributes(javax.naming.directory.Attributes) NamingEnumeration(javax.naming.NamingEnumeration) NamingException(javax.naming.NamingException) SRVRecord(org.jivesoftware.smack.util.dns.SRVRecord) InetAddress(java.net.InetAddress)

Example 7 with SRVRecord

use of org.jivesoftware.smack.util.dns.SRVRecord in project Smack by igniterealtime.

the class MiniDnsResolver method lookupSRVRecords0.

@Override
protected List<SRVRecord> lookupSRVRecords0(final String name, List<HostAddress> failedAddresses, DnssecMode dnssecMode) {
    final ResolverApi resolver = getResolver(dnssecMode);
    ResolverResult<SRV> result;
    try {
        result = resolver.resolve(name, SRV.class);
    } catch (IOException e) {
        failedAddresses.add(new HostAddress(name, e));
        return null;
    }
    // TODO: Use ResolverResult.getResolutionUnsuccessfulException() found in newer MiniDNS versions.
    if (!result.wasSuccessful()) {
        ResolutionUnsuccessfulException resolutionUnsuccessfulException = getExceptionFrom(result);
        failedAddresses.add(new HostAddress(name, resolutionUnsuccessfulException));
        return null;
    }
    if (shouldAbortIfNotAuthentic(name, dnssecMode, result, failedAddresses)) {
        return null;
    }
    List<SRVRecord> res = new LinkedList<SRVRecord>();
    for (SRV srv : result.getAnswers()) {
        String hostname = srv.name.ace;
        List<InetAddress> hostAddresses = lookupHostAddress0(hostname, failedAddresses, dnssecMode);
        if (hostAddresses == null) {
            continue;
        }
        SRVRecord srvRecord = new SRVRecord(hostname, srv.port, srv.priority, srv.weight, hostAddresses);
        res.add(srvRecord);
    }
    return res;
}
Also used : SRV(de.measite.minidns.record.SRV) ResolutionUnsuccessfulException(de.measite.minidns.hla.ResolutionUnsuccessfulException) ResolverApi(de.measite.minidns.hla.ResolverApi) DnssecResolverApi(de.measite.minidns.hla.DnssecResolverApi) IOException(java.io.IOException) SRVRecord(org.jivesoftware.smack.util.dns.SRVRecord) HostAddress(org.jivesoftware.smack.util.dns.HostAddress) InetAddress(java.net.InetAddress) LinkedList(java.util.LinkedList)

Aggregations

SRVRecord (org.jivesoftware.smack.util.dns.SRVRecord)7 ArrayList (java.util.ArrayList)5 InetAddress (java.net.InetAddress)4 HostAddress (org.jivesoftware.smack.util.dns.HostAddress)3 LinkedList (java.util.LinkedList)2 Record (org.xbill.DNS.Record)2 TextParseException (org.xbill.DNS.TextParseException)2 DnssecResolverApi (de.measite.minidns.hla.DnssecResolverApi)1 ResolutionUnsuccessfulException (de.measite.minidns.hla.ResolutionUnsuccessfulException)1 ResolverApi (de.measite.minidns.hla.ResolverApi)1 SRV (de.measite.minidns.record.SRV)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 NameNotFoundException (javax.naming.NameNotFoundException)1 NamingEnumeration (javax.naming.NamingEnumeration)1 NamingException (javax.naming.NamingException)1 Attribute (javax.naming.directory.Attribute)1 Attributes (javax.naming.directory.Attributes)1