• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk / #5762

01 Dec 2025 10:27AM UTC coverage: 13.282% (-0.02%) from 13.3%
#5762

push

github

web-flow
feat(boxsdkgen): Support new sign request metadata (box/box-openapi#565) (#1598)

0 of 48 new or added lines in 3 files covered. (0.0%)

15 existing lines in 9 files now uncovered.

8368 of 63001 relevant lines covered (13.28%)

0.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/box/sdkgen/networking/retries/BoxRetryStrategy.java
1
package com.box.sdkgen.networking.retries;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.random;
4

5
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
6
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
7

8
public class BoxRetryStrategy implements RetryStrategy {
9

10
  public int maxAttempts;
11

12
  public double retryRandomizationFactor;
13

14
  public double retryBaseInterval;
15

16
  public int maxRetriesOnException;
17

18
  public BoxRetryStrategy() {
×
19
    this.maxAttempts = 5;
×
20
    this.retryRandomizationFactor = 0.5;
×
21
    this.retryBaseInterval = 1;
×
22
    this.maxRetriesOnException = 2;
×
23
  }
×
24

25
  protected BoxRetryStrategy(Builder builder) {
×
26
    this.maxAttempts = builder.maxAttempts;
×
27
    this.retryRandomizationFactor = builder.retryRandomizationFactor;
×
28
    this.retryBaseInterval = builder.retryBaseInterval;
×
29
    this.maxRetriesOnException = builder.maxRetriesOnException;
×
30
  }
×
31

32
  @Override
33
  public boolean shouldRetry(
34
      FetchOptions fetchOptions, FetchResponse fetchResponse, int attemptNumber) {
35
    if (fetchResponse.getStatus() == 0) {
×
36
      return attemptNumber <= this.maxRetriesOnException;
×
37
    }
38
    boolean isSuccessful = fetchResponse.getStatus() >= 200 && fetchResponse.getStatus() < 400;
×
UNCOV
39
    String retryAfterHeader =
×
40
        (fetchResponse.getHeaders().containsKey("Retry-After")
×
41
            ? fetchResponse.getHeaders().get("Retry-After")
×
42
            : null);
43
    boolean isAcceptedWithRetryAfter =
×
44
        fetchResponse.getStatus() == 202 && !(retryAfterHeader == null);
×
45
    if (attemptNumber >= this.maxAttempts) {
×
46
      return false;
×
47
    }
48
    if (isAcceptedWithRetryAfter) {
×
49
      return true;
×
50
    }
51
    if (fetchResponse.getStatus() >= 500) {
×
52
      return true;
×
53
    }
54
    if (fetchResponse.getStatus() == 429) {
×
55
      return true;
×
56
    }
57
    if (fetchResponse.getStatus() == 401 && !(fetchOptions.getAuth() == null)) {
×
58
      fetchOptions.getAuth().refreshToken(fetchOptions.getNetworkSession());
×
59
      return true;
×
60
    }
61
    if (isSuccessful) {
×
62
      return false;
×
63
    }
64
    return false;
×
65
  }
66

67
  @Override
68
  public double retryAfter(
69
      FetchOptions fetchOptions, FetchResponse fetchResponse, int attemptNumber) {
70
    String retryAfterHeader = fetchResponse.getHeaders().get("Retry-After");
×
71
    if (!(retryAfterHeader == null)) {
×
72
      return Double.parseDouble(retryAfterHeader);
×
73
    }
74
    double randomization =
×
75
        random(1 - this.retryRandomizationFactor, 1 + this.retryRandomizationFactor);
×
76
    double exponential = Math.pow(2, attemptNumber);
×
77
    return exponential * this.retryBaseInterval * randomization;
×
78
  }
79

80
  public int getMaxAttempts() {
81
    return maxAttempts;
×
82
  }
83

84
  public double getRetryRandomizationFactor() {
85
    return retryRandomizationFactor;
×
86
  }
87

88
  public double getRetryBaseInterval() {
89
    return retryBaseInterval;
×
90
  }
91

92
  public int getMaxRetriesOnException() {
93
    return maxRetriesOnException;
×
94
  }
95

96
  public static class Builder {
97

98
    protected int maxAttempts;
99

100
    protected double retryRandomizationFactor;
101

102
    protected double retryBaseInterval;
103

104
    protected int maxRetriesOnException;
105

106
    public Builder() {
×
107
      this.maxAttempts = 5;
×
108
      this.retryRandomizationFactor = 0.5;
×
109
      this.retryBaseInterval = 1;
×
110
      this.maxRetriesOnException = 2;
×
111
    }
×
112

113
    public Builder maxAttempts(int maxAttempts) {
114
      this.maxAttempts = maxAttempts;
×
115
      return this;
×
116
    }
117

118
    public Builder retryRandomizationFactor(double retryRandomizationFactor) {
119
      this.retryRandomizationFactor = retryRandomizationFactor;
×
120
      return this;
×
121
    }
122

123
    public Builder retryBaseInterval(double retryBaseInterval) {
124
      this.retryBaseInterval = retryBaseInterval;
×
125
      return this;
×
126
    }
127

128
    public Builder maxRetriesOnException(int maxRetriesOnException) {
129
      this.maxRetriesOnException = maxRetriesOnException;
×
130
      return this;
×
131
    }
132

133
    public BoxRetryStrategy build() {
134
      return new BoxRetryStrategy(this);
×
135
    }
136
  }
137
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc