Display dir context : DirContext « JNDI LDAP « Java






Display dir context

 

import java.util.Enumeration;
import java.util.Hashtable;

import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

public class Main {
  public static void main(String args[]) throws Exception {
    Hashtable<String, String> env = new Hashtable<String, String>();
    env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
    env.put("java.naming.provider.url", "dns://123.123.123.123/");

    String dns_attributes[] = { "MX", "A", "HINFO" };

    DirContext ctx = new InitialDirContext(env);
    Attributes attrsl = ctx.getAttributes("http://www.yourserver.com", dns_attributes);
    for (int z = 0; z < dns_attributes.length; z++) {
      Attribute attr = attrsl.get(dns_attributes[z]);

      if (attr != null) {
        System.out.print(dns_attributes[z] + ": ");
        for (Enumeration vals = attr.getAll(); vals.hasMoreElements();) {
          System.out.println(vals.nextElement());
        }
      }
    }
  }
}

   
  








Related examples in the same category

1.Shows contexts that share the same connection
2.Shows contexts that originally shared the same connection using different connection
3.how to use a timeout when creating a connection
4.Read Timeout Test