Looks up the DNS name provided in the JNDI context.

@param discoveryDnsName The discovery DNS name
@throws NamingException when the record cannot be found
@return A set of cname records
163006
static Set<String> getCNamesFromTxtRecord(String discoveryDnsName) throws NamingException {
        Attributes attrs = DIR_CONTEXT.getAttributes(discoveryDnsName, new String[]{TXT_RECORD_TYPE});
        Attribute attr = attrs.get(TXT_RECORD_TYPE);
        String txtRecord = null;
        if (attr != null) {
            txtRecord = attr.get().toString();

            /**
             * compatible splited txt record of "host1 host2 host3" but not "host1" "host2" "host3".
             * some dns service provider support txt value only format "host1 host2 host3"
             */
            if (txtRecord.startsWith("\"") && txtRecord.endsWith("\"")) {
                txtRecord = txtRecord.substring(1, txtRecord.length() - 1);
            }
        }

        Set<String> cnamesSet = new TreeSet<>();
        if (txtRecord == null || txtRecord.trim().isEmpty()) {
            return cnamesSet;
        }
        String[] cnames = txtRecord.split(" ");
        Collections.addAll(cnamesSet, cnames);
        return cnamesSet;
    }
1275526
public Entry lookup(Dn dn) throws NoSuchNodeException, MissingParentException {
        existsCheck(dn);
        try {
            return connection.lookup(dn);
        } catch (LdapException e) {
            throw new LdapDaoException(e);
        }
    }
760918
@Nullable
    public static DnsCacheEntry getDnsCache(String host) {
        try {
            return InetAddressCacheUtil.getInetAddressCache(host);
        } catch (Exception e) {
            throw new DnsCacheManipulatorException("Fail to getDnsCache, cause: " + e.toString(), e);
        }
    }
517516
public String lookupNamespace(final String prefix) {
        Object namespace = namespaceMap.get(prefix);
        if (namespace != null) {
            return namespace.toString();
        }
        return this.namespaceTagHints.isEmpty() ? prefix : this.namespaceTagHints.get(prefix);
    }
874491
public void setDomainNames(java.util.Collection<String> domainNames) {
        if (domainNames == null) {
            this.domainNames = null;
            return;
        }

        this.domainNames = new java.util.ArrayList<String>(domainNames);
    }
601399
@SuppressWarnings("rawtypes")
    private List<InetAddress> resolveCname(String hostname) throws NamingException {

        List<InetAddress> inetAddresses = new ArrayList<>();

        Attributes attrs = context.getAttributes(hostname, new String[] { "CNAME" });
        Attribute attr = attrs.get("CNAME");

        if (attr != null && attr.size() > 0) {
            NamingEnumeration e = attr.getAll();

            while (e.hasMore()) {
                String h = (String) e.next();

                if (h.endsWith(".")) {
                    h = h.substring(0, h.lastIndexOf('.'));
                }
                try {
                    InetAddress[] resolved = resolve(h);
                    for (InetAddress inetAddress : resolved) {
                        inetAddresses.add(InetAddress.getByAddress(hostname, inetAddress.getAddress()));
                    }

                } catch (UnknownHostException e1) {
                    // ignore
                }
            }
        }

        return inetAddresses;
    }
1105358
public static dnsaddrec[] get(nitro_service service, dnsaddrec_args args) throws Exception{
		dnsaddrec obj = new dnsaddrec();
		options option = new options();
		option.set_args(nitro_util.object_to_string_withoutquotes(args));
		dnsaddrec[] response = (dnsaddrec[])obj.get_resources(service, option);
		return response;
	}
1061800
@Override
	public Object lookup(Name name) throws NamingException
    {
        if (name.isEmpty())
            return new FFMQJNDIContext(env, bindings);

        // Extract components that belong to this namespace
        String nm = name.toString();

        // Find object in internal hash table
        Object answer = bindings.get(nm);
        if (answer == null)
        {
        	// Dynamic queue or topic lookup
        	if (nm.startsWith("queue/") && nm.length() > 6)
        		return new QueueRef(nm.substring(nm.indexOf('/')+1));
        	if (nm.startsWith("topic/") && nm.length() > 6)
        		return new TopicRef(nm.substring(nm.indexOf('/')+1));
        	
            throw new NameNotFoundException(name + " not found");
        }

        return answer;
    }
132518
public String lookupNamespace(final String prefix) {
        return this.namespaceTagHints.isEmpty() ? prefix : this.namespaceTagHints.get(prefix);
    }
321528
public static dnsnsecrec get(nitro_service service, String hostname) throws Exception{
		dnsnsecrec obj = new dnsnsecrec();
		obj.set_hostname(hostname);
		dnsnsecrec response = (dnsnsecrec) obj.get_resource(service);
		return response;
	}
573303
private static Set<String> getEC2DiscoveryUrlsFromZone(String dnsName, DiscoveryUrlType type) {
        Set<String> eipsForZone;
        try {
            dnsName = "txt." + dnsName;
            LOG.debug("The zone url to be looked up is {} :", dnsName);
            Set<String> ec2UrlsForZone = DnsResolver.getCNamesFromTxtRecord(dnsName);
            for (String ec2Url : ec2UrlsForZone) {
                LOG.debug("The eureka url for the dns name {} is {}", dnsName, ec2Url);
                ec2UrlsForZone.add(ec2Url);
            }
            if (DiscoveryUrlType.CNAME.equals(type)) {
                return ec2UrlsForZone;
            }
            eipsForZone = new TreeSet<>();
            for (String cname : ec2UrlsForZone) {
                String[] tokens = cname.split("\\.");
                String ec2HostName = tokens[0];
                String[] ips = ec2HostName.split("-");
                StringBuilder eipBuffer = new StringBuilder();
                for (int ipCtr = 1; ipCtr < 5; ipCtr++) {
                    eipBuffer.append(ips[ipCtr]);
                    if (ipCtr < 4) {
                        eipBuffer.append(".");
                    }
                }
                eipsForZone.add(eipBuffer.toString());
            }
            LOG.debug("The EIPS for {} is {} :", dnsName, eipsForZone);
        } catch (Throwable e) {
            throw new RuntimeException("Cannot get cnames bound to the region:" + dnsName, e);
        }
        return eipsForZone;
    }
168135
protected String findCertInfo(X509Certificate[] x509certificates) throws NamingException {
        if (x509certificates != null && x509certificates.length != 0) {
            // Only ever use the first certificate, as this si the client supplied one.
            // Further ones are trust stores and CAs that have signed the first cert.
            Principal subject = x509certificates[0].getSubjectDN();
            if (subject != null && subject.getName() != null) {
                List<Rdn> rdns;
                try {
                    rdns = new LdapName(subject.getName()).getRdns();
                }
                catch (InvalidNameException ine) {
                    return null;
                }
                return certInfoExtractor.extractCertInfo(rdns);
            }
        }
        return null;
    }
1195784
static String getDNSubField(String varName, String DN) throws CertificateMapperException {
        if (varName.equals("DN")) {
            return DN; // return the whole DN
        }
        // Parse the DN looking for 'varName'
        StringTokenizer st = new StringTokenizer(DN);
        for (;;) {
            String name, value;
            try {
                name = st.nextToken(",= ");
                value = st.nextToken(",");
                if (value != null) {
                    value = value.substring(1);
                }
            } catch (NoSuchElementException e) {
                e.getMessage();
                break;
            }
            if (name.equals(varName)) {
                return value;
            }
        }

        throw new CertificateMapperException(WIMMessageKey.UNKNOWN_DN_FIELD, Tr.formatMessage(
                                                                                              tc,
                                                                                              WIMMessageKey.UNKNOWN_DN_FIELD,
                                                                                              WIMMessageHelper.generateMsgParms(varName)));
    }
789891
public String mapNamespace(String ns, SiteInfo targetWiki) throws Exception {
    Map<String, Ns> sourceMap = this.getNamespaces();
    Map<Integer, Ns> targetMap = targetWiki.getNamespacesById();
    Ns sourceNs = sourceMap.get(ns);
    if (sourceNs == null) {
      if (debug)
        LOGGER.log(Level.WARNING, "can not map unknown namespace " + ns);
      return ns;
    }
    Ns targetNs = targetMap.get(sourceNs.getId());
    if (targetNs == null) {
      if (debug)
        LOGGER.log(
            Level.WARNING,
            "missing namespace " + sourceNs.getValue() + " id:"
                + sourceNs.getId() + " canonical:" + sourceNs.getCanonical());
      return ns;
    }
    return targetNs.getValue();
  }
257902
public static InetAddress[]
    getAllByName(String name) throws UnknownHostException {
        try {
            InetAddress addr = getByAddress(name);
            return new InetAddress[]{addr};
        } catch (UnknownHostException e) {
            Record[] records = lookupHostName(name);
            InetAddress[] addrs = new InetAddress[records.length];
            for (int i = 0; i < records.length; i++)
                addrs[i] = addrFromRecord(name, records[i]);
            return addrs;
        }
    }
435932
public static String lookup(String resourceName) {
        String resource = null;

        // 1. Check in the JNDI tree
        Context ctx = null;
        try {
            ctx = (Context) new InitialContext().lookup(JNDI_ENVIRONMENT);
            resource = (String) ctx.lookup(resourceName);
        }
        catch (NamingException ignore) {}

        // 2. Check among system properties
        if (null == resource || resource.length() == 0) {
            System.out.println("Resource \"" + resourceName + "\" not published through JNDI...");
            try {
                resource = System.getProperty(resourceName);
            }
            catch (Exception ignore) {}
        }

        if (null == resource || resource.length() == 0) {
            System.out.println("Resource \"" + resourceName + "\" not published through system properties...");
        }
        return resource;
    }
304562
public DatanodeProtocol getNSNamenode(int namespaceId) throws IOException {
    NamespaceService nsos = namespaceManager.get(namespaceId);
    if(nsos == null || nsos.getDatanodeProtocol() == null) {
      throw new IOException("cannot find a namnode proxy for namespaceId=" + namespaceId);
    }
    return nsos.getDatanodeProtocol();
  }