use of org.xbill.DNS.SimpleResolver in project opennms by OpenNMS.
the class DnsProvisioningAdapter method afterPropertiesSet.
/**
* <p>afterPropertiesSet</p>
*
* @throws java.lang.Exception if any.
*/
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(m_nodeDao, "DnsProvisioner requires a NodeDao which is not null.");
// load current nodes into the map
m_template.execute(new TransactionCallbackWithoutResult() {
@Override
public void doInTransactionWithoutResult(TransactionStatus arg0) {
createDnsRecordMap();
}
});
String levelString = System.getProperty("importer.adapter.dns.level");
if (levelString != null) {
Integer level = Integer.getInteger(levelString);
if (level != null && level.intValue() > 0)
m_level = level;
}
String dnsServer = System.getProperty("importer.adapter.dns.server");
if (!StringUtils.isBlank(dnsServer)) {
LOG.info("DNS property found: {}", dnsServer);
if (dnsServer.contains(":")) {
final String[] serverAddress = dnsServer.split(":");
m_resolver = new SimpleResolver(serverAddress[0]);
m_resolver.setPort(Integer.valueOf(serverAddress[1]));
} else {
m_resolver = new SimpleResolver(dnsServer);
}
// Doesn't work for some reason, haven't figured out why yet
String key = System.getProperty("importer.adapter.dns.privatekey");
if (key != null && key.length() > 0) {
m_signature = key;
m_resolver.setTSIGKey(TSIG.fromString(m_signature));
}
} else {
LOG.warn("no DNS server configured, DnsProvisioningAdapter will not do anything!");
}
}
use of org.xbill.DNS.SimpleResolver in project Signal-Android by WhisperSystems.
the class CustomDns method lookup.
@Override
@NonNull
public List<InetAddress> lookup(@NonNull String hostname) throws UnknownHostException {
Resolver resolver = new SimpleResolver(dnsHostname);
Lookup lookup = doLookup(hostname);
lookup.setResolver(resolver);
Record[] records = lookup.run();
if (records != null) {
List<InetAddress> ipv4Addresses = Stream.of(records).filter(r -> r.getType() == Type.A).map(r -> (ARecord) r).map(ARecord::getAddress).toList();
if (ipv4Addresses.size() > 0) {
return ipv4Addresses;
}
}
throw new UnknownHostException(hostname);
}
use of org.xbill.DNS.SimpleResolver in project ecf by eclipse.
the class DnsSdAdvertiserServiceTest method createSRVRecord.
private void createSRVRecord() throws TextParseException, IOException, UnknownHostException {
// create a service manually
final Name zone = Name.fromString(DnsSdTestHelper.REG_DOMAIN + ".");
final Name type = Name.fromString("_" + DnsSdTestHelper.REG_SCHEME + "._" + DnsSdTestHelper.PROTO, zone);
final String s = serviceInfo.getPriority() + " " + serviceInfo.getWeight() + " " + serviceInfo.getLocation().getPort() + " " + serviceInfo.getLocation().getHost() + ".";
final Record record = Record.fromString(type, Type.SRV, DClass.IN, DnsSdTestHelper.TTL, s, zone);
final Update update = new Update(zone);
update.add(record);
final SimpleResolver resolver = new SimpleResolver(DnsSdTestHelper.DNS_SERVER);
resolver.setTCP(true);
resolver.setTSIGKey(new TSIG(DnsSdTestHelper.TSIG_KEY_NAME, DnsSdTestHelper.TSIG_KEY));
final Message response = resolver.send(update);
final int rcode = response.getRcode();
assertTrue("", rcode == 0);
}
use of org.xbill.DNS.SimpleResolver in project ecf by eclipse.
the class DnsSdDiscoveryAdvertiser method connect.
/* (non-Javadoc)
* @see org.eclipse.ecf.provider.dnssd.DnsSdDiscoveryLocator#connect(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.security.IConnectContext)
*/
public void connect(final ID aTargetID, final IConnectContext connectContext) throws ContainerConnectException {
// $NON-NLS-1$ //$NON-NLS-2$
Trace.trace(Activator.PLUGIN_ID, DnsSdDebugOptions.METHODS_TRACING, this.getClass(), "connect(ID aTargetID, IConnectContext connectContext)", "connecting container");
// connect can only be called once
if (targetID != null || getConfig() == null) {
throw new ContainerConnectException(Messages.DnsSdDiscoveryAdvertiser_Container_Already_Connected);
}
// TODO convert non DnsSdServiceTypeIDs into DSTIDs
if (aTargetID == null) {
targetID = new DnsSdServiceTypeID();
} else {
final Namespace ns = getConnectNamespace();
try {
targetID = (DnsSdServiceTypeID) ns.createInstance(new Object[] { aTargetID });
} catch (IDCreateException e) {
throw new ContainerConnectException(e);
}
}
// instantiate a default resolver
if (resolver == null) {
try {
resolver = new SimpleResolver();
resolver.setTCP(true);
} catch (UnknownHostException e) {
throw new ContainerConnectException(e);
}
}
// done setting up this provider, send event
fireContainerEvent(new ContainerConnectingEvent(this.getID(), targetID, connectContext));
fireContainerEvent(new ContainerConnectedEvent(this.getID(), targetID));
}
Aggregations