Search in sources :

Example 1 with DnsContext

use of com.sun.jndi.dns.DnsContext in project jdk8u_jdk by JetBrains.

the class NamingManager method getURLContext.

public static Context getURLContext(String scheme, Hashtable<?, ?> environment) throws NamingException {
    return new DnsContext("", null, new Hashtable<String, String>()) {

        public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
            return new BasicAttributes() {

                public Attribute get(String attrID) {
                    BasicAttribute ba = new BasicAttribute(attrID);
                    ba.add("1 1 99 b.com.");
                    // 2nd has higher priority
                    ba.add("0 0 88 a.com.");
                    return ba;
                }
            };
        }
    };
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) DnsContext(com.sun.jndi.dns.DnsContext)

Example 2 with DnsContext

use of com.sun.jndi.dns.DnsContext in project jdk8u_jdk by JetBrains.

the class IPv6NameserverPlatformParsingTest method main.

public static void main(String[] args) {
    Hashtable<String, String> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, com.sun.jndi.dns.DnsContextFactory.class.getName());
    String[] servers;
    try {
        Context ctx = NamingManager.getInitialContext(env);
        if (!com.sun.jndi.dns.DnsContextFactory.platformServersAvailable()) {
            throw new RuntimeException("FAIL: no platform servers available, test does not make sense");
        }
        DnsContext context = (DnsContext) ctx;
        servers = getServersFromContext(context);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
    for (String server : servers) {
        System.out.println("DEBUG: 'nameserver = " + server + "'");
        if (server.indexOf(':') >= 0 && server.indexOf('.') < 0) {
            System.out.println("DEBUG: ==> Found IPv6 address in servers list: " + server);
            foundIPv6 = true;
        }
    }
    try {
        new com.sun.jndi.dns.DnsClient(servers, 100, 1);
    } catch (NumberFormatException e) {
        throw new RuntimeException("FAIL: Tried to parse non-[]-encapsulated IPv6 address.", e);
    } catch (Exception e) {
        throw new RuntimeException("ERROR: Something unexpected happened.");
    }
    if (!foundIPv6) {
        // platforms. See comment as to how to run this test.
        throw new RuntimeException("ERROR: No IPv6 address returned from platform.");
    }
    System.out.println("PASS: Found IPv6 address and DnsClient parsed it correctly.");
}
Also used : Context(javax.naming.Context) DnsContext(com.sun.jndi.dns.DnsContext) Hashtable(java.util.Hashtable) DnsContext(com.sun.jndi.dns.DnsContext) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException)

Aggregations

DnsContext (com.sun.jndi.dns.DnsContext)2 Hashtable (java.util.Hashtable)1 Context (javax.naming.Context)1 NamingException (javax.naming.NamingException)1 BasicAttribute (javax.naming.directory.BasicAttribute)1 BasicAttributes (javax.naming.directory.BasicAttributes)1