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 aim42#331
  • Loading branch information
RehanChalana committed Oct 12, 2024
1 parent 076194d commit 1a5af1e
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 1a5af1e

Please sign in to comment.