org.xbill.DNS.SRVRecord Java Examples

The following examples show how to use org.xbill.DNS.SRVRecord. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XBillDnsSrvResolver.java    From dns-java with Apache License 2.0 6 votes vote down vote up
private static List<LookupResult> toLookupResults(Record[] queryResult) {
  ImmutableList.Builder<LookupResult> builder = ImmutableList.builder();

  if (queryResult != null) {
    for (Record record: queryResult) {
      if (record instanceof SRVRecord) {
        SRVRecord srvRecord = (SRVRecord) record;
        builder.add(LookupResult.create(srvRecord.getTarget().toString(),
                                        srvRecord.getPort(),
                                        srvRecord.getPriority(),
                                        srvRecord.getWeight(),
                                        srvRecord.getTTL()));
      }
    }
  }

  return builder.build();
}
 
Example #2
Source File: XBillDnsSrvResolverTest.java    From dns-java with Apache License 2.0 6 votes vote down vote up
private Message messageWithNodes(String query, String[] names) throws TextParseException {
  Name queryName = Name.fromString(query);
  Record question = Record.newRecord(queryName, Type.SRV, DClass.IN);
  Message queryMessage = Message.newQuery(question);
  Message result = new Message();
  result.setHeader(queryMessage.getHeader());
  result.addRecord(question, Section.QUESTION);

  for (String name1 : names) {
    result.addRecord(
        new SRVRecord(queryName, DClass.IN, 1, 1, 1, 8080, Name.fromString(name1)),
        Section.ANSWER);
  }

  return result;
}
 
Example #3
Source File: DNSServiceAddressResolver.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private String dnsSrvLookup(String query) throws ServiceAddressResolvingException {
    String result;
    try {
        Record[] records = new Lookup(query, Type.SRV).run();
        if (records != null && records.length > 0) {
            SRVRecord srv = (SRVRecord) records[0];
            result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort();
        } else {
            throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved");
        }
    } catch (TextParseException e) {
        throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e);
    }
    return result;
}
 
Example #4
Source File: DNSServiceAddressResolver.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private String dnsSrvLookup(String query) throws ServiceAddressResolvingException {
    String result;
    try {
        Record[] records = new Lookup(query, Type.SRV).run();
        if (records != null && records.length > 0) {
            SRVRecord srv = (SRVRecord) records[0];
            result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort();
        } else {
            throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved");
        }
    } catch (TextParseException e) {
        throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e);
    }
    return result;
}
 
Example #5
Source File: DNSServiceAddressResolver.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private String dnsSrvLookup(String query) throws ServiceAddressResolvingException {
    String result;
    try {
        Record[] records = new Lookup(query, Type.SRV).run();
        if (records != null && records.length > 0) {
            SRVRecord srv = (SRVRecord) records[0];
            result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort();
        } else {
            throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved");
        }
    } catch (TextParseException e) {
        throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e);
    }
    return result;
}
 
Example #6
Source File: DNSServiceAddressResolver.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private String dnsSrvLookup(String query) {
    String result;
    try {
        Record[] records = new Lookup(query, Type.SRV).run();
        if (records != null && records.length > 0) {
            SRVRecord srv = (SRVRecord) records[0];
            result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort();
        } else {
            throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved");
        }
    } catch (TextParseException e) {
        throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e);
    }
    return result;
}
 
Example #7
Source File: DNSServiceAddressResolver.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private String dnsSrvLookup(String query) throws ServiceAddressResolvingException {
    String result;
    try {
        Record[] records = new Lookup(query, Type.SRV).run();
        if (records != null && records.length > 0) {
            SRVRecord srv = (SRVRecord) records[0];
            result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort();
        } else {
            throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved");
        }
    } catch (TextParseException e) {
        throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e);
    }
    return result;
}
 
Example #8
Source File: DNSServiceAddressResolver.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private String dnsSrvLookup(String query) throws ServiceAddressResolvingException {
    String result;
    try {
        Record[] records = new Lookup(query, Type.SRV).run();
        if (records != null && records.length > 0) {
            SRVRecord srv = (SRVRecord) records[0];
            result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort();
        } else {
            throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved");
        }
    } catch (TextParseException e) {
        throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e);
    }
    return result;
}
 
Example #9
Source File: ConnectionWrapper.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
private LDAPConnection createConnection() throws LDAPException {
	LDAPConnection ldapcon = null;
	switch (interceptor.type) {
		case LDAPS :
					if (this.interceptor.getSocketFactory() == null) {
						
						ldapcon = new LDAPConnection(new LDAPJSSESecureSocketFactory());
					} else {
						
						ldapcon = new LDAPConnection(new LDAPJSSESecureSocketFactory(this.interceptor.getSocketFactory().getSSLSocketFactory()));
					}
			//ldapcon = new LDAPConnection();
					break;
					
		case LDAP : ldapcon = new LDAPConnection();
		            break;
		case DSMLV2 : DsmlConnection con = new DsmlConnection();
					  con.setUseSoap(interceptor.isSoap);
					  ldapcon = con;
					  break;
		case SPML : SPMLConnection spml = new SPMLConnection(interceptor.spmlImpl);
					ldapcon = spml;
					break;
		
	}
	
	this.lastAccessed = System.currentTimeMillis();
	
	if (ldapcon == null) {
		return null;
	} else {
		String host = this.interceptor.host;

		if (this.interceptor.useSrvDNS) {
			Record[] records;
			try {
				records = new Lookup(host, Type.SRV).run();
			} catch (TextParseException e) {
				throw new LDAPException(LDAPException.resultCodeToString(LDAPException.OPERATIONS_ERROR),LDAPException.OPERATIONS_ERROR,"Could not lookup srv",e);
			}
			if (records == null) {
				throw new LDAPException("No SRV records",LDAPException.OPERATIONS_ERROR,"");
			}
			SRVRecord srv = (SRVRecord) records[0];
			host = srv.getTarget().toString();
		}

		ldapcon.connect(host,this.interceptor.port);
		return ldapcon;
	}
}