|
36 | 36 | import java.net.HttpURLConnection; |
37 | 37 | import java.net.MalformedURLException; |
38 | 38 | import java.net.ProtocolException; |
| 39 | +import java.net.SocketTimeoutException; |
39 | 40 | import java.net.URL; |
40 | 41 | import java.net.URLEncoder; |
41 | 42 | import java.util.ArrayList; |
|
57 | 58 | import org.apache.commons.lang.StringUtils; |
58 | 59 |
|
59 | 60 | import static java.util.Arrays.asList; |
| 61 | +import java.util.logging.Level; |
60 | 62 | import static java.util.logging.Level.*; |
61 | 63 | import static org.kohsuke.github.GitHub.MAPPER; |
62 | 64 |
|
@@ -579,6 +581,10 @@ private void setRequestMethod(HttpURLConnection uc) throws IOException { |
579 | 581 | } |
580 | 582 |
|
581 | 583 | private <T> T parse(Class<T> type, T instance) throws IOException { |
| 584 | + return parse(type, instance, 2); |
| 585 | + } |
| 586 | + |
| 587 | + private <T> T parse(Class<T> type, T instance, int timeouts) throws IOException { |
582 | 588 | InputStreamReader r = null; |
583 | 589 | int responseCode = -1; |
584 | 590 | String responseMessage = null; |
@@ -609,6 +615,10 @@ private <T> T parse(Class<T> type, T instance) throws IOException { |
609 | 615 | // to preserve backward compatibility |
610 | 616 | throw e; |
611 | 617 | } catch (IOException e) { |
| 618 | + if (e instanceof SocketTimeoutException && timeouts > 0) { |
| 619 | + LOGGER.log(Level.INFO, "timed out accessing " + uc.getURL() + "; will try " + timeouts + " more time(s)", e); |
| 620 | + return parse(type, instance, timeouts - 1); |
| 621 | + } |
612 | 622 | throw new HttpException(responseCode, responseMessage, uc.getURL(), e); |
613 | 623 | } finally { |
614 | 624 | IOUtils.closeQuietly(r); |
|
0 commit comments