diff --git a/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java b/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java index c5497c2b2..168a51fc9 100644 --- a/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java +++ b/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java @@ -37,12 +37,12 @@ * This tests all the href attribute in ALL the rules every time the tests are executed (PR and nightly builds) * Helpful to ensure we have always links that points to something so that links are really helpful for the user * Optimized with a very basic cache for not checking more than once the same URL - * + *
* The runTestsMatching is available in this test - * + *
* To change the connection timeout use the standard "-Dsun.net.client.defaultConnectTimeout=
* To quickly see the debug log, execute the test with the property "-Dorg.slf4j.simpleLogger.log.org.jboss.windup=debug"
*/
@RunWith(Parameterized.class)
@@ -158,30 +158,31 @@ private boolean isValidLink(final String link)
if (CERT_FAILURE_LINKS.contains(link))
return true;
- try {
- final long starTime = System.currentTimeMillis();
- int returnCode = 0;
- if (!CACHE_ANALYZED_LINKS.containsKey(link))
- {
- for (int retry = 0; !ACCEPTED_RESPONSE_CODE.contains(returnCode) && retry < RETRIES; retry++) {
- if (retry > 0) LOG.warn(String.format("Tentative #%d to connect to %s", retry + 1, link));
+ final long starTime = System.currentTimeMillis();
+ int returnCode = 0;
+ if (!CACHE_ANALYZED_LINKS.containsKey(link)) {
+ for (int retry = 0; !ACCEPTED_RESPONSE_CODE.contains(returnCode) && retry < RETRIES; retry++) {
+ if (retry > 0) LOG.warn(String.format("Tentative #%d to connect to %s", retry + 1, link));
+ try {
final URL url = new URL(link);
final HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
// property name from https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html
urlConn.setConnectTimeout(Integer.getInteger("sun.net.client.defaultConnectTimeout", 5000));
+ urlConn.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0");
urlConn.connect();
returnCode = urlConn.getResponseCode();
+ } catch (IOException e) {
+ LOG.error(String.format("'%s' exception connecting to %s", e.getMessage(), link), e);
}
- CACHE_ANALYZED_LINKS.put(link, returnCode);
}
- final boolean validLink = ACCEPTED_RESPONSE_CODE.contains(CACHE_ANALYZED_LINKS.get(link));
- if (validLink) LOG.debug(String.format("Response code %d for %s [%dms]", CACHE_ANALYZED_LINKS.get(link), link, System.currentTimeMillis() - starTime));
- else LOG.error(String.format("Response code %d for %s [%dms]", CACHE_ANALYZED_LINKS.get(link), link, System.currentTimeMillis() - starTime));
- return validLink;
- } catch (IOException e) {
- LOG.error(String.format("'%s' exception connecting to %s", e.getMessage(), link), e);
- return false;
+ CACHE_ANALYZED_LINKS.put(link, returnCode);
}
+ final boolean validLink = ACCEPTED_RESPONSE_CODE.contains(CACHE_ANALYZED_LINKS.get(link));
+ if (validLink)
+ LOG.debug(String.format("Response code %d for %s [%dms]", CACHE_ANALYZED_LINKS.get(link), link, System.currentTimeMillis() - starTime));
+ else
+ LOG.error(String.format("Response code %d for %s [%dms]", CACHE_ANALYZED_LINKS.get(link), link, System.currentTimeMillis() - starTime));
+ return validLink;
}
private String buildListOfFailedRulesLinks(final Map