@SuppressWarnings("PMD.UseStringBufferForStringAppends")
  public static String create(final DNSAccessRecord dnsAccessRecord) {
    final String event = createEvent(dnsAccessRecord);
    String rType = "-";
    String rdtl = "-";
    String rloc = "-";

    if (dnsAccessRecord.getResultType() != null) {
      rType = dnsAccessRecord.getResultType().toString();
      if (dnsAccessRecord.getResultDetails() != null) {
        rdtl = dnsAccessRecord.getResultDetails().toString();
      }
    }

    if (dnsAccessRecord.getResultLocation() != null) {
      final Geolocation resultLocation = dnsAccessRecord.getResultLocation();

      final DecimalFormat decimalFormat = new DecimalFormat(".##");
      decimalFormat.setRoundingMode(RoundingMode.DOWN);
      rloc =
          decimalFormat.format(resultLocation.getLatitude())
              + ","
              + decimalFormat.format(resultLocation.getLongitude());
    }

    final String routingInfo =
        "rtype=" + rType + " rloc=\"" + rloc + "\" rdtl=" + rdtl + " rerr=\"-\"";
    String answer = "ans=\"-\"";

    if (dnsAccessRecord.getDnsMessage() != null) {
      answer = createTTLandAnswer(dnsAccessRecord.getDnsMessage());
    }
    return event + " " + routingInfo + " " + answer;
  }
示例#2
0
 @Test
 public void testIps() {
   try {
     final String testips[][] = {{"40.40.40.40", "cache-group-1"}};
     for (int i = 0; i < testips.length; i++) {
       Geolocation location = maxmindGeolocationService.location(testips[i][0]);
       Assert.assertNotNull(location);
       String loc = location.toString();
       LOGGER.info(String.format("result for ip=%s: %s\n", testips[i], loc));
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }