コード例 #1
0
  /** {@inheritDoc} */
  public void print(DnsRecord record) {
    if (record == null) {
      writer.println("Null Resource Record");
      return;
    }

    writer.println("-----------");
    print("Record Name", record.getName());
    print("Type", typeToString(record.getType()));
    print("TTL", String.valueOf(record.getTtl()));
    switch (record.getType()) {
      default:
        break;

      case Type.A:
        print((ARecord) toRecord(record));
        break;

      case Type.SOA:
        print((SOARecord) toRecord(record));
        break;

      case Type.MX:
        print((MXRecord) toRecord(record));
        break;

      case Type.CERT:
        print((CERTRecord) toRecord(record));
        break;
    }

    writer.flush();
  }
コード例 #2
0
  /*
   * Look for SOA records corresponding to the request
   * TODO: Add cache coherency to SOA records?
   */
  protected synchronized Record checkForSoaRecord(String questionName) {
    if (!questionName.endsWith(".")) questionName += ".";

    if (soaRecords == null) {
      DnsRecord[] getRecs = null;
      // load all SOA records...
      try {
        getRecs = proxy.getDNSByType(Type.SOA);

        if (getRecs == null || getRecs.length == 0) soaRecords = Collections.emptyMap();
        else {
          soaRecords = new HashMap<String, Record>();

          for (DnsRecord rec : getRecs) {
            Record newRec =
                Record.newRecord(
                    Name.fromString(rec.getName()),
                    Type.SOA,
                    rec.getDclass(),
                    rec.getTtl(),
                    rec.getData());

            soaRecords.put(newRec.getName().toString(), newRec);
          }
        }
      } catch (Exception e) {
        LOGGER.error("Failed to load SOA records from config service.");
      }
    }

    Record retVal = null;
    if (soaRecords.size() > 0) {
      // look for the record by question name

      retVal = soaRecords.get(questionName);
      if (retVal == null) {
        // start taking apart the question name . by .
        int index = -1;
        while ((index = questionName.indexOf(".")) > 0 && index < (questionName.length() - 1)) {
          questionName = questionName.substring(index + 1);
          retVal = soaRecords.get(questionName);
          if (retVal != null) break;
        }
      }
    }

    return retVal;
  }
コード例 #3
0
ファイル: DNSRecordUtil.java プロジェクト: DM-TOR/nhin-d
  private static DnsRecord toDnsRecord(DNSRecord rec) {
    DnsRecord retVal = new DnsRecord();

    retVal.setData(rec.getData());
    retVal.setDclass(rec.getDclass());
    retVal.setName(rec.getName());
    retVal.setTtl(rec.getTtl());
    retVal.setType(rec.getType());

    return retVal;
  }
コード例 #4
0
  protected Collection<Record> processGenericANYRecordRequest(String name) throws DNSException {
    DnsRecord records[];

    try {
      records = proxy.getDNSByNameAndType(name, Type.ANY);
    } catch (Exception e) {
      throw new DNSException(
          DNSError.newError(Rcode.SERVFAIL),
          "DNS service proxy call for DNS records failed: " + e.getMessage(),
          e);
    }

    if (records == null || records.length == 0) return null;

    Collection<Record> retVal = new ArrayList<Record>();
    try {
      for (DnsRecord record : records) {
        Record rec =
            Record.newRecord(
                Name.fromString(record.getName()),
                record.getType(),
                record.getDclass(),
                record.getTtl(),
                record.getData());

        retVal.add(rec);
      }
    } catch (Exception e) {
      throw new DNSException(
          DNSError.newError(Rcode.SERVFAIL),
          "Failure while parsing generic record data: " + e.getMessage(),
          e);
    }

    return retVal;
  }
コード例 #5
0
 /*
  * converts a configuration service DnsRecord to a dnsjava Record
  */
 private Record toRecord(DnsRecord rec) {
   return Record.newRecord(
       nameFromString(rec.getName()), rec.getType(), rec.getDclass(), rec.getTtl(), rec.getData());
 }