11package io .split .client ;
22
3+ import io .split .client .dtos .ProxyConfiguration ;
34import io .split .client .impressions .ImpressionListener ;
45import io .split .client .impressions .ImpressionsManager ;
56import io .split .client .utils .FileTypeEnum ;
89import io .split .storages .enums .OperationMode ;
910import io .split .storages .enums .StorageMode ;
1011import org .apache .hc .core5 .http .HttpHost ;
12+ import org .slf4j .LoggerFactory ;
1113import pluggable .CustomStorageWrapper ;
1214
1315import java .io .IOException ;
2729 */
2830public class SplitClientConfig {
2931
32+ private static final org .slf4j .Logger _log = LoggerFactory .getLogger (SplitClientConfig .class );
3033 public static final String LOCALHOST_DEFAULT_FILE = "split.yaml" ;
3134 public static final String SDK_ENDPOINT = "https://sdk.split.io" ;
3235 public static final String EVENTS_ENDPOINT = "https://events.split.io" ;
3336 public static final String AUTH_ENDPOINT = "https://auth.split.io/api/v2/auth" ;
3437 public static final String STREAMING_ENDPOINT = "https://streaming.split.io/sse" ;
3538 public static final String TELEMETRY_ENDPOINT = "https://telemetry.split.io/api/v1" ;
3639
40+ public static class HttpScheme {
41+ private HttpScheme () {
42+ throw new IllegalStateException ("Utility class" );
43+ }
44+ public static final String HTTP = "http" ;
45+ public static final String HTTPS = "https" ;
46+ }
47+
3748 private final String _endpoint ;
3849 private final String _eventsEndpoint ;
3950
@@ -82,6 +93,7 @@ public class SplitClientConfig {
8293 private final ThreadFactory _threadFactory ;
8394
8495 // Proxy configs
96+ private final ProxyConfiguration _proxyConfiguration ;
8597 private final HttpHost _proxy ;
8698 private final String _proxyUsername ;
8799 private final String _proxyPassword ;
@@ -118,6 +130,7 @@ private SplitClientConfig(String endpoint,
118130 HttpHost proxy ,
119131 String proxyUsername ,
120132 String proxyPassword ,
133+ ProxyConfiguration proxyConfiguration ,
121134 int eventsQueueSize ,
122135 long eventSendIntervalInMillis ,
123136 int maxStringLength ,
@@ -171,6 +184,7 @@ private SplitClientConfig(String endpoint,
171184 _proxy = proxy ;
172185 _proxyUsername = proxyUsername ;
173186 _proxyPassword = proxyPassword ;
187+ _proxyConfiguration = proxyConfiguration ;
174188 _eventsQueueSize = eventsQueueSize ;
175189 _eventSendIntervalInMillis = eventSendIntervalInMillis ;
176190 _maxStringLength = maxStringLength ;
@@ -302,6 +316,10 @@ public String proxyPassword() {
302316 return _proxyPassword ;
303317 }
304318
319+ public ProxyConfiguration proxyConfiguration () {
320+ return _proxyConfiguration ;
321+ }
322+
305323 public long eventSendIntervalInMillis () {
306324 return _eventSendIntervalInMillis ;
307325 }
@@ -417,8 +435,8 @@ public boolean isSdkEndpointOverridden() {
417435 }
418436
419437 public CustomHttpModule alternativeHTTPModule () { return _alternativeHTTPModule ; }
420- public static final class Builder {
421438
439+ public static final class Builder {
422440 private String _endpoint = SDK_ENDPOINT ;
423441 private boolean _endpointSet = false ;
424442 private String _eventsEndpoint = EVENTS_ENDPOINT ;
@@ -442,6 +460,7 @@ public static final class Builder {
442460 private int _proxyPort = -1 ;
443461 private String _proxyUsername ;
444462 private String _proxyPassword ;
463+ private ProxyConfiguration _proxyConfiguration ;
445464 private int _eventsQueueSize = 500 ;
446465 private long _eventSendIntervalInMillis = 30 * (long )1000 ;
447466 private int _maxStringLength = 250 ;
@@ -734,32 +753,44 @@ public Builder waitBeforeShutdown(int waitTime) {
734753
735754 /**
736755 * The host location of the proxy. Default is localhost.
756+ * @deprecated
757+ * This method is deprecated.
758+ * <p> Use {@link ProxyConfiguration)} instead.
737759 *
738760 * @param proxyHost location of the proxy
739761 * @return this builder
740762 */
763+ @ Deprecated
741764 public Builder proxyHost (String proxyHost ) {
742765 _proxyHost = proxyHost ;
743766 return this ;
744767 }
745768
746769 /**
747770 * The port of the proxy. Default is -1.
771+ * @deprecated
772+ * This method is deprecated.
773+ * <p> Use {@link ProxyConfiguration)} instead.
748774 *
749775 * @param proxyPort port for the proxy
750776 * @return this builder
751777 */
778+ @ Deprecated
752779 public Builder proxyPort (int proxyPort ) {
753780 _proxyPort = proxyPort ;
754781 return this ;
755782 }
756783
757784 /**
758785 * Set the username for authentication against the proxy (if proxy settings are enabled). (Optional).
786+ * @deprecated
787+ * This method is deprecated.
788+ * <p> Use {@link ProxyConfiguration)} instead.
759789 *
760790 * @param proxyUsername
761791 * @return this builder
762792 */
793+ @ Deprecated
763794 public Builder proxyUsername (String proxyUsername ) {
764795 _proxyUsername = proxyUsername ;
765796 return this ;
@@ -776,6 +807,17 @@ public Builder proxyPassword(String proxyPassword) {
776807 return this ;
777808 }
778809
810+ /**
811+ * Set the mtls authentication against the proxy (if proxy settings are enabled). (Optional).
812+ *
813+ * @param proxyConfiguration
814+ * @return this builder
815+ */
816+ public Builder proxyConfiguration (ProxyConfiguration proxyConfiguration ) {
817+ _proxyConfiguration = proxyConfiguration ;
818+ return this ;
819+ }
820+
779821 /**
780822 * Disables running destroy() on shutdown by default.
781823 *
@@ -927,7 +969,7 @@ public Builder operationMode(OperationMode mode) {
927969
928970 /**
929971 *
930- * @param storage mode
972+ * @param mode
931973 * @return this builder
932974 */
933975 public Builder storageMode (StorageMode mode ) {
@@ -1096,6 +1138,26 @@ private void verifyAlternativeClient() {
10961138 }
10971139 }
10981140
1141+ private void verifyProxy () {
1142+ if (_proxyConfiguration == null )
1143+ return ;
1144+
1145+ if (_proxyPort != -1 ) {
1146+ _log .warn ("Both the deprecated proxy configuration methods (`proxyHost`, `proxyPort`, `proxyUsername`, or `proxyPassword`) " +
1147+ "and the new `ProxyConfiguration` builder are being used. `ProxyConfiguration` will take precedence." );
1148+ }
1149+
1150+ if (!(_proxyConfiguration .getHost ().getSchemeName ().equals (HttpScheme .HTTP ) ||
1151+ _proxyConfiguration .getHost ().getSchemeName ().equals (HttpScheme .HTTPS ))) {
1152+ throw new IllegalArgumentException ("Proxy scheme must be either http or https." );
1153+ }
1154+
1155+ if ((_proxyConfiguration .getP12File () != null && _proxyConfiguration .getPassKey () == null ) ||
1156+ (_proxyConfiguration .getP12File () == null && _proxyConfiguration .getPassKey () != null )) {
1157+ throw new IllegalArgumentException ("Proxy mTLS must have p12 file path and name, and pass phrase." );
1158+ }
1159+ }
1160+
10991161 public SplitClientConfig build () {
11001162
11011163 verifyRates ();
@@ -1108,6 +1170,8 @@ public SplitClientConfig build() {
11081170
11091171 verifyAlternativeClient ();
11101172
1173+ verifyProxy ();
1174+
11111175 if (_numThreadsForSegmentFetch <= 0 ) {
11121176 throw new IllegalArgumentException ("Number of threads for fetching segments MUST be greater than zero" );
11131177 }
@@ -1133,6 +1197,7 @@ public SplitClientConfig build() {
11331197 proxy (),
11341198 _proxyUsername ,
11351199 _proxyPassword ,
1200+ _proxyConfiguration ,
11361201 _eventsQueueSize ,
11371202 _eventSendIntervalInMillis ,
11381203 _maxStringLength ,
0 commit comments