99import com .box .sdkgen .networking .proxyconfig .ProxyConfig ;
1010import com .box .sdkgen .networking .retries .BoxRetryStrategy ;
1111import com .box .sdkgen .networking .retries .RetryStrategy ;
12+ import com .box .sdkgen .networking .timeoutconfig .TimeoutConfig ;
1213import java .util .ArrayList ;
1314import java .util .HashMap ;
1415import java .util .List ;
@@ -31,6 +32,8 @@ public class NetworkSession {
3132
3233 protected ProxyConfig proxyConfig ;
3334
35+ protected TimeoutConfig timeoutConfig ;
36+
3437 public NetworkSession () {
3538 networkClient = new BoxNetworkClient ();
3639 retryStrategy = new BoxRetryStrategy ();
@@ -45,6 +48,7 @@ protected NetworkSession(Builder builder) {
4548 this .retryStrategy = builder .retryStrategy ;
4649 this .dataSanitizer = builder .dataSanitizer ;
4750 this .proxyConfig = builder .proxyConfig ;
51+ this .timeoutConfig = builder .timeoutConfig ;
4852 }
4953
5054 public NetworkSession withAdditionalHeaders () {
@@ -63,6 +67,7 @@ public NetworkSession withAdditionalHeaders(Map<String, String> additionalHeader
6367 .retryStrategy (this .retryStrategy )
6468 .dataSanitizer (this .dataSanitizer )
6569 .proxyConfig (this .proxyConfig )
70+ .timeoutConfig (this .timeoutConfig )
6671 .build ();
6772 }
6873
@@ -75,6 +80,7 @@ public NetworkSession withCustomBaseUrls(BaseUrls baseUrls) {
7580 .retryStrategy (this .retryStrategy )
7681 .dataSanitizer (this .dataSanitizer )
7782 .proxyConfig (this .proxyConfig )
83+ .timeoutConfig (this .timeoutConfig )
7884 .build ();
7985 }
8086
@@ -90,6 +96,7 @@ public NetworkSession withInterceptors(List<Interceptor> interceptors) {
9096 .retryStrategy (this .retryStrategy )
9197 .dataSanitizer (this .dataSanitizer )
9298 .proxyConfig (this .proxyConfig )
99+ .timeoutConfig (this .timeoutConfig )
93100 .build ();
94101 }
95102
@@ -102,6 +109,7 @@ public NetworkSession withNetworkClient(NetworkClient networkClient) {
102109 .retryStrategy (this .retryStrategy )
103110 .dataSanitizer (this .dataSanitizer )
104111 .proxyConfig (this .proxyConfig )
112+ .timeoutConfig (this .timeoutConfig )
105113 .build ();
106114 }
107115
@@ -114,6 +122,7 @@ public NetworkSession withRetryStrategy(RetryStrategy retryStrategy) {
114122 .retryStrategy (retryStrategy )
115123 .dataSanitizer (this .dataSanitizer )
116124 .proxyConfig (this .proxyConfig )
125+ .timeoutConfig (this .timeoutConfig )
117126 .build ();
118127 }
119128
@@ -126,6 +135,7 @@ public NetworkSession withDataSanitizer(DataSanitizer dataSanitizer) {
126135 .retryStrategy (this .retryStrategy )
127136 .dataSanitizer (dataSanitizer )
128137 .proxyConfig (this .proxyConfig )
138+ .timeoutConfig (this .timeoutConfig )
129139 .build ();
130140 }
131141
@@ -145,6 +155,30 @@ public NetworkSession withProxy(ProxyConfig config) {
145155 .retryStrategy (this .retryStrategy )
146156 .dataSanitizer (this .dataSanitizer )
147157 .proxyConfig (config )
158+ .timeoutConfig (this .timeoutConfig )
159+ .build ();
160+ }
161+
162+ public NetworkSession withTimeoutConfig (TimeoutConfig timeoutConfig ) {
163+ if (timeoutConfig == null ) {
164+ throw new IllegalArgumentException ("TimeoutConfig cannot be null" );
165+ }
166+
167+ if (!(this .networkClient instanceof BoxNetworkClient )) {
168+ throw new BoxSDKError ("Timeouts are only supported for BoxNetworkClient" );
169+ }
170+
171+ BoxNetworkClient newClient =
172+ ((BoxNetworkClient ) this .networkClient ).withTimeoutConfig (timeoutConfig );
173+ return new Builder ()
174+ .additionalHeaders (this .additionalHeaders )
175+ .baseUrls (this .baseUrls )
176+ .interceptors (this .interceptors )
177+ .networkClient (newClient )
178+ .retryStrategy (this .retryStrategy )
179+ .dataSanitizer (this .dataSanitizer )
180+ .proxyConfig (this .proxyConfig )
181+ .timeoutConfig (timeoutConfig )
148182 .build ();
149183 }
150184
@@ -176,6 +210,10 @@ public ProxyConfig getProxyConfig() {
176210 return proxyConfig ;
177211 }
178212
213+ public TimeoutConfig getTimeoutConfig () {
214+ return timeoutConfig ;
215+ }
216+
179217 public static class Builder {
180218
181219 protected Map <String , String > additionalHeaders = new HashMap <>();
@@ -192,6 +230,8 @@ public static class Builder {
192230
193231 protected ProxyConfig proxyConfig ;
194232
233+ protected TimeoutConfig timeoutConfig ;
234+
195235 public Builder () {
196236 networkClient = new BoxNetworkClient ();
197237 retryStrategy = new BoxRetryStrategy ();
@@ -233,6 +273,11 @@ public Builder proxyConfig(ProxyConfig proxyConfig) {
233273 return this ;
234274 }
235275
276+ public Builder timeoutConfig (TimeoutConfig timeoutConfig ) {
277+ this .timeoutConfig = timeoutConfig ;
278+ return this ;
279+ }
280+
236281 public NetworkSession build () {
237282 return new NetworkSession (this );
238283 }
0 commit comments