Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include IOException in the retry mechanism #1052

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
* <p>
* The runTestsMatching is available in this test
*
* <p>
* To change the connection timeout use the standard "-Dsun.net.client.defaultConnectTimeout=<value>" property
* from https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html
*
* <p>
* To quickly see the debug log, execute the test with the property "-Dorg.slf4j.simpleLogger.log.org.jboss.windup=debug"
*/
@RunWith(Parameterized.class)
Expand Down Expand Up @@ -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<String, List<String>> failedRulesWithLinks)
Expand Down
Loading