Revision 56978
Added by Michele Artini over 4 years ago
HttpFetcher.java | ||
---|---|---|
44 | 44 |
.build()); |
45 | 45 |
|
46 | 46 |
public static String fetch(final String url) throws URISyntaxException { |
47 |
return fetch(new URI(url), MAX_NUMBER_OF_ATTEMPTS);
|
|
47 |
return fetch(new URI(url), 1);
|
|
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
public static String fetch(final URI url) { |
51 |
return fetch(url, MAX_NUMBER_OF_ATTEMPTS);
|
|
51 |
return fetch(url, 1);
|
|
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
public static String fetch(final URI url, final int attempts) { |
55 |
if (attempts == 0) { throw new RuntimeException("Max number of attempts reached, downloading url: " + url); } |
|
55 |
if (attempts > MAX_NUMBER_OF_ATTEMPTS) { |
|
56 |
log.error("Max number of attempts reached, downloading url: " + url); |
|
57 |
return ""; |
|
58 |
} |
|
56 | 59 |
|
57 | 60 |
try { |
61 |
log.debug("Downloading URL: " + url + " - try: " + attempts); |
|
58 | 62 |
return (new RestTemplate(httpRequestFactory)).getForObject(url, String.class); |
59 |
} catch (final Exception e) {
|
|
63 |
} catch (final Throwable e) {
|
|
60 | 64 |
try { |
61 |
log.error("Error downloading url: " + url + " - " + e.getMessage()); |
|
65 |
log.error("Error downloading url: " + url + " - try: " + attempts + " - " + e.getMessage());
|
|
62 | 66 |
Thread.sleep(INTERVAL_MILLIS); |
63 |
return fetch(url, attempts - 1);
|
|
67 |
return fetch(url, attempts + 1);
|
|
64 | 68 |
} catch (final InterruptedException e1) { |
65 |
throw new RuntimeException(e1); |
|
69 |
log.error(e); |
|
70 |
return ""; |
|
66 | 71 |
} |
67 | 72 |
} |
68 | 73 |
} |
Also available in: Unified diff
- failedCallback
- update of dli objects
- WorkAround for duplicated sets from people repository