当前位置: 首页>>代码示例>>Java>>正文


Java ResolverConfiguration类代码示例

本文整理汇总了Java中sun.net.dns.ResolverConfiguration的典型用法代码示例。如果您正苦于以下问题:Java ResolverConfiguration类的具体用法?Java ResolverConfiguration怎么用?Java ResolverConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ResolverConfiguration类属于sun.net.dns包,在下文中一共展示了ResolverConfiguration类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRealmFromDNS

import sun.net.dns.ResolverConfiguration; //导入依赖的package包/类
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:Config.java

示例2: serversForUrls

import sun.net.dns.ResolverConfiguration; //导入依赖的package包/类
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:DnsContextFactory.java

示例3: serversForUrls

import sun.net.dns.ResolverConfiguration; //导入依赖的package包/类
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<String>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:35,代码来源:DnsContextFactory.java

示例4: getTemporaryContext

import sun.net.dns.ResolverConfiguration; //导入依赖的package包/类
private DirContext getTemporaryContext() throws NamingException {
    SoftReference<ThreadContext> ref = contextRef.get();
    ThreadContext thrCtxt = null;
    List<String> nsList = null;

    // if no property specified we need to obtain the list of servers
    //
    if (nameProviderUrl == null)
        nsList = ResolverConfiguration.open().nameservers();

    // if soft reference hasn't been gc'ed no property has been
    // specified then we need to check if the DNS configuration
    // has changed.
    //
    if ((ref != null) && ((thrCtxt = ref.get()) != null)) {
        if (nameProviderUrl == null) {
            if (!thrCtxt.nameservers().equals(nsList)) {
                // DNS configuration has changed
                thrCtxt = null;
            }
        }
    }

    // new thread context needs to be created
    if (thrCtxt == null) {
        final Hashtable<String,Object> env = new Hashtable<>();
        env.put("java.naming.factory.initial",
                "com.sun.jndi.dns.DnsContextFactory");

        // If no nameservers property specified we create provider URL
        // based on system configured name servers
        //
        String provUrl = nameProviderUrl;
        if (provUrl == null) {
            provUrl = createProviderURL(nsList);
            if (provUrl.length() == 0) {
                throw new RuntimeException("bad nameserver configuration");
            }
        }
        env.put("java.naming.provider.url", provUrl);

        // Need to create directory context in privileged block
        // as JNDI-DNS needs to resolve the name servers.
        //
        DirContext dirCtxt;
        try {
            dirCtxt = java.security.AccessController.doPrivileged(
                    new java.security.PrivilegedExceptionAction<DirContext>() {
                        public DirContext run() throws NamingException {
                            // Create the DNS context using NamingManager rather than using
                            // the initial context constructor. This avoids having the initial
                            // context constructor call itself.
                            Context ctx = NamingManager.getInitialContext(env);
                            if (!(ctx instanceof DirContext)) {
                                return null; // cannot create a DNS context
                            }
                            return (DirContext)ctx;
                        }
                });
        } catch (java.security.PrivilegedActionException pae) {
            throw (NamingException)pae.getException();
        }

        // create new soft reference to our thread context
        //
        thrCtxt = new ThreadContext(dirCtxt, nsList);
        contextRef.set(new SoftReference<ThreadContext>(thrCtxt));
    }

    return thrCtxt.dirContext();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:72,代码来源:DNSNameService.java

示例5: DNSNameService

import sun.net.dns.ResolverConfiguration; //导入依赖的package包/类
public DNSNameService() throws Exception {

        // default domain
        String domain = AccessController.doPrivileged(
            new GetPropertyAction("sun.net.spi.nameservice.domain"));
        if (domain != null && domain.length() > 0) {
            domainList = new LinkedList<String>();
            domainList.add(domain);
        }

        // name servers
        String nameservers = AccessController.doPrivileged(
            new GetPropertyAction("sun.net.spi.nameservice.nameservers"));
        if (nameservers != null && nameservers.length() > 0) {
            nameProviderUrl = createProviderURL(nameservers);
            if (nameProviderUrl.length() == 0) {
                throw new RuntimeException("malformed nameservers property");
            }

        } else {

            // no property specified so check host DNS resolver configured
            // with at least one nameserver in dotted notation.
            //
            List<String> nsList = ResolverConfiguration.open().nameservers();
            if (nsList.isEmpty()) {
                throw new RuntimeException("no nameservers provided");
            }
            boolean found = false;
            for (String addr: nsList) {
                if (IPAddressUtil.isIPv4LiteralAddress(addr) ||
                    IPAddressUtil.isIPv6LiteralAddress(addr)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new RuntimeException("bad nameserver configuration");
            }
        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:DNSNameService.java

示例6: platformServersAvailable

import sun.net.dns.ResolverConfiguration; //导入依赖的package包/类
public static boolean platformServersAvailable() {
    return !filterNameServers(
                ResolverConfiguration.open().nameservers(), true
            ).isEmpty();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:DnsContextFactory.java


注:本文中的sun.net.dns.ResolverConfiguration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。