public Collection resolveTxt()

in core/src/main/java/com/google/cloud/sql/core/JndiDnsResolver.java [57:81]


  public Collection<String> resolveTxt(String domainName)
      throws javax.naming.NameNotFoundException {
    try {
      // Notice: This is old Java 1.2 style code. It uses the ancient JNDI DNS Provider api.
      // See https://docs.oracle.com/javase/7/docs/technotes/guides/jndi/jndi-dns.html

      // Explicitly reference the JNDI DNS classes. This is required for GraalVM.
      Hashtable contextProps = new Hashtable<>();
      contextProps.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory");
      contextProps.put(Context.OBJECT_FACTORIES, "com.sun.jndi.url.dns.dnsURLContextFactory");
      Attribute attr =
          new InitialDirContext(contextProps)
              .getAttributes(jndiPrefix + domainName, new String[] {"TXT"})
              .get("TXT");
      // attr.getAll() returns a Vector containing strings, one for each record returned by dns.
      return Collections.list(attr.getAll()).stream()
          .map((Object v) -> (String) v)
          .sorted() // sort multiple records alphabetically
          .collect(Collectors.toList());
    } catch (NameNotFoundException e) {
      throw e;
    } catch (NamingException e) {
      throw new RuntimeException("Unable to look up domain name " + domainName, e);
    }
  }