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

box / box-java-sdk-gen / #549

15 Sep 2025 01:34PM UTC coverage: 36.587% (+0.03%) from 36.559%
#549

Pull #447

github

web-flow
Merge 1db8d3e87 into 58a40fe53
Pull Request #447: feat: Add proxy support (box/box-codegen#822)

9 of 71 new or added lines in 4 files covered. (12.68%)

3 existing lines in 1 file now uncovered.

18376 of 50226 relevant lines covered (36.59%)

0.37 hits per line

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

64.75
/src/main/java/com/box/sdkgen/networking/network/NetworkSession.java
1
package com.box.sdkgen.networking.network;
2

3
import com.box.sdkgen.box.errors.BoxSDKError;
4
import com.box.sdkgen.internal.logging.DataSanitizer;
5
import com.box.sdkgen.networking.baseurls.BaseUrls;
6
import com.box.sdkgen.networking.boxnetworkclient.BoxNetworkClient;
7
import com.box.sdkgen.networking.interceptors.Interceptor;
8
import com.box.sdkgen.networking.networkclient.NetworkClient;
9
import com.box.sdkgen.networking.proxyconfig.ProxyConfig;
10
import com.box.sdkgen.networking.retries.BoxRetryStrategy;
11
import com.box.sdkgen.networking.retries.RetryStrategy;
12
import java.util.ArrayList;
13
import java.util.HashMap;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.stream.Collectors;
17
import java.util.stream.Stream;
18

19
public class NetworkSession {
20
  protected Map<String, String> additionalHeaders = new HashMap<>();
1✔
21

22
  protected BaseUrls baseUrls = new BaseUrls();
1✔
23

24
  protected List<Interceptor> interceptors = new ArrayList<>();
1✔
25

26
  protected NetworkClient networkClient;
27

28
  protected RetryStrategy retryStrategy;
29

30
  protected DataSanitizer dataSanitizer;
31

32
  protected ProxyConfig proxyConfig;
33

34
  public NetworkSession() {
1✔
35
    networkClient = new BoxNetworkClient();
1✔
36
    retryStrategy = new BoxRetryStrategy();
1✔
37
    dataSanitizer = new DataSanitizer();
1✔
38
  }
1✔
39

40
  protected NetworkSession(Builder builder) {
1✔
41
    this.additionalHeaders = builder.additionalHeaders;
1✔
42
    this.baseUrls = builder.baseUrls;
1✔
43
    this.networkClient = builder.networkClient;
1✔
44
    this.interceptors = builder.interceptors;
1✔
45
    this.retryStrategy = builder.retryStrategy;
1✔
46
    this.dataSanitizer = builder.dataSanitizer;
1✔
47
    this.proxyConfig = builder.proxyConfig;
1✔
48
  }
1✔
49

50
  public NetworkSession withAdditionalHeaders() {
51
    return withAdditionalHeaders(new HashMap<>());
×
52
  }
53

54
  public NetworkSession withAdditionalHeaders(Map<String, String> additionalHeaders) {
55
    Map<String, String> newHeaders = new HashMap<>();
1✔
56
    newHeaders.putAll(this.additionalHeaders);
1✔
57
    newHeaders.putAll(additionalHeaders);
1✔
58
    return new NetworkSession.Builder()
1✔
59
        .additionalHeaders(newHeaders)
1✔
60
        .baseUrls(this.baseUrls)
1✔
61
        .interceptors(this.interceptors)
1✔
62
        .networkClient(this.networkClient)
1✔
63
        .retryStrategy(this.retryStrategy)
1✔
64
        .dataSanitizer(this.dataSanitizer)
1✔
65
        .proxyConfig(this.proxyConfig)
1✔
66
        .build();
1✔
67
  }
68

69
  public NetworkSession withCustomBaseUrls(BaseUrls baseUrls) {
70
    return new Builder()
1✔
71
        .additionalHeaders(this.additionalHeaders)
1✔
72
        .baseUrls(baseUrls)
1✔
73
        .interceptors(this.interceptors)
1✔
74
        .networkClient(this.networkClient)
1✔
75
        .retryStrategy(this.retryStrategy)
1✔
76
        .dataSanitizer(this.dataSanitizer)
1✔
77
        .proxyConfig(this.proxyConfig)
1✔
78
        .build();
1✔
79
  }
80

81
  public NetworkSession withInterceptors(List<Interceptor> interceptors) {
82
    List<Interceptor> newInterceptors =
1✔
83
        Stream.concat(this.interceptors.stream(), interceptors.stream())
1✔
84
            .collect(Collectors.toList());
1✔
85
    return new Builder()
1✔
86
        .additionalHeaders(this.additionalHeaders)
1✔
87
        .baseUrls(this.baseUrls)
1✔
88
        .interceptors(newInterceptors)
1✔
89
        .networkClient(this.networkClient)
1✔
90
        .retryStrategy(this.retryStrategy)
1✔
91
        .dataSanitizer(this.dataSanitizer)
1✔
92
        .proxyConfig(this.proxyConfig)
1✔
93
        .build();
1✔
94
  }
95

96
  public NetworkSession withNetworkClient(NetworkClient networkClient) {
97
    return new Builder()
×
98
        .additionalHeaders(this.additionalHeaders)
×
99
        .baseUrls(this.baseUrls)
×
100
        .interceptors(this.interceptors)
×
101
        .networkClient(networkClient)
×
102
        .retryStrategy(this.retryStrategy)
×
NEW
103
        .dataSanitizer(this.dataSanitizer)
×
NEW
104
        .proxyConfig(this.proxyConfig)
×
UNCOV
105
        .build();
×
106
  }
107

108
  public NetworkSession withRetryStrategy(RetryStrategy retryStrategy) {
109
    return new Builder()
×
110
        .additionalHeaders(this.additionalHeaders)
×
111
        .baseUrls(this.baseUrls)
×
112
        .interceptors(this.interceptors)
×
113
        .networkClient(this.networkClient)
×
114
        .retryStrategy(retryStrategy)
×
NEW
115
        .dataSanitizer(this.dataSanitizer)
×
NEW
116
        .proxyConfig(this.proxyConfig)
×
UNCOV
117
        .build();
×
118
  }
119

120
  public NetworkSession withDataSanitizer(DataSanitizer dataSanitizer) {
121
    return new Builder()
×
122
        .additionalHeaders(this.additionalHeaders)
×
123
        .baseUrls(this.baseUrls)
×
124
        .interceptors(this.interceptors)
×
125
        .networkClient(this.networkClient)
×
126
        .retryStrategy(this.retryStrategy)
×
127
        .dataSanitizer(dataSanitizer)
×
NEW
128
        .proxyConfig(this.proxyConfig)
×
NEW
129
        .build();
×
130
  }
131

132
  public NetworkSession withProxy(ProxyConfig config) {
NEW
133
    if (config == null) {
×
NEW
134
      throw new IllegalArgumentException("ProxyConfig cannot be null");
×
135
    }
NEW
136
    if (!(this.networkClient instanceof BoxNetworkClient)) {
×
NEW
137
      throw new BoxSDKError("Proxies are only supported for BoxNetworkClient");
×
138
    }
NEW
139
    BoxNetworkClient newClient = ((BoxNetworkClient) this.networkClient).withProxy(config);
×
NEW
140
    return new Builder()
×
NEW
141
        .additionalHeaders(this.additionalHeaders)
×
NEW
142
        .baseUrls(this.baseUrls)
×
NEW
143
        .interceptors(this.interceptors)
×
NEW
144
        .networkClient(newClient)
×
NEW
145
        .retryStrategy(this.retryStrategy)
×
NEW
146
        .dataSanitizer(this.dataSanitizer)
×
NEW
147
        .proxyConfig(config)
×
UNCOV
148
        .build();
×
149
  }
150

151
  public Map<String, String> getAdditionalHeaders() {
152
    return additionalHeaders;
1✔
153
  }
154

155
  public BaseUrls getBaseUrls() {
156
    return baseUrls;
1✔
157
  }
158

159
  public NetworkClient getNetworkClient() {
160
    return networkClient;
1✔
161
  }
162

163
  public List<Interceptor> getInterceptors() {
164
    return interceptors;
1✔
165
  }
166

167
  public RetryStrategy getRetryStrategy() {
168
    return retryStrategy;
1✔
169
  }
170

171
  public DataSanitizer getDataSanitizer() {
172
    return dataSanitizer;
1✔
173
  }
174

175
  public ProxyConfig getProxyConfig() {
NEW
176
    return proxyConfig;
×
177
  }
178

179
  public static class Builder {
180

181
    protected Map<String, String> additionalHeaders = new HashMap<>();
1✔
182

183
    protected BaseUrls baseUrls = new BaseUrls();
1✔
184

185
    protected NetworkClient networkClient;
186

187
    protected List<Interceptor> interceptors = new ArrayList<>();
1✔
188

189
    protected RetryStrategy retryStrategy;
190

191
    protected DataSanitizer dataSanitizer;
192

193
    protected ProxyConfig proxyConfig;
194

195
    public Builder() {
1✔
196
      networkClient = new BoxNetworkClient();
1✔
197
      retryStrategy = new BoxRetryStrategy();
1✔
198
      dataSanitizer = new DataSanitizer();
1✔
199
    }
1✔
200

201
    public Builder additionalHeaders(Map<String, String> additionalHeaders) {
202
      this.additionalHeaders = additionalHeaders;
1✔
203
      return this;
1✔
204
    }
205

206
    public Builder baseUrls(BaseUrls baseUrls) {
207
      this.baseUrls = baseUrls;
1✔
208
      return this;
1✔
209
    }
210

211
    public Builder networkClient(NetworkClient networkClient) {
212
      this.networkClient = networkClient;
1✔
213
      return this;
1✔
214
    }
215

216
    public Builder interceptors(List<Interceptor> interceptors) {
217
      this.interceptors = interceptors;
1✔
218
      return this;
1✔
219
    }
220

221
    public Builder retryStrategy(RetryStrategy retryStrategy) {
222
      this.retryStrategy = retryStrategy;
1✔
223
      return this;
1✔
224
    }
225

226
    public Builder dataSanitizer(DataSanitizer dataSanitizer) {
227
      this.dataSanitizer = dataSanitizer;
1✔
228
      return this;
1✔
229
    }
230

231
    public Builder proxyConfig(ProxyConfig proxyConfig) {
232
      this.proxyConfig = proxyConfig;
1✔
233
      return this;
1✔
234
    }
235

236
    public NetworkSession build() {
237
      return new NetworkSession(this);
1✔
238
    }
239
  }
240
}
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