11package com .box .sdkgen .networking .network ;
22
3+ import com .box .sdkgen .box .errors .BoxSDKError ;
34import com .box .sdkgen .internal .logging .DataSanitizer ;
45import com .box .sdkgen .networking .baseurls .BaseUrls ;
56import com .box .sdkgen .networking .boxnetworkclient .BoxNetworkClient ;
67import com .box .sdkgen .networking .interceptors .Interceptor ;
78import com .box .sdkgen .networking .networkclient .NetworkClient ;
9+ import com .box .sdkgen .networking .proxyconfig .ProxyConfig ;
810import com .box .sdkgen .networking .retries .BoxRetryStrategy ;
911import com .box .sdkgen .networking .retries .RetryStrategy ;
1012import java .util .ArrayList ;
@@ -27,6 +29,8 @@ public class NetworkSession {
2729
2830 protected DataSanitizer dataSanitizer ;
2931
32+ protected ProxyConfig proxyConfig ;
33+
3034 public NetworkSession () {
3135 networkClient = new BoxNetworkClient ();
3236 retryStrategy = new BoxRetryStrategy ();
@@ -40,6 +44,7 @@ protected NetworkSession(Builder builder) {
4044 this .interceptors = builder .interceptors ;
4145 this .retryStrategy = builder .retryStrategy ;
4246 this .dataSanitizer = builder .dataSanitizer ;
47+ this .proxyConfig = builder .proxyConfig ;
4348 }
4449
4550 public NetworkSession withAdditionalHeaders () {
@@ -56,7 +61,8 @@ public NetworkSession withAdditionalHeaders(Map<String, String> additionalHeader
5661 .interceptors (this .interceptors )
5762 .networkClient (this .networkClient )
5863 .retryStrategy (this .retryStrategy )
59- .dataSanitizer (dataSanitizer )
64+ .dataSanitizer (this .dataSanitizer )
65+ .proxyConfig (this .proxyConfig )
6066 .build ();
6167 }
6268
@@ -67,7 +73,8 @@ public NetworkSession withCustomBaseUrls(BaseUrls baseUrls) {
6773 .interceptors (this .interceptors )
6874 .networkClient (this .networkClient )
6975 .retryStrategy (this .retryStrategy )
70- .dataSanitizer (dataSanitizer )
76+ .dataSanitizer (this .dataSanitizer )
77+ .proxyConfig (this .proxyConfig )
7178 .build ();
7279 }
7380
@@ -81,7 +88,8 @@ public NetworkSession withInterceptors(List<Interceptor> interceptors) {
8188 .interceptors (newInterceptors )
8289 .networkClient (this .networkClient )
8390 .retryStrategy (this .retryStrategy )
84- .dataSanitizer (dataSanitizer )
91+ .dataSanitizer (this .dataSanitizer )
92+ .proxyConfig (this .proxyConfig )
8593 .build ();
8694 }
8795
@@ -92,7 +100,8 @@ public NetworkSession withNetworkClient(NetworkClient networkClient) {
92100 .interceptors (this .interceptors )
93101 .networkClient (networkClient )
94102 .retryStrategy (this .retryStrategy )
95- .dataSanitizer (dataSanitizer )
103+ .dataSanitizer (this .dataSanitizer )
104+ .proxyConfig (this .proxyConfig )
96105 .build ();
97106 }
98107
@@ -103,7 +112,8 @@ public NetworkSession withRetryStrategy(RetryStrategy retryStrategy) {
103112 .interceptors (this .interceptors )
104113 .networkClient (this .networkClient )
105114 .retryStrategy (retryStrategy )
106- .dataSanitizer (dataSanitizer )
115+ .dataSanitizer (this .dataSanitizer )
116+ .proxyConfig (this .proxyConfig )
107117 .build ();
108118 }
109119
@@ -115,6 +125,26 @@ public NetworkSession withDataSanitizer(DataSanitizer dataSanitizer) {
115125 .networkClient (this .networkClient )
116126 .retryStrategy (this .retryStrategy )
117127 .dataSanitizer (dataSanitizer )
128+ .proxyConfig (this .proxyConfig )
129+ .build ();
130+ }
131+
132+ public NetworkSession withProxy (ProxyConfig config ) {
133+ if (config == null ) {
134+ throw new IllegalArgumentException ("ProxyConfig cannot be null" );
135+ }
136+ if (!(this .networkClient instanceof BoxNetworkClient )) {
137+ throw new BoxSDKError ("Proxies are only supported for BoxNetworkClient" );
138+ }
139+ BoxNetworkClient newClient = ((BoxNetworkClient ) this .networkClient ).withProxy (config );
140+ return new Builder ()
141+ .additionalHeaders (this .additionalHeaders )
142+ .baseUrls (this .baseUrls )
143+ .interceptors (this .interceptors )
144+ .networkClient (newClient )
145+ .retryStrategy (this .retryStrategy )
146+ .dataSanitizer (this .dataSanitizer )
147+ .proxyConfig (config )
118148 .build ();
119149 }
120150
@@ -142,6 +172,10 @@ public DataSanitizer getDataSanitizer() {
142172 return dataSanitizer ;
143173 }
144174
175+ public ProxyConfig getProxyConfig () {
176+ return proxyConfig ;
177+ }
178+
145179 public static class Builder {
146180
147181 protected Map <String , String > additionalHeaders = new HashMap <>();
@@ -156,6 +190,8 @@ public static class Builder {
156190
157191 protected DataSanitizer dataSanitizer ;
158192
193+ protected ProxyConfig proxyConfig ;
194+
159195 public Builder () {
160196 networkClient = new BoxNetworkClient ();
161197 retryStrategy = new BoxRetryStrategy ();
@@ -192,6 +228,11 @@ public Builder dataSanitizer(DataSanitizer dataSanitizer) {
192228 return this ;
193229 }
194230
231+ public Builder proxyConfig (ProxyConfig proxyConfig ) {
232+ this .proxyConfig = proxyConfig ;
233+ return this ;
234+ }
235+
195236 public NetworkSession build () {
196237 return new NetworkSession (this );
197238 }
0 commit comments