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 ; }
Looks up the DNS name provided in the JNDI context .