code: public static URI[] fromDNSName(String srvName) throws NamingException {
      List<URI> uris = new ArrayList<>();
      Hashtable<String, String> env = new Hashtable<>();
      env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
      env.put("java.naming.provider.url", "dns:");
  
      DirContext ctx = new InitialDirContext(env);
      Attributes attributes = ctx.getAttributes(srvName, new String[]{"SRV"});
      NamingEnumeration<? extends Attribute> records = attributes.getAll();
  
      while (records.hasMore()) {
        Attribute next = records.next();
  
        @SuppressWarnings("unchecked")
        NamingEnumeration<String> values = (NamingEnumeration<String>) next.getAll();
        while (values.hasMore()) {
          String dns = values.next();
          String[] split = dns.split(" ");
          String port = split[2];
          String host = split[3];
          if (host.endsWith(".")) {
            host = host.substring(0, host.length() - 1);
          }
          URI uri = URI.create("http://" + host + ":" + port);
          uris.add(uri);
        }
      }
      return uris.toArray(new URI[uris.size()]);
    }
docs: Convert given DNS SRV address to array of URIs
  
  @param srvName complete DNS name to resolve to URIs
  @return Array of URIs
  @throws NamingException if DNS name was invalid