1 package org.apache.maven.wagon.shared.http;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.http.HttpResponse;
23 import org.apache.http.HttpStatus;
24 import org.apache.http.annotation.Contract;
25 import org.apache.http.annotation.ThreadingBehavior;
26 import org.apache.http.client.ServiceUnavailableRetryStrategy;
27 import org.apache.http.protocol.HttpContext;
28 import org.apache.http.util.Args;
29
30
31
32
33
34
35 @Contract( threading = ThreadingBehavior.IMMUTABLE )
36 public class StandardServiceUnavailableRetryStrategy implements ServiceUnavailableRetryStrategy
37 {
38
39
40
41
42 private final int maxRetries;
43
44
45
46
47 private final long retryInterval;
48
49 public StandardServiceUnavailableRetryStrategy( final int maxRetries, final int retryInterval )
50 {
51 super();
52 Args.positive( maxRetries, "Max retries" );
53 Args.positive( retryInterval, "Retry interval" );
54 this.maxRetries = maxRetries;
55 this.retryInterval = retryInterval;
56 }
57
58 @Override
59 public boolean retryRequest( final HttpResponse response, final int executionCount, final HttpContext context )
60 {
61 int statusCode = response.getStatusLine().getStatusCode();
62 boolean retryableStatusCode = statusCode == HttpStatus.SC_REQUEST_TIMEOUT
63
64 || statusCode == AbstractHttpClientWagon.SC_TOO_MANY_REQUESTS
65
66 || statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR
67 || statusCode == HttpStatus.SC_BAD_GATEWAY
68 || statusCode == HttpStatus.SC_SERVICE_UNAVAILABLE
69 || statusCode == HttpStatus.SC_GATEWAY_TIMEOUT;
70 return executionCount <= maxRetries && retryableStatusCode;
71 }
72
73 @Override
74 public long getRetryInterval()
75 {
76 return retryInterval;
77 }
78
79 }