Fix DNS lookup
This commit is contained in:
@@ -46,10 +46,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.xbill.DNS.Lookup;
|
import org.xbill.DNS.*;
|
||||||
import org.xbill.DNS.SRVRecord;
|
|
||||||
import org.xbill.DNS.TextParseException;
|
|
||||||
import org.xbill.DNS.Type;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
@@ -130,10 +127,19 @@ public class InvitationManager {
|
|||||||
log.info("Lookup name: {}", lookupDns);
|
log.info("Lookup name: {}", lookupDns);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SRVRecord[] records = (SRVRecord[]) new Lookup(lookupDns, Type.SRV).run();
|
List<SRVRecord> srvRecords = new ArrayList<>();
|
||||||
if (records != null) {
|
Record[] rawRecords = new Lookup(lookupDns, Type.SRV).run();
|
||||||
Arrays.sort(records, Comparator.comparingInt(SRVRecord::getPriority));
|
if (rawRecords != null && rawRecords.length > 0) {
|
||||||
for (SRVRecord record : records) {
|
for (Record record : rawRecords) {
|
||||||
|
if (Type.SRV == record.getType()) {
|
||||||
|
srvRecords.add((SRVRecord) record);
|
||||||
|
} else {
|
||||||
|
log.info("Got non-SRV record: {}", record.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
srvRecords.sort(Comparator.comparingInt(SRVRecord::getPriority));
|
||||||
|
for (SRVRecord record : srvRecords) {
|
||||||
log.info("Found SRV record: {}", record.toString());
|
log.info("Found SRV record: {}", record.toString());
|
||||||
return "https://" + record.getTarget().toString(true) + ":" + record.getPort();
|
return "https://" + record.getTarget().toString(true) + ":" + record.getPort();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user