Skip to content

Commit

Permalink
feat: enhance BrokenHttpLinksCheckerSpec to resolve from a list of ho…
Browse files Browse the repository at this point in the history
…stnames

- progress towards fixing #331
  • Loading branch information
RehanChalana committed Oct 13, 2024
1 parent b2a1fa9 commit a330dbe
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;

public class CustomHostNameResolver {

public static final String WIREMOCK_HOST = "my.custom.mocked.host";

private static Object originalResolver;

private static final List<String> hostnames = Arrays.asList(
"www.amazon.com",
"google.com",
"junit.org",
"plumelib.org",
"people.csail.mit.edu",
"arc42.org",
"mock.codes"
);

static {
try {
Field implField = InetAddress.class.getDeclaredField("impl");
Expand All @@ -21,7 +33,7 @@ public class CustomHostNameResolver {

public InetAddress[] resolve(String hostname) throws UnknownHostException {
// Custom DNS resolution logic
if (WIREMOCK_HOST.equals(hostname)) {
if (hostnames.contains(hostname)) {
return new InetAddress[]{InetAddress.getByAddress("localhost", new byte[]{127, 0, 0, 1})};
}
// Fallback to original resolver using reflection
Expand Down

0 comments on commit a330dbe

Please sign in to comment.