Skip to content

Commit

Permalink
RESTful service to verify DNS lookup #4242
Browse files Browse the repository at this point in the history
  • Loading branch information
gunterze committed Oct 2, 2023
1 parent ae85294 commit b90d5a1
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.InetAddress;
Expand Down Expand Up @@ -92,25 +93,27 @@ public Response listHosts(@PathParam("host") String host) {
}

private static StreamingOutput entity(InetAddress[] inetAddresses, long lookupTime) {
return out -> {
try (JsonGenerator gen = Json.createGenerator(out)) {
return out -> writeTo(inetAddresses, lookupTime, out);
}

private static void writeTo(InetAddress[] inetAddresses, long lookupTime, OutputStream out) {
try (JsonGenerator gen = Json.createGenerator(out)) {
gen.writeStartObject();
gen.write("dnsLookupTime", lookupTime);
gen.writeStartArray("hosts");
for (InetAddress inetAddress : inetAddresses) {
long startRDNSLookup = System.currentTimeMillis();
String hostName = inetAddress.getHostName();
long endRDNSLookup = System.currentTimeMillis();
gen.writeStartObject();
gen.write("dnsLookupTime", lookupTime);
gen.writeStartArray("hosts");
for (InetAddress inetAddress : inetAddresses) {
long startRDNSLookup = System.currentTimeMillis();
String hostName = inetAddress.getHostName();
long endRDNSLookup = System.currentTimeMillis();
gen.writeStartObject();
gen.write("rdnsLookupTime", endRDNSLookup - startRDNSLookup);
gen.write("hostName", hostName);
gen.write("hostAddress", inetAddress.getHostAddress());
gen.writeEnd();
}
gen.writeEnd();
gen.write("rdnsLookupTime", endRDNSLookup - startRDNSLookup);
gen.write("hostName", hostName);
gen.write("hostAddress", inetAddress.getHostAddress());
gen.writeEnd();
}
};
gen.writeEnd();
gen.writeEnd();
}
}

private void logRequest() {
Expand Down

0 comments on commit b90d5a1

Please sign in to comment.